25.8.4.1.2 Code
Add to the main application source file, before any functions:
Add to the main application source file, outside of any functions:#define CONF_PWM_MODULE LED_0_PWM4CTRL_MODULE#define CONF_PWM_CHANNEL LED_0_PWM4CTRL_CHANNEL#define CONF_PWM_OUTPUT LED_0_PWM4CTRL_OUTPUT#define CONF_PWM_OUT_PIN LED_0_PWM4CTRL_PIN#define CONF_PWM_OUT_MUX LED_0_PWM4CTRL_MUX
Copy-paste the following callback function code to your user application:structtcc_module tcc_instance;
Copy-paste the following setup code to your user application:staticvoidtcc_callback_to_change_duty_cycle(structtcc_module *constmodule_inst){staticuint32_t delay = 10;staticuint32_t i = 0;if(--delay) {return;}delay = 10;i = (i + 0x0800) & 0xFFFF;tcc_set_compare_value(module_inst,(enumtcc_match_capture_channel)(TCC_MATCH_CAPTURE_CHANNEL_0 + CONF_PWM_CHANNEL),i + 1);}
Add to user application initialization (typically the start of main()):staticvoidconfigure_tcc(void){structtcc_config config_tcc;tcc_get_config_defaults(&config_tcc, CONF_PWM_MODULE);config_tcc.counter.period = 0xFFFF;config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;config_tcc.compare.match[CONF_PWM_CHANNEL] = 0xFFFF;config_tcc.pins.enable_wave_out_pin[CONF_PWM_OUTPUT] =true;config_tcc.pins.wave_out_pin[CONF_PWM_OUTPUT] = CONF_PWM_OUT_PIN;config_tcc.pins.wave_out_pin_mux[CONF_PWM_OUTPUT] = CONF_PWM_OUT_MUX;tcc_init(&tcc_instance, CONF_PWM_MODULE, &config_tcc);tcc_enable(&tcc_instance);}staticvoidconfigure_tcc_callbacks(void){tcc_register_callback(&tcc_instance,tcc_callback_to_change_duty_cycle,(enumtcc_callback)(TCC_CALLBACK_CHANNEL_0 + CONF_PWM_CHANNEL));tcc_enable_callback(&tcc_instance,(enumtcc_callback)(TCC_CALLBACK_CHANNEL_0 + CONF_PWM_CHANNEL));}
configure_tcc();configure_tcc_callbacks();
