SAMD21 External Interrupt to Increment Timer

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all,

 

I have a SAM D21 Xplained board that I am using to learn about the SAM D21 MCU. I am more familiar with AVR devices. This one seems to be quite complex and sparsely documented (compared to AVR).

 

What I would like to do is use an external interrupt to cause one of the timers (counter) to increment. I would like to use another timer to periodically record (print to usart, save in nvm, etc) the count of the other timer and reset it to zero. Essentially I am building a frequency meter. I have tried using ASF3 via AS7, and was able to get the periodic timer and the external interrupt working, but I haven't been able to use the event system to connect the interrupt and timer/counter. I have done the same using Atmel START.

 

What do you recommend as the best way to do this (e.g. writing registers directly, asf3, asf4/START)?

 

Is Atmel START the first place I should be looking for hardware drivers?

 

Does ASF3/4 include the functionality to do this or will I have to resort to low level code regardless?

 

I have seen examples linking an external interrupt to a timer capture, but I have not seen one using the external interrupt to cause the timer to increment. Does an example like this exist and can someone point me to it?

 

I suppose I can always simply use the external interrupt to manually increment a counter variable and then record that value in my periodic interrupt, but it seems like there is a way to do this in hardware and I would like to be able to experiment with both methods.

 

Thanks.

 

-Colin

Last Edited: Thu. Sep 6, 2018 - 06:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To change the example to get the external event counting (for the TC) here:

https://community.atmel.com/foru...

you can remove this (i.e., don't enable input capture):

    TC3->COUNT16.CTRLC.bit.CPTEN0 = 1;
    TC3->COUNT16.CTRLC.bit.CPTEN1 = 1;
    while (TC3->COUNT16.STATUS.bit.SYNCBUSY);

and change the event action 

	TC3->COUNT16.EVCTRL.bit.EVACT = TC_EVCTRL_EVACT_COUNT_Val;

/Lars

Last Edited: Sat. Sep 8, 2018 - 09:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the help Lars. Do you know if this can be done using Atmel START?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I never tried but it's possible, the Timer module (when using a TC) has event configuration where "Event Action" can be set to "Count on event". Then one just have to figure out all other settings that will make an event channel where the EIC is the generator and the Timer is the user (for me that seems a lot easier to do in code).

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks again for your help Lars. I have got your example working for me.