Pulse counter using Teensy 4.0

aab5544

New member
Hi everyone,

Hope you are doing well.

I need some help and guidance on building a pulse/frequency counter with a microcontroller under $50. I have analog pulses 486 mV in amplitude and 100 ns wide that are coming from my photodiode TIA at frequency of around 60 Hz. I would like to feed these pulses into a microcontroller and have their frequency displayed on a screen. I wanted to know if the Teensy 4.0 is capable of processing and counting pulses like these. The specs say the analog pins can handle 0 V to 3.3 V, so I think my input voltage will be handled. Are the 100 ns pulses too short to be counted or will the Teensy 4.0 be fine? The pulses are low frequency (60 to 100 Hz) so there is ample time between pulses. I just don't want to miss any pulses. I have attached an image of one of the pulses on the oscilloscope. Thank you.
 

Attachments

  • 367742000_968102230935915_5896623680706023662_n.jpg
    367742000_968102230935915_5896623680706023662_n.jpg
    263.2 KB · Views: 27
If you boost the gain on your Trans Impedance Amplifier (TIA) to output 0 -> 3.3Volts you could send it directly into the Teensy 4.x and count pulses with no problem, otherwise you could send it into the A/D and then do anything you want with the results of the digitized analog signal.

Regards,
Ed
 
Hi Ed,

Thank you for the reply. So it is better to increase the output pulse to an amplitude in the range of 2-3 V? I can do that by increasing the feedback resistance but it will decrease the bandwidth, which I would not prefer. You mentioned sending the analog signal to the Analog to Digital Convertor, I'm assuming this is a pin and function on the Teensy 4.0 and then count the digital pulses without missing any? I just want to be clear in understanding what you mean before purchasing the board.

Best regards,

Aamer
 
You could also add another op-amp stage with the gain to raise the output to 3V, or put a comparator in instead of an op-amp.
The A/D converter on the 4.x is very fast, and the Teensy 4.x has a 600MHz clock so would not have any problem keeping up with a 100Hz input signal. It just depends on what you want to do with this signal out of the photodiode.
You have not given us much info on your final goal, so anything else anyone of the many expierenced engineers on this forum can do is just guess. This limits the possibility of our ability to help you.
There are many ways to solve this simple issue you have, so if you give us more info about your goal it would help immensely.

Regards,
Ed
 
Ed,

I tried using a second stage Op-Amp for additional gain, but there was too much signal degradation. I switched to the TL714 comparator and got a 4 V digital pulse but more than half of the square pulse was below the 0 V baseline on the oscilloscope. The 600 MHz explanation makes sense (1/600 MHz would sample ever 1.67 ns).

Sorry I was not clear, my goal is to make a portable pulse counter for these photodiode TIA pulses and display the value of the frequency on a small OLED screen. I would need a fast mircocontroller to process the pulses and output the counts per second/frequency on a OLED. I have seen people on YouTube do this with an Arduino + OLED, but my pulses are too small and short for the Ardiono. I went down the path of converting the pulse to a larger digital one using a compaprator and then stretching the pulse with a LMC555 timer, but again too much signal degradtion. I just want to count these pulses without missing any and output the results on a OLED. Hopefulley this cleared things up. Thank you.

Best regards,
Aamer
 
The ADC inside Teensy is far too slow for this type of narrow pulse.

You will need to handle this as a 3V a digital signal. A voltage comparator is probably the best way, but TL714 is probably too slow. I'd recommend trying a faster chip, like TLV3601.



This chip can also work with 3.3V power and has push-pull output, so you will get the proper output signal range to use with Teensy.

Your best chance of counting is probably with attachInterrupt() and a function that increments a variable and sets a flag to indicate it has changed. Both need to be "volatile". Then your main program can monitor the flag and update the display when the count has changed.
 
I tried to look up the minimum pulse width needed for the GPIO interrupt hardware, but couldn't find it in NXP's documentation.

But as a general rule of thumb, usually 2 clock cycles are needed because they almost always use a circuit that synchronizes the pulse to the chip's internal clock. The GPIO peripheral really does run at 600 MHz. Most of the other peripherals like timers run at 150 MHz, so you probably would not want to use a hardware timer (eg, FreqCount or FreqMeasure libraries).
 
Perhaps a fast opamp to boost the signal level, then fast comparator to convert to logic signal, followed by monostable to stretch the pulses. 465mV is probably enough with a fast comparator to avoid the need for the opamp.
 
I tried to look up the minimum pulse width needed for the GPIO interrupt hardware, but couldn't find it in NXP's documentation.

But as a general rule of thumb, usually 2 clock cycles are needed because they almost always use a circuit that synchronizes the pulse to the chip's internal clock. The GPIO peripheral really does run at 600 MHz. Most of the other peripherals like timers run at 150 MHz, so you probably would not want to use a hardware timer (eg, FreqCount or FreqMeasure libraries).
Hi Paul,

Thank you for your explanation. That means I have to convert the analog pulse to a digital pulse on the order of 3 V. I think 150 MHz would do the job for detecting the pulse only, I am not measuring them, just detecting them. Any idea where I can find a tutorial about setting up a frequency counting code for the Teensy?

Best regards,

Aamer
 
The ADC inside Teensy is far too slow for this type of narrow pulse.

You will need to handle this as a 3V a digital signal. A voltage comparator is probably the best way, but TL714 is probably too slow. I'd recommend trying a faster chip, like TLV3601.



This chip can also work with 3.3V power and has push-pull output, so you will get the proper output signal range to use with Teensy.

Your best chance of counting is probably with attachInterrupt() and a function that increments a variable and sets a flag to indicate it has changed. Both need to be "volatile". Then your main program can monitor the flag and update the display when the count has changed.
Hi @Paul,

Do you think the tlv3501 will also be sufficient?
 
Are the input pulses occurring at regular intervals? If not, you have to worry about stretched input pulses blocking incoming new pulses that occur soon after the first pulse. I got schooled on this issue when designing a radon scintillation detector as one of my first embedded microprocessor projects in the late 1970s. (That I remember that is NOT a testament to clean living—just a bit of luck in the genetic lottery!)
 
Back
Top