25.8.3.1.2 Code
Add to the main application source file, outside of any functions:
Copy-paste the following callback function code to your user application:struct
tcc_module tcc_instance;
Copy-paste the following setup code to your user application:static
void
tcc_callback_to_toggle_led(
struct
tcc_module *
const
module_inst)
{
port_pin_toggle_output_level(LED0_PIN);
}
Add to user application initialization (typically the start of main()):static
void
configure_tcc(
void
)
{
struct
tcc_config config_tcc;
tcc_get_config_defaults(&config_tcc, TCC0);
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;
tcc_init(&tcc_instance, TCC0, &config_tcc);
tcc_enable(&tcc_instance);
}
static
void
configure_tcc_callbacks(
void
)
{
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);
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);
}
configure_tcc();
configure_tcc_callbacks();