Shop OBEX P1 Docs P2 Docs Learn Events
Frequency Counter — Parallax Forums

Frequency Counter

Gerry ShandGerry Shand Posts: 45
edited 2009-04-17 06:19 in BASIC Stamp
Hi All:

It has been awhile having been kept busy with a few project assignments but I managed to make it back.

I was wondering if anyone has been successful in using a BS-2 to create a frequency counter capable of measuring pulses between 1 - 10 Hz down to 3 decimal places? The intent is to read the signal for a pre-determined length of time (either 0.25 seconds or 1 second) and display the results on a LCD.

I have the circuitry required to convert the signal into a proper square wave (using a LM-339) and the pulse's duty cycle will vary. I also·have the program for the LCD as well.

Looking through the manual, I could use either the FreqIn or Count command but I am wondering about long·pulse width times versus the resolution.

Any advice?

Thanks in advance.

Regards,

Gerry Shand

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-15 16:38
    There is no FREQIN statement. Do you mean PULSIN? This won't quite do what you want.

    The COUNT statement will count the number of pulses seen in a time interval, but it gives an integer result. You'd have to count pulses for several minutes to get any sort of resolution.

    The PULSIN statement will measure pulse width, but not frequency.

    You could use calibrated loops to count pulses during a fixed interval. This would use a combination of PAUSE statements and the execution time of other statements to count pulses (edges) seen during a time interval. I don't think you could get the sort of accuracy you want with a BS2. The BS2 only executes about 4K statements per second
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-04-15 20:38
    This is inherently impossible.· That is, you can't count a 10-Hz signal, say, for one second, and come up with three-significant-digit accuracy.· If you count for any interval and get m pulses [noparse][[/noparse]or cycles], your maximum accuracy is 1/m.· Since you will get (in 1 second, for a 10-Hz signal) either 9 or 10 pulses, your inherent accuracy is about 11%.· That's not quite three-significant-digit accuracy.

    What you can do is measure the interval between two consecutive pulses, in microseconds for example, and then you will have the period in microseconds, from which you can compute the frequency [noparse][[/noparse]this conversion is left as an exercise for the student, as is the determination of the expected accuracy].

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net

    Post Edited (Carl Hayes) : 4/15/2009 9:20:07 PM GMT
  • $WMc%$WMc% Posts: 1,884
    edited 2009-04-17 03:05
    Gerry Shand

    This is just a thought.

    If Your 1-10Hz signal was used to enable the output of an external oscillator at Let's say 10kHz. ((10kHz value just for round numbers) " I haven't done the math" for what You need exactly.))

    The output from the external OSC. would start on the raising edge of Your 1-10Hz pulse, The OSC. would send out pulses @ 10kHz to the BS2 COUNT PIN until Your 1-10Hz went low or falling edge.

    With some experimenting with the external OSC. and the sample rate on the COUNT PIN on the BS2, The accuracy You want should be obtainable.

    This will take some " tweaking ", But I think it would work.


    _____________$WMc%__________

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-04-17 06:19
    $WMc% said...
    The output from the external OSC. would start on the raising edge of Your 1-10Hz pulse, The OSC. would send out pulses @ 10kHz to the BS2 COUNT PIN until Your 1-10Hz went low or falling edge.
    No.· That would measure pulse length, not pulse frequency.· You can't measure frequency that way at all, directly at least.· You can measure the interval between pulses (that is, the period, from which you can compute the frequency), but you would turn on the clock at a rising [noparse][[/noparse]not raising] edge and turn it off at the next rising [noparse][[/noparse]not falling] edge, and count the cycles of your external fast clock to determine the period.

    If the external clock is fast enough, you can get the resolution you need; and if its frequency is accurate and stable enough and your detection of the rising edge is precise enough, you can get the required accuracy, too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
Sign In or Register to comment.