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 | |
Related Project(s) | |
In this section you can find all the projects related to the Pulse Width Modulation (PWM). | |
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.
p_pwm | Pointer to a PWM instance. |
ul_channel | PWM 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.
p_pwm | Pointer to a PWM instance. |
ul_event | Bitmask of channel number to disable counter event interrupt. |
ul_fault | Bitmask 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.
p_pwm | Pointer to a PWM instance. |
ul_channel | PWM 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.
p_pwm | Pointer to a PWM instance. |
ul_event | Channel number to enable counter event interrupt. |
ul_fault | Channel 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.
p_pwm | Pointer to a PWM instance. |
p_channel | Configurations of the specified PWM channel. |
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.
p_pwm | Pointer to a PWM instance. |
uint32_t pwm_channel_get_interrupt_status | ( | Pwm * | p_pwm | ) |
Get channel counter event and fault protection trigger interrupt status.
p_pwm | Pointer to a PWM instance. |
Referenced by PWM_Handler().
uint32_t pwm_channel_get_status | ( | Pwm * | p_pwm | ) |
Check which PWM channel is enabled.
p_pwm | Pointer to a PWM instance. |
p_channel | Configurations of the specified PWM channel. |
uint32_t pwm_channel_init | ( | Pwm * | p_pwm, |
pwm_channel_t * | p_channel | ||
) |
Initialize one PWM channel.
p_pwm | Pointer to a PWM instance. |
p_channel | Configurations of the specified PWM channel. |
0 | if 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.
p_pwm | Pointer to a PWM instance. |
p_channel | Configurations of the specified PWM channel. |
ul_duty | New duty cycle value. |
0 | if 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.
p_pwm | Pointer to a PWM instance. |
p_channel | Configurations of the specified PWM channel. |
ul_period | New period value. |
0 | if 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 |
Find a prescaler/divisor couple to generate the desired ul_frequency from ul_mck.
ul_frequency | Desired frequency in Hz. |
ul_mck | Master clock frequency in Hz. |
Return | the 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).
p_pwm | Pointer to a PWM instance. |
clock_config | PWM clock configuration. |
0 | if 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().