i want to read frequency realtime

Anyway, I am hoping to improve the accuracy. After watching Dave Jones' video about surplus Rubidium Frequency Standards available on eBay cheap, I've ordered one. That is supposed to deliver a super-accurate 10 MHz signal. By using that as the source for Timer 1 rather than the internal clock you should be able to get a very accurate count (within the resolution that 10 MHz gives you).

I saw that video also and was very impressed at the prices of those used surplus clock sources and considered buying one. However I long ago bought a 10mhz OCXO oscillator on e-bay for like $15 and to be honest haven't used it much other then as a standard to check other instruments against. So while the Rubidium standard carries a much higher coolness factor, a good OCXO is much more cost effective, much smaller, and good enough for anything outside of a laboratory environment.

Typical offerings:

http://www.ebay.com/itm/ISOTEMP-OCXO131-191-10Mhz-OCXO-OSCILLATOR-SQUARE-WAVE-/180808600834?pt=BI_Cellular_Optical_Television_Test_Equipment&hash=item2a19084d02

And it's spec sheet showing accuracy: frequency stablity is +/- 25 ppb (yes billion), so about 1000X better then a typical microcontroller crystal.

Lefty

Interesting, thanks!

@Nick Gammon

I did my best to program my frequency counting code. It look basic, but it work. retrolefty just discuss about a high frequency feed into a test signal, and count those fast pulse. I juts sudgest that in the tread : measure a 60 Hz precisely. I did a code fot it and it work. I was using pulseIn(). Your code is better.

Heh, I am doing my best...

That's fine: "go with what works", I say. And if I write something, and it works for the situation at hand, I am happy. The simpler the better. :slight_smile:

In this case however, where 10 KHz was quoted, we had to try something else.

Yeah...I agree. My code work because I use the 1 second baseline and count pulse inside that 1 second. And my 60 / 50 hz monitor work by using pulseIn() for the High and also for the LOW. But your code is better...

About the hardware side, just a squarewave from 0-5 at X frequency going into a digital pin 2 ( interrupt 0 ) ? Right ? or it is a +/- wave using a zero crosing, just my up-dated schematic in the tread : http://arduino.cc/forum/index.php/topic,87699.0.html, in the last posting.

I will use your code and study it so I can understand it, if you don't mind.

Anyway... good work ! :wink:

@Nick Gammon

Just a question :

TCCR1A = 0;
  TCCR1B = 0;
  // Timer 1 - interrupt on overflow
  TIMSK1 = _BV (TOIE1);   // enable Timer1 Interrupt
  // zero it
  TCNT1 = 0;     
  // start Timer 1
  TCCR1B =  _BV (CS20);  //  no prescaling

This section of your code. It is came from the ATMEGA328P datasheet ? I wonder where can I get this info.

Yes it's all in the datasheet. It's the primary font of knowledge about the chip.

Be prepared to read it many times (like I did) before it all sinks in. :wink:

Thank Nick.

I will read it many time... :roll_eyes:

you guys are all amazings...... techone your code works really well but i couldnt use cos i need faster updates in frequency than 1 second but if a reduce the sample time it just gives errors....... nick you code its very accurate, but i still have something i would like to think of..... its that for signal comming out from a sensor signal its not that perfect square, so how i was thinkig that a low-pass filter with bessel eq. could work to clean that, but to be honests i know bessel but i dont know how to applied it to a program to filter the signal....

still your code its amazing, probably this would become a playground link to your code......

but i will follow your lesson and read many many time atmega 328 datasheet jeje

@copachino

Check the link in my post in this tread. To measure a 60 Hz sine wave into a square wave, I have to build an op-amp, comfigure into a comparator. The LM339 did not work. I was force to use a 741 op-amp, using a dual voltage ( two set of 4.5 battery pack ) , a diode and a transistor using a 5 V to make sure the output of the transistor is TTL compatible.

Here the link again and check the last post for the schematic. It will give you an idea.
http://arduino.cc/forum/index.php/topic,87699.0.html

i see if i can get one og those to try it out

@copachino

Any regular op-amp will do. A dual type or a quad type or a single is just fine. Just check the datasheet. The dual power can be made like :

positive wire 9 V negative - com/gnd wire - positive 9 V negative wire. Just connect two battery pack in series. The mid part is the gnd or commun.

As for power up. 1. Power up the Arduino. 2 Power up the dual power circuit 3. power up the input signal.

Why ? If the Ardiuno board is off, and you got a signal into the pins, it may damage the Arduino.

i got some lm386 so id see if those have a good behavior... thanks fo reply

copachino:
i got some lm386 so id see if those have a good behavior... thanks fo reply

An LM386 is not a op-amp, it's a low power audio amplifier chip, and as such not a good candidate for comparator type duty.

Lefty

thanks for that jejeje ahhh well i have to get some op-amp and try them for a good response

I agree with Techone about the op-amp. I did a bit of experimenting with them:

That was for an LDR, but if you used a voltage divider to get the comparison point as half-way through the voltage range you expect, then that should clean up a non-square signal into a square one.

i used a LM339 but it never work am trying to make an analog sensor output tobe square but still getting negative results...... so nick with the lm358 what do i need to change in the circuit to get a high input when my sensor gives 200mv o maybe 100mv...... its an inductive sensor so when the magnetic field its low the output voltage its 100mv or something near.....

this is a sample on my sensor took from the analog A0 and plotted with kst

Uploaded with ImageShack.us

for this i am holding a magnet with my hand and passing it to the sensor the fastar as i can, but if you see there when is low speed the output get too low voltage, anl also there is a lot of noise coming from the sensor

Right. Well what you want to do is set up the op-amp as a comparator. You need a voltage divider on the - input to the op-amp (eg. pin 2) and your signal into the + (eg. pin 3) input.

Looking at this page:

http://www.raltron.com/cust/tools/voltage_divider.asp

I type in that I have 5V input voltage, and a 10K as R1 (from 5V to pin 2). I want 100 mV comparison voltage for the op-amp so I type 0.1 as the output voltage and hit "calculate". It tells me to use a 204 ohm resistor, so say use a 220 ohm between pin 2 and ground. Now you should be able to measure around 0.1V on pin 2 of the op-amp. That means it will turn on when the input on pin 3 is above 100 mV and turn off if it is less, thus "squaring up" your input.

Something like this:

thank you so much jejje ummm but i cant get an op-amp right now stores are close so i need to wait till monday.
but maybe a could try this with the lm339 if not i will have to wait till then....

thanks again all of you techone, nick gammon and retrolefty..... you guys have help me a lot

one doubt 220R its going to ground?

copachino:
thank you so much jejje ummm but i cant get an op-amp right now stores are close so i need to wait till monday.
but maybe a could try this with the lm339 if not i will have to wait till then....

thanks again all of you techone, nick gammon and retrolefty..... you guys have help me a lot

one doubt 220R its going to ground?

Here is a link to the datasheet for a LM339. There is a typical application section that should show you how to use the chip. Most people that have trouble with this chip forget that it has an open collector output that requires an external resistor wired between the output pin and +5vdc. The programmable internal pin pull-up option for an arduino input pin can satisfy that requirement.