Microchip® Advanced Software Framework

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

See Quickstart guide for SAM PWM module.

Driver for the PWM (Pulse Width Modulation). This driver provides access to the main features of the PWM controller.

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the Pulse Width Modulation (PWM).
 

Macros

#define PWM_CLOCK_DIV_MAX   256
 
#define PWM_CLOCK_PRE_MAX   11
 
#define PWM_WPCR_WPCMD_DISABLE_SW_PROT   (PWM_WPCR_WPCMD(0))
 
#define PWM_WPCR_WPCMD_ENABLE_HW_PROT   (PWM_WPCR_WPCMD(2))
 
#define PWM_WPCR_WPCMD_ENABLE_SW_PROT   (PWM_WPCR_WPCMD(1))
 
#define PWM_WPCR_WPKEY_PASSWD   0x50574D00
 

Functions

void pwm_channel_disable (Pwm *p_pwm, uint32_t ul_channel)
 Disable the PWM channel. More...
 
void pwm_channel_disable_interrupt (Pwm *p_pwm, uint32_t ul_event, uint32_t ul_fault)
 Disable the interrupt of a channel counter event and fault protection. More...
 
void pwm_channel_enable (Pwm *p_pwm, uint32_t ul_channel)
 Enable the PWM channel. More...
 
void pwm_channel_enable_interrupt (Pwm *p_pwm, uint32_t ul_event, uint32_t ul_fault)
 Enable the interrupt of a channel counter event and fault protection. More...
 
uint32_t pwm_channel_get_counter (Pwm *p_pwm, pwm_channel_t *p_channel)
 Return channel counter value. More...
 
uint32_t pwm_channel_get_interrupt_mask (Pwm *p_pwm)
 Get channel counter event and fault protection trigger interrupt mask. More...
 
uint32_t pwm_channel_get_interrupt_status (Pwm *p_pwm)
 Get channel counter event and fault protection trigger interrupt status. More...
 
uint32_t pwm_channel_get_status (Pwm *p_pwm)
 Check which PWM channel is enabled. More...
 
uint32_t pwm_channel_init (Pwm *p_pwm, pwm_channel_t *p_channel)
 Initialize one PWM channel. More...
 
uint32_t pwm_channel_update_duty (Pwm *p_pwm, pwm_channel_t *p_channel, uint32_t ul_duty)
 Change the duty cycle of the PWM channel. More...
 
uint32_t pwm_channel_update_period (Pwm *p_pwm, pwm_channel_t *p_channel, uint32_t ul_period)
 Change the period of the PWM channel. More...
 
static uint32_t pwm_clocks_generate (uint32_t ul_frequency, uint32_t ul_mck)
 Find a prescaler/divisor couple to generate the desired ul_frequency from ul_mck. More...
 
uint32_t pwm_init (Pwm *p_pwm, pwm_clock_t *clock_config)
 Initialize the PWM source clock (clock A and clock B). More...
 

#define PWM_CLOCK_DIV_MAX   256

Referenced by pwm_clocks_generate().

#define PWM_CLOCK_PRE_MAX   11

Referenced by pwm_clocks_generate().

#define PWM_WPCR_WPCMD_DISABLE_SW_PROT   (PWM_WPCR_WPCMD(0))
#define PWM_WPCR_WPCMD_ENABLE_HW_PROT   (PWM_WPCR_WPCMD(2))
#define PWM_WPCR_WPCMD_ENABLE_SW_PROT   (PWM_WPCR_WPCMD(1))
#define PWM_WPCR_WPKEY_PASSWD   0x50574D00

void pwm_channel_disable ( Pwm *  p_pwm,
uint32_t  ul_channel 
)

Disable the PWM channel.

Note
A disabled PWM channel can be re-initialized using pwm_channel_init().
Parameters
p_pwmPointer to a PWM instance.
ul_channelPWM channel number to disable.

Referenced by main().

void pwm_channel_disable_interrupt ( Pwm *  p_pwm,
uint32_t  ul_event,
uint32_t  ul_fault 
)

Disable the interrupt of a channel counter event and fault protection.

Parameters
p_pwmPointer to a PWM instance.
ul_eventBitmask of channel number to disable counter event interrupt.
ul_faultBitmask of channel number to disable fault protection interrupt(ignored by SAM3N/SAM4N/SAM4C/SAM4CP/SAM4CM).

References UNUSED.

Referenced by main().

void pwm_channel_enable ( Pwm *  p_pwm,
uint32_t  ul_channel 
)

Enable the PWM channel.

Note
The PWM channel should be initialized by pwm_channel_init() before it is enabled.
Parameters
p_pwmPointer to a PWM instance.
ul_channelPWM channel number to enable.

Referenced by main().

void pwm_channel_enable_interrupt ( Pwm *  p_pwm,
uint32_t  ul_event,
uint32_t  ul_fault 
)

Enable the interrupt of a channel counter event and fault protection.

Parameters
p_pwmPointer to a PWM instance.
ul_eventChannel number to enable counter event interrupt.
ul_faultChannel number to enable fault protection interrupt(ignored by SAM3N/SAM4N/SAM4C/SAM4CP/SAM4CM).

References UNUSED.

Referenced by main().

uint32_t pwm_channel_get_counter ( Pwm *  p_pwm,
pwm_channel_t p_channel 
)

Return channel counter value.

Parameters
p_pwmPointer to a PWM instance.
p_channelConfigurations of the specified PWM channel.
Returns
channel Counter value.

References pwm_channel_t::channel.

uint32_t pwm_channel_get_interrupt_mask ( Pwm *  p_pwm)

Get channel counter event and fault protection trigger interrupt mask.

Parameters
p_pwmPointer to a PWM instance.
Returns
Channel counter event and fault protection trigger interrupt mask.
uint32_t pwm_channel_get_interrupt_status ( Pwm *  p_pwm)

Get channel counter event and fault protection trigger interrupt status.

Parameters
p_pwmPointer to a PWM instance.
Returns
Channel counter event and fault protection trigger interrupt status.

Referenced by PWM_Handler().

uint32_t pwm_channel_get_status ( Pwm *  p_pwm)

Check which PWM channel is enabled.

Parameters
p_pwmPointer to a PWM instance.
p_channelConfigurations of the specified PWM channel.
Returns
Bitmask of enabled PWM channel(s).
uint32_t pwm_channel_init ( Pwm *  p_pwm,
pwm_channel_t p_channel 
)

Initialize one PWM channel.

Parameters
p_pwmPointer to a PWM instance.
p_channelConfigurations of the specified PWM channel.
Return values
0if initialization succeeds, otherwise fails.

References pwm_channel_t::alignment, pwm_channel_t::channel, pwm_channel_t::polarity, PWM_HIGH, pwm_channel_t::ul_duty, pwm_channel_t::ul_period, and pwm_channel_t::ul_prescaler.

Referenced by main().

uint32_t pwm_channel_update_duty ( Pwm *  p_pwm,
pwm_channel_t p_channel,
uint32_t  ul_duty 
)

Change the duty cycle of the PWM channel.

Parameters
p_pwmPointer to a PWM instance.
p_channelConfigurations of the specified PWM channel.
ul_dutyNew duty cycle value.
Return values
0if changing succeeds, otherwise fails.

Check parameter

References pwm_channel_t::channel, PWM_INVALID_ARGUMENT, pwm_channel_t::ul_duty, and pwm_channel_t::ul_period.

Referenced by PWM_Handler().

uint32_t pwm_channel_update_period ( Pwm *  p_pwm,
pwm_channel_t p_channel,
uint32_t  ul_period 
)

Change the period of the PWM channel.

Parameters
p_pwmPointer to a PWM instance.
p_channelConfigurations of the specified PWM channel.
ul_periodNew period value.
Return values
0if changing succeeds, otherwise fails.

Check parameter

References pwm_channel_t::channel, PWM_INVALID_ARGUMENT, pwm_channel_t::ul_duty, and pwm_channel_t::ul_period.

static uint32_t pwm_clocks_generate ( uint32_t  ul_frequency,
uint32_t  ul_mck 
)
static

Find a prescaler/divisor couple to generate the desired ul_frequency from ul_mck.

Parameters
ul_frequencyDesired frequency in Hz.
ul_mckMaster clock frequency in Hz.
Return values
Returnthe value to be set in the PWM Clock Register (PWM Mode Register for SAM3N/SAM4N/SAM4C/SAM4CP/SAM4CM) or PWM_INVALID_ARGUMENT if the configuration cannot be met.

References PWM_CLOCK_DIV_MAX, PWM_CLOCK_PRE_MAX, and PWM_INVALID_ARGUMENT.

Referenced by pwm_init().

uint32_t pwm_init ( Pwm *  p_pwm,
pwm_clock_t clock_config 
)

Initialize the PWM source clock (clock A and clock B).

Parameters
p_pwmPointer to a PWM instance.
clock_configPWM clock configuration.
Return values
0if initialization succeeds, otherwise fails.

References pwm_clocks_generate(), PWM_INVALID_ARGUMENT, pwm_clock_t::ul_clka, pwm_clock_t::ul_clkb, and pwm_clock_t::ul_mck.

Referenced by main().