Counting external pulses in counters: Teensy 3.2, Teensy 4.0 or something else?

Status
Not open for further replies.
I want to count two or three external signals that deliver pulses to the MCU, without ever missing one count.

Currently I am using a Arduino Mega 2560, but sadly it only has one counter input connected (T5 to pin 47). I have read that the Seeduino mega does break out more counters, but I am not sure how easy it would be to get one in Europe.

Now I understand that counters are very hardware dependent, and will probably look completely different on the ARM CPUs of Teensy 3.x or 4.0. Even on the AVR it was probably the most complex feature I ever used.

How difficult is it to do stuff like this (count the pulses on a pin, trigger an interrupt when count reaches 1000) on the Teensy? And should I choose the 3.2 or the new 4.0, or will it make no practical difference?

Thanks in advance,
Ralph
 
T_3.2 has one pin for FreqCount. It seems three were available on Teensy 4 - two edge pins and one bottom pad - but I'm not sure if they can work in parallel or if they overlap? And only one was mapped to FreqCount at this time.

How far apart are the pulses to each pin? Is the processor doing much else after seeing the target counts?
 
Thanks, defragster! One of the signals is 1kHz or so, one is 1Hz, maybe later some third signal will be added in the same range.

And I do not need frequencies, just aggregated totals from the last manual reset of the counter, if that makes a difference.
 
Just checking frequencies because the Teensy could just trigger an interrupt on each pulse and count them at those low rates without missing anything. If they were near or over 1MHz that could cause misses at some point - though the T4 could handle much faster.

T4 would do it easily with interrupt on RISE for each of three pins - and each pin with an _isr() could count and act accordingly.
 
Just checking frequencies because the Teensy could just trigger an interrupt on each pulse and count them at those low rates without missing anything. If they were near or over 1MHz that could cause misses at some point - though the T4 could handle much faster.

T4 would do it easily with interrupt on RISE for each of three pins - and each pin with an _isr() could count and act accordingly.

use FreqMeasureMulti

works fine on T3.2
 
use FreqMeasureMulti

works fine on T3.2

Thanks! I will have a look at that code.

Is there a direct equivalent to the 16 bit counters in e.g. the Teensy 2.0 (feeding an input to the T1 pin, counting in CTC mode, comparing to OCR)?

There does seem to be a Low Power Timer (there is only one of these?) and the FlexTimer (several of them), but can I hook them up to an external source, and count without generating an interrupt upon each external pulse, but only on coute
Is there a tutorial similar to https://www.robotshop.com/community/forum/t/arduino-101-timers-and-interrupts/13072 for the ARM family on the Teensy 3.2 or 4.0 on how to setup timers, what input pins they are linked to, etc.?
Even if with the faster CPU doing everything with interrupts is very feasible, I want to learn how to use timers -- if possible, and if it is not orders of magnitude more complicated than on AVR architecture.
 
There does seem to be a Low Power Timer (there is only one of these?) and the FlexTimer (several of them), but can I hook them up to an external source, and count without generating an interrupt upon each external pulse,

Yes, the low power timer supports this. It's used by the FreqCount library, so that should be your first place to look for example code. Of course, the reference manual gives all the details about the timers. The nice thing about LPTRM is it's fairly simple, not loaded with advanced PWM features that take hundreds of pages to document.

If you read the ref manual, you'll also see the FTM timers can theoretically do counting of external pulses. But you can't get access to the pins needed to give them a clock signal. Hopefully knowing that now can save you from wasting time exploring the huge FTM chapter, only to later discover scattered across other chapters that you can't actually use it.

It definitely does work with LPTRM, as FreqCount demonstrates.
 
Yes, the low power timer supports this. It's used by the FreqCount library, so that should be your first place to look for example code. Of course, the reference manual gives all the details about the timers. The nice thing about LPTRM is it's fairly simple, not loaded with advanced PWM features that take hundreds of pages to document.

If you read the ref manual, you'll also see the FTM timers can theoretically do counting of external pulses. But you can't get access to the pins needed to give them a clock signal. Hopefully knowing that now can save you from wasting time exploring the huge FTM chapter, only to later discover scattered across other chapters that you can't actually use it.

It definitely does work with LPTRM, as FreqCount demonstrates.

Thanks a lot for this, I had looked at the two chapters a bit, but compared to the Atmel timer documentation, it is probably 10 times as much information, and somewhat different terminology again.

I suppose I should arrive in the 21st century, and give up my 8bit habit ; Thanks!
 
Status
Not open for further replies.
Back
Top