Configure the TCC
- Create a module software instance structure for the TCC module to store the TCC driver state while it is in use.
structtcc_module tcc_instance;Note: This should never go out of scope as long as the module is in use. In most cases, this should be global. - Create a TCC module configuration struct, which can be filled out to adjust the configuration of a physical TCC peripheral.
structtcc_config config_tcc; - Initialize the TCC configuration struct with the module's default values.
tcc_get_config_defaults(&config_tcc, CONF_PWM_MODULE);Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Alter the TCC settings to configure the counter width, wave generation mode and the compare channel 0 value.
config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV1024;config_tcc.counter.period = 0x1000;config_tcc.compare.channel_function[CONF_TCC_CAPTURE_CHANNEL] =TCC_CHANNEL_FUNCTION_CAPTURE;config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;config_tcc.compare.wave_polarity[CONF_PWM_CHANNEL] = TCC_WAVE_POLARITY_0;config_tcc.compare.match[CONF_PWM_CHANNEL] = compare_values[2]; - Alter the TCC settings to configure the PWM output on a physical device pin.
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; - Configure the TCC module with the desired settings.
tcc_init(&tcc_instance, CONF_PWM_MODULE, &config_tcc); - Configure and enable the desired events for the TCC module.
structtcc_events events_tcc = {.input_config[0].modify_action =false,.input_config[1].modify_action =false,.output_config.modify_generation_selection =false,.generate_event_on_channel[CONF_PWM_CHANNEL] =true,.on_event_perform_channel_action[CONF_TCC_CAPTURE_CHANNEL] =true};tcc_enable_events(&tcc_instance, &events_tcc);
