Help!
ChrisK
Posts: 2
I thought this would have been easy for the STAMP to-do but it seems I could have been wrong..
Im looking to write a program for the stamp that will output a series of square waves at different frequencies starting at 2000hz down to 100hz with a 50% duty cycle.
Any ideas on this one?
Im looking to write a program for the stamp that will output a series of square waves at different frequencies starting at 2000hz down to 100hz with a 50% duty cycle.
Any ideas on this one?
Comments
That being said, have you searched on "Square wave" in the BASIC Stamp forum?
falcon
There's an FAQ that addresses your question - 5th from the bottom
http://www.parallax.com/tabid/385/Default.aspx
I tried a few things but was unable to achieve a 2 kHz square wave directly.
My BS2p outputs a 200kHz square (more the most part) using the following PWM command
I suppose you could run the PWM output to some external logic... a counter, logic gate, a flip-flop
http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/bincount.html#c2
I have tried using FREQOUT as well
As the manual states it has a range of 0 to 32767 Hz, but I believe this generates sine waves.
Go here:
http://www.parallax.com/tabid/440/Default.aspx
and download the "BASIC Stamp Syntax and Reference Manual 2.2 (5.3 MB)".
Look on manual page 199 (PDF page 203), you'll find the info for FREQOUT.
It doesn't produce a pure sinewave - it uses PWM to create the wave and it's up to you to filter the high frequency components of that construction as shown on manual page 200 (PDF page 204).
You could use this filtered output by running it into a Schmitt trigger inverter (i.e. 74LS14) for "squaring up" the waveform.
but it isn't fast enough for 2000Hz and the resolution isn't good.
PAUSE 2 is 188.0 Hz
PAUSE 1 is 301.2 Hz
PAUSE 0 is 757.6 Hz
no PAUSE at all is 1.19 kHz
I suppose you could try to stick some other code in the loop besides PAUSE for the lower frequencies, but 1.19 kHz is as fast as it will go.
Some of them are faster than others and can do faster LOOPs...
The classic BS2 and BS2e executes about 4000 instructions/second,
the BS2sx does about 10.000 instructions/second,
the BS2p24 and BS2p40 does about 12.000,
the BS2pe does about 6.000 instructions/second
and finally, the BS2px24 blazes away at 19.000 instructions/second.