Workflow

  1. 1.
    Enable the TC module's capture pin:
    ioport_set_pin_mode(PIN_TC_CAPTURE, PIN_TC_CAPTURE_MUX);
    ioport_disable_pin(PIN_TC_CAPTURE);
    
  2. 2.
    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();
      
  3. 3.
    Enable the TC interrupt using NVIC:
    NVIC_DisableIRQ(TC_IRQn);
    NVIC_ClearPendingIRQ(TC_IRQn);
    NVIC_SetPriority(TC_IRQn, 0);
    NVIC_EnableIRQ(TC_IRQn);
    
  4. 4.
    Enable the capture channel interrupt:
    tc_enable_interrupt(TC, TC_CHANNEL_CAPTURE, TC_IER_LDRBS);
    
  5. 5.
    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) {
    
    } 
    
  6. 6.
    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);
    
  7. 7.
    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);