SAM C21 Xplained Pro.
#define CONF_TC_MODULE TC3
Add to the main application source file, outside of any functions:
struct tc_module tc_instance;
Copy-paste the following callback function code to your user application:
void tc_callback_to_toggle_led(
struct tc_module *const module_inst)
{
port_pin_toggle_output_level(LED0_PIN);
}
Copy-paste the following setup code to your user application:
void configure_tc(void)
{
struct tc_config config_tc;
tc_get_config_defaults(&config_tc);
config_tc.counter_size = TC_COUNTER_SIZE_8BIT;
config_tc.clock_source = GCLK_GENERATOR_1;
config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV1024;
config_tc.counter_8_bit.period = 100;
config_tc.counter_8_bit.compare_capture_channel[0] = 50;
config_tc.counter_8_bit.compare_capture_channel[1] = 54;
tc_init(&tc_instance, CONF_TC_MODULE, &config_tc);
tc_enable(&tc_instance);
}
void configure_tc_callbacks(void)
{
tc_register_callback(&tc_instance, tc_callback_to_toggle_led,
TC_CALLBACK_OVERFLOW);
tc_register_callback(&tc_instance, tc_callback_to_toggle_led,
TC_CALLBACK_CC_CHANNEL0);
tc_register_callback(&tc_instance, tc_callback_to_toggle_led,
TC_CALLBACK_CC_CHANNEL1);
tc_enable_callback(&tc_instance, TC_CALLBACK_OVERFLOW);
tc_enable_callback(&tc_instance, TC_CALLBACK_CC_CHANNEL0);
tc_enable_callback(&tc_instance, TC_CALLBACK_CC_CHANNEL1);
}
Add to user application initialization (typically the start of
main()):
configure_tc();
configure_tc_callbacks();