In this use case the PWM module is configured with overflow interrupt.
Setup steps
Example code
Add to application C-file:
*
* void my_callback(void)
* {
* do_something();
* }
* {
*
*
* }
Workflow
- Define config struct for PWM module:
- Define a callback function in the application which does whatever task you want it to do:
void my_callback(void)
{
do_something();
}
- Initialize interrupt controller module:
- Initialize sysclock module:
- Enable global interrupts:
- Initialize config struct and set up PWM with frequency of 75 Hz:
- Note
- Since the timer/counter PWM_TCE0 and channel PWM_CH_A is used, the PWM will be output on port E, pin 0. See pwm_tc_t and pwm_channel_t for more information on what port/pin is used for different timer/counters.
- Attention
- This step must not be skipped or the initial content of the structs will be unpredictable, possibly causing misconfiguration.
- Set callback function on PWM TC channel overflow:
Usage steps
Example code
Add to, e.g., main loop in application C-file:
Workflow
- Start PWM with 50% duty cycle: