24.8.3.1.2 Code
Add to the main application source file, before any functions, according to the kit used:
- SAM D20 Xplained Pro.
#define CONF_TC_MODULE TC3
- SAM D21 Xplained Pro.
#define CONF_TC_MODULE TC3
- SAM R21 Xplained Pro.
#define CONF_TC_MODULE TC3
- SAM D11 Xplained Pro.
#define CONF_TC_MODULE TC1
- SAM L21 Xplained Pro.
#define CONF_TC_MODULE TC3
- SAM L22 Xplained Pro.
#define CONF_TC_MODULE TC3
- SAM DA1 Xplained Pro.
#define CONF_TC_MODULE TC3
- SAM C21 Xplained Pro.
Add to the main application source file, outside of any functions:#define CONF_TC_MODULE TC3
Copy-paste the following callback function code to your user application:struct
tc_module tc_instance;
Copy-paste the following setup code to your user application:void
tc_callback_to_toggle_led(
struct
tc_module *
const
module_inst)
{
port_pin_toggle_output_level(LED0_PIN);
}
Add to user application initialization (typically the start of main()):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);
}
configure_tc();
configure_tc_callbacks();