Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PWM - Pulse Width Modulation

Pulse Width Modulation (PWM) Software Driver for modules below revision v4.0.0.

This driver provides an API to get access to the main features of the PWM controller.

Data Structures

struct  pwm_opt_t
 Input parameters when initializing a PWM channel. More...
 

Macros

#define PWM_FAILURE   -1
 Value returned by function when it was unable to complete successfully for some unspecified reason. More...
 
#define PWM_INVALID_ARGUMENT   1
 Value returned by function when the channel number is invalid. More...
 
#define PWM_INVALID_INPUT   1
 Value returned by function when the input parameters are out of range. More...
 
#define PWM_MODE_CENTER_ALIGNED   1
 Operate PWM channel in center aligned mode. More...
 
#define PWM_MODE_LEFT_ALIGNED   0
 Operate PWM channel in left aligned mode. More...
 
#define PWM_POLARITY_HIGH   1
 PWM channel starts output high level. More...
 
#define PWM_POLARITY_LOW   0
 PWM channel starts output low level. More...
 
#define PWM_SUCCESS   0
 Value returned by function when it completed successfully. More...
 
#define PWM_UPDATE_DUTY   0
 PWM channel write in CUPDx updates duty cycle at the next period start event. More...
 
#define PWM_UPDATE_PERIOD   1
 PWM channel write in CUPDx updates period at the next period start event. More...
 

Functions

int pwm_async_update_channel (unsigned int channel_id, const avr32_pwm_channel_t *pwm_channel)
 Update channel register CPRDx or CDTYx without synchronizing with the PWM period. This function uses the CUPDx register as a double buffer for the period or the duty cycle. Only the first 20 bits of cupd are significant. More...
 
int pwm_channel_init (unsigned int channel_id, const avr32_pwm_channel_t *pwm_channel)
 Initialize a specific PWM channel. More...
 
int pwm_init (const pwm_opt_t *opt)
 This function initialize the PWM controller (mode register) and disable the interrupt. More...
 
int pwm_start_channels (unsigned long channels_bitmask)
 Start PWM channels. More...
 
int pwm_stop_channels (unsigned long channels_bitmask)
 Stop PWM channels. More...
 
int pwm_sync_update_channel (unsigned int channel_id, const avr32_pwm_channel_t *pwm_channel)
 Update channel register CPRDx or CDTYx by forcing synchronization with the PWM period. This function uses the CUPDx register as a double buffer for the period or the duty cycle. Only the first 20 bits of cupd are significant. More...
 

#define PWM_FAILURE   -1

Value returned by function when it was unable to complete successfully for some unspecified reason.

#define PWM_INVALID_ARGUMENT   1

Value returned by function when the channel number is invalid.

Referenced by pwm_channel_init().

#define PWM_INVALID_INPUT   1

Value returned by function when the input parameters are out of range.

Referenced by pwm_async_update_channel(), pwm_channel_init(), pwm_init(), pwm_start_channels(), pwm_stop_channels(), and pwm_sync_update_channel().

#define PWM_MODE_CENTER_ALIGNED   1

Operate PWM channel in center aligned mode.

#define PWM_MODE_LEFT_ALIGNED   0

Operate PWM channel in left aligned mode.

#define PWM_POLARITY_HIGH   1

PWM channel starts output high level.

#define PWM_POLARITY_LOW   0

PWM channel starts output low level.

#define PWM_SUCCESS   0

Value returned by function when it completed successfully.

Referenced by pwm_async_update_channel(), pwm_channel_init(), pwm_init(), pwm_start_channels(), pwm_stop_channels(), and pwm_sync_update_channel().

#define PWM_UPDATE_DUTY   0

PWM channel write in CUPDx updates duty cycle at the next period start event.

#define PWM_UPDATE_PERIOD   1

PWM channel write in CUPDx updates period at the next period start event.

int pwm_async_update_channel ( unsigned int  channel_id,
const avr32_pwm_channel_t *  pwm_channel 
)

Update channel register CPRDx or CDTYx without synchronizing with the PWM period. This function uses the CUPDx register as a double buffer for the period or the duty cycle. Only the first 20 bits of cupd are significant.

Parameters
channel_idThe channel identifier (0 to max channel-1)
*pwm_channelPointer to PWM channel struct avr32_pwm_channel_t
Returns
PWM_SUCCESS or PWM_INVALID_INPUT
Warning
Calling this function several times in a row may result in some update values never being issued to PWM if some external synchronizing mechanism like an interrupt is not used.
Note
This update function should be preferred when updating a PWM channel from an interrupt handler.

References PWM_INVALID_INPUT, and PWM_SUCCESS.

int pwm_channel_init ( unsigned int  channel_id,
const avr32_pwm_channel_t *  pwm_channel 
)

Initialize a specific PWM channel.

Parameters
channel_idThe channel identifier mask
*pwm_channelPointer to PWM channel struct avr32_pwm_channel_t
Returns
PWM_SUCCESS, PWM_INVALID_INPUT or PWM_INVALID_ARGUMENT

References PWM_INVALID_ARGUMENT, PWM_INVALID_INPUT, and PWM_SUCCESS.

int pwm_init ( const pwm_opt_t opt)

This function initialize the PWM controller (mode register) and disable the interrupt.

Parameters
optPWM Channel structure parameter
Returns
PWM_SUCCESS or PWM_INVALID_INPUT

References Disable_global_interrupt, pwm_opt_t::diva, pwm_opt_t::divb, Enable_global_interrupt, Is_global_interrupt_enabled, pwm_opt_t::prea, pwm_opt_t::preb, PWM_INVALID_INPUT, and PWM_SUCCESS.

int pwm_start_channels ( unsigned long  channels_bitmask)

Start PWM channels.

Parameters
channels_bitmaskA bit-mask with set bits indicating channels to start.
Returns
PWM_SUCCESS or PWM_INVALID_INPUT

References PWM_INVALID_INPUT, and PWM_SUCCESS.

int pwm_stop_channels ( unsigned long  channels_bitmask)

Stop PWM channels.

Parameters
channels_bitmaskA bit-mask with set bits indicating channels to stop.
Returns
PWM_SUCCESS or PWM_INVALID_INPUT

References PWM_INVALID_INPUT, and PWM_SUCCESS.

int pwm_sync_update_channel ( unsigned int  channel_id,
const avr32_pwm_channel_t *  pwm_channel 
)

Update channel register CPRDx or CDTYx by forcing synchronization with the PWM period. This function uses the CUPDx register as a double buffer for the period or the duty cycle. Only the first 20 bits of cupd are significant.

Parameters
channel_idThe channel identifier (0 to max channel-1)
*pwm_channelPointer to PWM channel struct avr32_pwm_channel_t
Returns
PWM_SUCCESS or PWM_INVALID_INPUT
Note
This update function should be preferred when updating a PWM channel by polling.

References PWM_INVALID_INPUT, and PWM_SUCCESS.