Measuring Frequency using Arduino Mega

Thread Starter

abdulsamad4321

Joined Nov 24, 2013
38
Hi.... I am working on a Smart Energy Meter. I have measured the value using arduino Mega. For Current Measurement i am using ACS712 module and for voltage measurement i am using a Lm358 op-amp. I displayed value on Serial monitor of Arduino IDE. Now i want to fine frequency can anyone guide me how measure frequency from same circuit but only changing code? please help me. i can upload circuit diagram if anyone need.
 

AlbertHall

Joined Jun 4, 2014
9,666
Determining the peak is tricky and won't be very accurate. It might be better to choose a threshold near the middle of the waveform (the exact level is non-critical) where the voltage will be changing more quickly and a more repeatable timing will be achieved. For greater accuracy, time a number of cycles in a row and average.
 

BR-549

Joined Sep 22, 2013
4,938
Limit the frequency of interest to 5 volts. Or the voltage of the chip. Limit the current and feed it to an input pin. Set up a rising/falling(pick one) interrupt on that pin. Upon the first rise/fall interrupt.....start a counter. Reset new interrupt vector and reset interrupt. Upon second interrupt....stop counter. The counter count will be the period of the frequency of interest. One can modify and average if needed.
The counter clocks and chip clocks will limit high frequency range.
Audio frequencies and below should be easy.
 

Thread Starter

abdulsamad4321

Joined Nov 24, 2013
38
Determine a peak value, then count the time between peaks.
can you please tell how to detect peak in arduino or please give me code to detect peak.
Thank You Sir for you reply

Determining the peak is tricky and won't be very accurate. It might be better to choose a threshold near the middle of the waveform (the exact level is non-critical) where the voltage will be changing more quickly and a more repeatable timing will be achieved. For greater accuracy, time a number of cycles in a row and average.
Yes please can you give me code how to detect peak of a signal. or some logic or command you know that detects peak.
Thank You for your Reply Sir.

Limit the frequency of interest to 5 volts. Or the voltage of the chip. Limit the current and feed it to an input pin. Set up a rising/falling(pick one) interrupt on that pin. Upon the first rise/fall interrupt.....start a counter. Reset new interrupt vector and reset interrupt. Upon second interrupt....stop counter. The counter count will be the period of the frequency of interest. One can modify and average if needed.
The counter clocks and chip clocks will limit high frequency range.
Audio frequencies and below should be easy.
i limited it to 5 volts but don't know how to detect peaks. Can you please help me with that. A code, Logic or Command that you can tell which detects peak.
Thank you for your Reply Sir.
 
Last edited by a moderator:

BR-549

Joined Sep 22, 2013
4,938
I haven't looked at that chip for a couple of years now......and I think it has 130 some instructions.....so no....I can't help you with the programming.

What happens at the peaks of a sine wave? That's where the signal changes direction. We don't care what the voltage is when that peak happens......we just want to know the time. The time between two direction changes is called the period of the frequency.

The general I/O pins can detect that direction. This is all explained in the data sheet. Here is the first link of a google search.....

http://playground.arduino.cc/Code/Interrupts
 
Top