Shop OBEX P1 Docs P2 Docs Learn Events
Newbee looking to create a square wave sweep generator — Parallax Forums

Newbee looking to create a square wave sweep generator

fiveslofiveslo Posts: 40
edited 2008-08-19 15:27 in General Discussion
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

  • fiveslofiveslo Posts: 40
    edited 2008-08-16 04:16
    New USB SX Key gets so hot when plugged into USB port that I'm afraid to try anything now.. .Posted a question on the forum, I hope someone has a fix for this.... HELP !!!!!!
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2008-08-19 01:03
    Rob,

    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
  • fiveslofiveslo Posts: 40
    edited 2008-08-19 06:37
    Sparks-R-Fun said...
    Rob,

    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
    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...
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-19 15:27
    Here's a program to play with. It uses a 1 microsecond interrupt to control the square wave output. There are two 16-bit variables that control the cycle; one for the high side of the cycle (hpHigh), one for the low side (hpLow).

    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
Sign In or Register to comment.