25.8.3.1.3 Workflow
- 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. - Configure the TCC module.
- 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, TCC0);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 GCLK source, prescaler, period and compare channel values.
config_tcc.counter.clock_source = GCLK_GENERATOR_1;config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV64;config_tcc.counter.period = 2000;config_tcc.compare.match[0] = 900;config_tcc.compare.match[1] = 930;config_tcc.compare.match[2] = 1100;config_tcc.compare.match[3] = 1250; - Configure the TCC module with the desired settings.
tcc_init(&tcc_instance, TCC0, &config_tcc); - Enable the TCC module to start the timer.
tcc_enable(&tcc_instance);
- Configure the TCC callbacks.
- Register the Overflow and Compare Channel Match callback functions with the driver.
tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,TCC_CALLBACK_OVERFLOW);tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,TCC_CALLBACK_CHANNEL_0);tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,TCC_CALLBACK_CHANNEL_1);tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,TCC_CALLBACK_CHANNEL_2);tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,TCC_CALLBACK_CHANNEL_3); - Enable the Overflow and Compare Channel Match callbacks so that it will be called by the driver when appropriate.
tcc_enable_callback(&tcc_instance, TCC_CALLBACK_OVERFLOW);tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_0);tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_1);tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_2);tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_3);
