Shop OBEX P1 Docs P2 Docs Learn Events
Help with Counting frequency of tones — Parallax Forums

Help with Counting frequency of tones

lfreezelfreeze Posts: 174
edited 2007-11-14 21:28 in Propeller 1
I have been struggling through the Counter Modules and Circuit Applications section
of the propeller education kit lab series (most of it way beyond my skill level).
I have been able to assemble a counter
program (attached as COUNTER1) Which counts the cycles of tones generated by
the propeller. the tones are generated in a separate COG and are measured on an
asynch basis. I take enough snippets of the tone to get a consistent number
for each frequency.

I thought I would take this a step further and generate tones external from the
propeller and measure them using a smaller propeller program (attached as COUNTER2).
I used a BS2 and the freqout command, to generate the tones. I used the same
frequencies and intervals, but got very different unusable
results. I don't have a scope, so I could only verify the tones by listening to them.
They sound okay, but the measurements are not. I made a direct connection from the PIN on
the BS2 through a 1K resistor to the Propeller pin.

I don't know if I have created a bad program which will only work with propeller generated
tones, or I have to build an interface from the stamp2 to the propeller.
Any help or guidance would be appreciated. Here are some examples of the results I am
getting with both of the programs. Please excuse the length of this question, but I wasnt
sure how else to ask it.

Propeller measuremet of 1K, 2K, and 3K Propeller generated tones
Frequency = 0
Frequency = 0
Frequency = 0
Frequency = 1010
Frequency = 1010
Frequency = 1020
Frequency = 0
Frequency = 0
Frequency = 0
Frequency = 2020
Frequency = 2020
Frequency = 2020
Frequency = 0
Frequency = 0
Frequency = 0
Frequency = 2240
Frequency = 3030
Frequency = 3030
Frequency = 2720
Frequency = 0
Frequency = 0
Frequency = 0

Propeller measurement of 1K, 2K, and 3K Freqout tones from STAMP
Frequency = 0
Frequency = 0
Frequency = 0
Frequency = 48640
Frequency = 48690
Frequency = 25850
Frequency = 0
Frequency = 0
Frequency = 47350
Frequency = 47750
Frequency = 47720
Frequency = 0
Frequency = 0
Frequency = 0
Frequency = 47690
Frequency = 47710
Frequency = 47740
Frequency = 0
Frequency = 0
Frequency = 13880

Thanks in advance for reading this and for any help you can provide.

Larry

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-13 22:14
    The numbers you're seeing from the BASIC Stamp are probably accurate. The Stamp's FREQOUT statement does not put out a square wave of the selected frequency. Rather, it outputs a square wave that, when low-pass filtered, produces an approximate sine wave of the chosen frequency. To accomplish this, there are many extra transistions in the square wave. You could try low-pass filtering the Stamp output and measuring the result. I'll bet you come a lot closer to what you expect.

    -Phil
  • lfreezelfreeze Posts: 174
    edited 2007-11-13 23:12
    Thanks Phil, that solves the mystery. I· had thought that freqout produced a good sine wave as I had used it

    to create DTMF tones and it worked okay.· ·I will take your suggestion and try the low pass filter. I will

    also find another source to generate the tones as a further benchmark for testing..

    Larry
  • deSilvadeSilva Posts: 2,967
    edited 2007-11-13 23:47
    @Ifreeze: Your measurements are rather unprecise... The reason is that you you perform many instructions other than the WAITCNT in line 50.

    A substantial improvement of accuracy can be achieved when you set PHSA to zero just before the WAITCNT and read it immediately after the WAITCNT.

    Subtracting 2300 is not a good idea for many reasons...
    WAITCNT should take around 800 ticks extra only (ca. 10 µs @80 MHz)
  • lfreezelfreeze Posts: 174
    edited 2007-11-14 21:28
    I inserted the low pass filter that Phil suggested and
    It certainly improved the results (see below). I built a trial
    and error filter using devices I had on hand. I still think working with
    analog signal levels and frequencies is close to witchcraft, but I can't argue with
    success. The RC filter component combination
    that produced the best results were an a 1K ohm
    resistor with .1MFD capacitor. I also changed the program to include
    the suggestions DeSilva made. I also increased the reps by reducing the
    waitcnt. (revised program attached)

    Frequency = 21020
    Frequency = 21420
    Frequency = 21690
    Frequency = 21130
    Frequency = 0
    Frequency = 0
    Frequency = 0
    Frequency = 0
    Frequency = 22200
    Frequency = 33530
    Frequency = 32910
    Frequency = 32470
    Frequency = 27870
    Frequency = 0
    Frequency = 0
    Frequency = 0
    Frequency = 0
    Frequency = 143470
    Frequency = 146090
    Frequency = 142430
    Frequency = 144220
    Frequency = 6450
    Frequency = 0
    Frequency = 0
    Frequency = 0
    Frequency = 0

    Thank you both for your time and help.
    Larry
Sign In or Register to comment.