9.1.3.3 Workflow
- Enable the TC module's capture pin:
ioport_set_pin_mode(PIN_TC_CAPTURE, PIN_TC_CAPTURE_MUX);ioport_disable_pin(PIN_TC_CAPTURE); - Initialize the capture channel to the following:
Load RA on the rising edge of TIOA
Load RB on the falling edge of TIOA
Set the external trigger to TIOA
- Set the external trigger to falling edge
tc_capture_initialize();
- Enable the TC interrupt using NVIC:
NVIC_DisableIRQ(TC_IRQn);NVIC_ClearPendingIRQ(TC_IRQn);NVIC_SetPriority(TC_IRQn, 0);NVIC_EnableIRQ(TC_IRQn); - Enable the capture channel interrupt:
tc_enable_interrupt(TC, TC_CHANNEL_CAPTURE, TC_IER_LDRBS); - In the TC_Handler() function, the load. RB interrupt can be checked by:
if((tc_get_status(TC, TC_CHANNEL_CAPTURE) & TC_SR_LDRBS) == TC_SR_LDRBS) {} - In the TC_Handler() function, the RA value. can be read by:
uint32_t gs_ul_captured_ra;gs_ul_captured_ra = tc_read_ra(TC, TC_CHANNEL_CAPTURE); - In the TC_Handler() function, the RB value. can be read by:
uint32_t gs_ul_captured_rb;gs_ul_captured_rb = tc_read_rb(TC, TC_CHANNEL_CAPTURE);
