How can I build a frequency counter for up to 50 MHz with Arduino? I know the max is 16 ISH MHz for arduino
Welcome to the forum
You started a topic in the Uncategorised category of the forum
Your topic has been moved to a relevant category. Please be careful in future when deciding where to start new topics
Like most high speed applications, you develop a high-speed front end (i.e, a counter) that you can sample at a more leisurely place with the micro,
How do you do that?
My friend Gustavo and I wrote the code and put together this project for a frequencyr up to 40mHz using an ESP32.
It is not for 50 mHz but measures up to 40 mHz.
Hth
The setup below tops out between 25 and 40 MHz (probably closer to the lower end due to the capacitance of the solderless breadboard). A 74AC flip flop prescaler would double that on a PCB setup. A 74LV8154 free running counter, a DS3231S to provide a 1Hz latching signal, a MAX7219 and LEDs for display, and the Uno to do the processing and control.
If you're going to use the DS3231S for an accurate 1Hz, get a real one from the likes of Mouser or DigiKey. There's little point in using something from Amazon or eBay which might or might not even be a DS3231S - just set up a 1Hz timer on the Uno in that case.
You do that by squaring up the signal and then dividing down by some constant divisor to where the signal can be counted by the counter you build. Many time a signal is divided by 10 or 100 so the decimal point of the counter can be mentally adjusted to the actual frequency.
So much depends on your needed accuracy.
Why do you need one?
Can you please tell us your electronics, programming, arduino, hardware experience?
Is this a school/college/university project?
Thanks.. Tom....
Going by this very similar post on Reddit, it's a school project.
How can I use a prescaler to measure frequency up to 50 MHz with an Arduino Uno?
- Add a binary counter between the source and the Arduino input.
When a time interval expires, read the binary counter.
Can you please elaborate or give me some more sources ? I'm a beginner at Arduino and this is a school assignment where the teacher didn't explain anything and didn't give some hints
Here is a hint. Set your prescaler to a divider that will output a pulse train that fits your Arduino program capability.
- A hardware binary counter can handle high clock speeds, example 74VHC4040.
- At reset, start a TIMER.
- You can read counter outputs with the Arduino when the (example) MSB transitions (an interrupt can be detected).
On interrupt, calculate TIMER value. - A matter of Math to get frequency.
The 74vhc isn't available in my country apparently can you give an alternative ? And I really want to understand you but not a single word is understandable to me :)))
-
TI makes the 4 bit counter SN74LV393B.
f(max) 85Mhz at 5V. -
Remember, the Arduino clock accuracy may be an issue.
'm trying to build the 50 mhz frequency counter that i made a post about a month ago. I'm using proteus to simulate the circuit because i cant find the counter anywhere. So basically what i was thinking about is using the 74hct4040 as to divide by 16 and then read the frequency in arduino and multiply it by the dividing factor. Here is the schematic
and here is the code
const int resetPin = 2;
const int q4Pin = 3;
void setup() {
Serial.begin(9600);
pinMode(resetPin, OUTPUT);
pinMode(q4Pin, INPUT);
digitalWrite(resetPin, LOW);
}
void loop() {
digitalWrite(resetPin, HIGH);
delayMicroseconds(1);
digitalWrite(resetPin, LOW);
unsigned long startTime = millis();
unsigned long pulseCount = 0;
while (millis() - startTime < 1000) {
if (digitalRead(q4Pin) == HIGH) {
while (digitalRead(q4Pin) == HIGH);
pulseCount++;
}
}
float frequency = pulseCount * 16;
Serial.print("Pulse Count: ");
Serial.print(pulseCount);
Serial.print(" - Frequency: ");
Serial.print(frequency);
Serial.println(" Hz");
delay(1000);
}
The problem is no matter what frequency i give in the signal generator the terminal always displays Frequency: 0.
Can someone please help me understand where i am wrong? I'm new to arduino and thought this project was to build a simple frequency counter with no external counters.
This will just increment pulseCount as fast as it can while the clock input is high. Not once count per pulse as you probably intend.
I'd consider doing this with a timer/input capture instead since the code execution overhead will be a problem trying to count ~3MHz pulses on a 16MHz core.
Let's see how you've wired everything up; get the hardware sorted first, then have another look at the code (which certainly has plenty of potential for improvements).
Also, have you verified with a scope that the output of your 4040 does indeed give the anticipated 3.something MHz pulse train from a 50MHz input?
Evidently, also/start by counting much slower, like a 100kHz input or so. Once that works, speed things up.
you should be more aggressive (divide by 256 - take the 8th bit) for example which will lead to a frequency of 195.3125 kHz (50 MHz / 256) which is more manageable on your 16MHz arduino if you want to do other stuff
you should connect that to an interrupt pin and monitor the number of fronts for a given duration to get the frequency