Salesforce

SAM D/L/C - TC Capture Example using Atmel START

« Go Back

Information

 
Article Number000007631
TitleSAM D/L/C - TC Capture Example using Atmel START
Question
How to configure TC for Capture using Atmel START ?

Is there any example project for TC Capture using ASF4 (Atmel START)?
Answer
There is no direct driver for TC capture in Atmel START however it can be achieved by using the TC Lite drivers in Atmel START.

Attached the L21 example project for TC Capture with Atmel START

Configuration details:
  • Timer TC0 is configured in 32bit mode with PWP event capture using TC Lite driver in Atmel START.
  • Pin PA16 is configured as a external interrupt level high.
  • Event system Channel 0 is configured as PA16(EXINT) as event generator and TC0 as event user in Asynchronous Path.
  • TC2 is configured as PWM generator for Pin PB17 (This is only for TC Capture verification).
Note: You can import the attached atstart configuration in Atmel START to see the configuration.

Steps to be followed after generating the Project from Atmel START:
  • TC1 Clock should be enabled as the TC0 is configured in 32 bit mode. COUNT32 mode is achieved by pairing two 16-bit TC peripherals. TCn is paired with TCn+1. It can be done in the 'TIMER_0_CLOCK_init()' function in 'driver_init.c' file as given below,
void TIMER_0_CLOCK_init(void)
{
       hri_mclk_set_APBCMASK_TC0_bit(MCLK);
       hri_mclk_set_APBCMASK_TC1_bit(MCLK);
       hri_gclk_write_PCHCTRL_reg(GCLK, TC0_GCLK_ID, CONF_GCLK_TC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
       hri_gclk_write_PCHCTRL_reg(GCLK, TC1_GCLK_ID, CONF_GCLK_TC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
}
  • TC0 Interrupt handler should be enabled before starting the Timer(hri_tc_write_CTRLA_ENABLE_bit()) inside the 'TIMER_0_init()' in 'tc_lite.c' file.
   NVIC_DisableIRQ(TC0_IRQn);
      NVIC_ClearPendingIRQ(TC0_IRQn);
      NVIC_EnableIRQ(TC0_IRQn);
  • TC0 Interrupt Handler should be added in the 'tc_lite.c' file as given below,
void TC0_Handler(void)
{
       if (hri_tc_get_interrupt_OVF_bit(TC0)) {
              hri_tc_clear_interrupt_OVF_bit(TC0);
       }
       if(hri_tc_get_interrupt_ERR_bit(TC0)) {
              hri_tc_clear_interrupt_ERR_bit(TC0);
       }
       if(hri_tc_get_interrupt_MC1_bit(TC0)) {
             
              hri_tc_clear_interrupt_MC1_bit(TC0);
              while(TC0->COUNT32.SYNCBUSY.bit.CC0);
              pulse_width = hri_tccount32_read_CC_reg(TC0, 0);
              while(TC0->COUNT32.SYNCBUSY.bit.CC1);
              period = hri_tccount32_read_CC_reg(TC0, 1);
       }
}

How to test?
  • Pin PB17 and PA16 should be connected.
  • Captured Period and Pulse width will be available in the terminal.
  • PWM generator's Period and Pulse Width can be varied using pwm_set_parameters() function in 'driver_example.c' file.
void PWM_0_example(void)
{
       pwm_set_parameters(&PWM_0, 9000, 6000);
       pwm_enable(&PWM_0);
}

Note: This Project Cannot be reconfigured from Atmel START. This project can be referred for SAM D/L/C devices.
URL NameSAM-D-L-C---TC-Capture-Example-using-Atmel-START


Powered by