Newbee looking to create a square wave sweep generator
As far as the SX goes, I consider myself a definite newbee, even though I've owned the serial SX key for over a year now.... I recently tried to fire up the serial SX key and it to my dismay failed... well not to give up I ordered a new USB SX Key... anyways why I tried to use the SX is this... I'm looking to create a square wave sweep generator with the frequencies ranging from 0Hz to 300kHz.... Hopefully this is possible with the SX, since after posting a similar request on the BASIC Stamp side forum, the best info provided by Tracy Allen was to use the PWM command, however with the BS2p, the highest frequency I got was 200kHz, interesting but definitely not the solution to my problem... I need to create this·generator to give the frequencies, and pause for a said time at each frequency then increment to the next "sweeped" and/or "stepped" frequency...· I would also like to adjust the duty cycle of the square wave, on and off times at the said frequency.. I guess the first question I should ask is the SX28 capable of this task, and then the most obvious question, how do I start and can anyone please help.... Thanks.. Rob
Comments
I suggest starting with the square wave generation. Then work to vary the frequency. Then add pauses and adjust the duty cycle, etc. Start simple and take it step by step.
Keep asking questions as you need additional help.
- Sparks
You're definitely right, start simple, keep it simple.. I definitely read you.. Now I just have to try it... my brand new SX USB Key, is off to Parallax for evaluation as to why it gets so hot by being plugged into just the USB port, so back to the old reliable SX Serial Key....and yes I'll post more questions on this...
F = 1 / ((hpLow + hpHigh) * 0.000001)
With this code the theoretical range is 7.6 Hz to 500 kHz. You could fine-tune the ISR timing to change the max output; I selected one microsecond to make the math easy.
Keep in mind that at the high end your resolution will not be great; this list shows total cycles (hpLow + hpHigh) and the resultant frequencies:
2 : 500_000
3 : 333_333
4 : 250_000
5 : 200_000
6 : 166_667
7 : 142_857
8 : 125_000
9 : 111_111
10 : 100_000
You can see that as the cycle count gets larger the delta between associated frequencies gets smaller.
Post Edited (JonnyMac) : 8/19/2008 3:41:17 PM GMT