help please : count the frequency of an oscillator with arduino atmega328p

Thread Starter

ahmed55

Joined Apr 8, 2017
40
i want to read the output frequency of my oscillator ( 50 - 150 MHz ) with arduino , the oscillator output is a sinewave signal . i used a frequency divider 1:64 MB504 , to reduce the frequency so that i can read it with arduino ( 8 MHZ) . i found many method to read frequency with arduino ( pulsln , freqcount ..) . the divider output voltage is 1.6 peak to peak . i need to addapt the voltage between 0 and 5 v . can anyone help me please ??
 

Attachments

shteii01

Joined Feb 19, 2010
4,644
I don't see why you need to change 1.6 Vpp to 0-5 V range.

You want frequency. Your ADC can detect positive peaks. Take two positive peaks, ignore negative portion of the signal, find time between the two positive peaks, that is the period of the signal. 1/period=frequency
 

tsan

Joined Sep 6, 2014
138
i want to read the output frequency of my oscillator ( 50 - 150 MHz ) with arduino , the oscillator output is a sinewave signal . i used a frequency divider 1:64 MB504 , to reduce the frequency so that i can read it with arduino ( 8 MHZ) . i found many method to read frequency with arduino ( pulsln , freqcount ..) . the divider output voltage is 1.6 peak to peak . i need to addapt the voltage between 0 and 5 v . can anyone help me please ??
On the simulation output voltage is from -0,2 to 3,6 volts and atmega328p counter input can detect it as is when the supply is 5 volts. Input threshold is about 3 volts.
 

Thread Starter

ahmed55

Joined Apr 8, 2017
40
i found method using analog comparator : https://arduino.stackexchange.com/questions/21157/arduino-read-frequency-of-input-from-audio-jack
Can I use this comparateur without the voltage divider ? and use the same code ???

volatilebool counting;volatileunsignedlong count;

ISR (ANALOG_COMP_vect){if(counting)
count++;}

void setup (){Serial.begin(115200);Serial.println ("Started.");
ADCSRB =0;// (Disable) ACME: Analog Comparator Multiplexer Enable
ACSR = bit (ACI)// (Clear) Analog Comparator Interrupt Flag| bit (ACIE)// Analog Comparator Interrupt Enable| bit (ACIS1);// ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)}// end of setup

unsignedlong startTime;

void loop (){

if(!counting){
startTime = micros ();
count =0;
counting =true;}else{// is a second up? (1000000 microseconds)if(micros ()- startTime >=1000000){
counting =false;Serial.print(count);Serial.println (F(" Hz."));}// end of a second being up

}// end of if

}// end of loop
 

Thread Starter

ahmed55

Joined Apr 8, 2017
40
I don't see why you need to change 1.6 Vpp to 0-5 V range.

You want frequency. Your ADC can detect positive peaks. Take two positive peaks, ignore negative portion of the signal, find time between the two positive peaks, that is the period of the signal. 1/period=frequency
Can you explain more how can I do that with an example or schematic ?
 

shteii01

Joined Feb 19, 2010
4,644
Can you explain more how can I do that with an example or schematic ?
We don't care about anything below zero because we don't need it. Your ADC is set to read the values above zero so you should not have any trouble reading the positive peaks.

Just figure out the time between the two peaks.

frequency.jpg
 

DickCappels

Joined Aug 21, 2008
10,171
I think he means the analog comparator can be used to drive the on-chip counter. One comparator input can be connected to the output of your counter and the other can use the internal 1.1 volt bandgap reference.
 
Top