Sunday, 25 February 2018

avr - atmega32u4 use Timer as souce for a counter


I started to play around with an atmega32u4 and came across a question I wasn't able to solve right now (may be I just missed the right page in the 500 pages datasheet).


I was able to create a routine that allows me to generate a configurable clock signal on PB5. Yeah! :D


Now I had the idea to use this clock as source for an counter to easy able to generate interrupts on a configurable amount of clock cycles for example on every 42nd.



As far as I figured out the use of counters I need to connect the T(0-1) pin to the clock source right?


Now my question is there a way to use the generated clock without the need of a wire between PB5 and the Tx pin?


Sadly there is no T pin for Timer3? So I need to swap timer1 and timer3 to generating clock with timer3 and connect it to timer1's T pin?



Answer



There is no way around it, you need the external link.




The only other way to do it is to use Timer 4 to generate your clock. One of the outputs of Timer 4 shares a pin with the T1 pin, so theoretically you could set Timer 4 up to toggle the output pin, and Timer 1 to use the T1 pin as its source and save an IO pin in the process.


The pin would have to be configured as an output in order for Timer 4 to generate the clock, however this is not an issue. Even in the Tx pins are configured as outputs, they can still clock the internal timers:



If external pin modes are used for the Timer/Countern, transitions on the Tn pin will clock the counter even if the pin is configured as an output.




(Extract from Datasheet, P134)


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...