Shop OBEX P1 Docs P2 Docs Learn Events
Square wave to sine wave converter? — Parallax Forums

Square wave to sine wave converter?

achilles03achilles03 Posts: 247
edited 2009-01-06 19:09 in General Discussion
I'm looking for a relatively easy way to convert a square wave to a sine wave. It doesn't have to be super efficient, and it doesn't have to be a "perfect" sine wave. The frequency range I'm looking at is between 500 to 1000 Hertz. One method that I liked is shown here:

www.wenzel.com/graphics/pinet.gif

But my circuit analysis classes have faded from memory, so I can't model the response of that circuit to get an idea of how well it would work. Are there any other suggestions? Or any pointers how I could figure out that circuit?

Just to nip it in the bud, the speed at which I need to change frequencies is too fast to use the freqout command, and I need to basically switch pin states (i.e. a square wave).

Thanks in advance!
Dave

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-01-05 21:34
    achilles03,

    You can use any general circuit simulator to get a feel for testing that circuit. I can tell you though that for your application you would want to select the L and C so that it is close, but not at a resonate frequency of your input. The reason is that if you allow the circuit to resonate it will peak at that particular frequency in orders of magnitude and could saturate other parts of your circuit. By running your square wave frequency just under or just over resonate frequency you will have a response that's much easier to deal with over a frequency variance.

    Another method, that you might be able to incorporate, is to have a reference LC circuit that IS at resonance and time slice it as you need to produce your sine wave. I did this with the Propeller here...

    http://forums.parallax.com/showthread.php?p=739083

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • achilles03achilles03 Posts: 247
    edited 2009-01-06 05:09
    Thanks, that certainly is viable method. Based on what I need to do, I think I'll give a first shot to that pi network filter. I think it's basically a Butterworth filter?

    Anyways, I've set-up a time incrementation program in Matlab, but I'm still working out the equations.

    I'm a little rusty, so I could still use some help figuring out the circuit. What would the equivalent mechanical diagram for that be? I can see that it's a dashpot and spring in parallel with a mass, but I can't figure out where to place the left-most capacitor.

    Thanks,
    Dave
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-01-06 06:30
    achilles03,

    For quick and dirty "pop-corn" simulation stuff, I have been using this java based circuit simulator that Metron9 posted some time ago.· I have a local copy on my machine so I don't need to be online to use it.· It seems to be fairly accurate, fast, and stable.

    http://www.falstad.com/circuit/
    $ 1 5.0E-6 2.803162489452614 50 5.0 50
    v 432 368 496 368 0 2 500.0 5.0 0.0 0.0 0.5
    r 496 368 608 368 0 100.0
    l 608 368 704 368 0 5.0E-4 0.03617803862046759
    c 704 368 704 464 0 9.999999999999999E-5 0.0794203649371324
    g 704 464 704 496 0
    g 608 464 608 496 0
    g 432 368 400 368 0
    w 704 368 752 368 0
    c 608 464 608 368 0 9.999999999999999E-5 -0.008661706932758362
    r 496 272 608 272 0 100.0
    c 608 272 608 192 0 9.999999999999999E-5 2.3679128317210942
    g 608 192 608 160 0
    l 608 272 704 272 0 5.0E-4 -1.4457360054017436
    c 704 272 704 192 0 9.999999999999999E-5 -2.44105721405424
    g 704 192 704 160 0
    w 704 272 752 272 0
    g 432 272 400 272 0
    v 496 272 432 272 0 2 1000.0 5.0 0.0 0.0 0.5
    o 15 4 0 42 5.0 9.765625E-5 0 -1
    o 7 4 0 42 0.625 9.765625E-5 0 -1
    

    ·If you play with various frequencies and component values, you will see that a sine wave will be produced, but also notice the amplitude of the sine wave will change as you sweep your frequency.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 1/6/2009 6:36:57 AM GMT
    1440 x 900 - 199K
    SIM.JPG 199.3K
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-01-06 07:01
    transdot.gif
    achilles03,

    Here is another method that may work better for you.· It still suffers from a decaying amplitude as the frequency increases, but it isn't as bad as the pi-filter method.· This method requires two oscillators running into the inputs of an XOR gate.· The result is a PWM stream proportional to the differences in frequency.· i.e. if one input to the XOR is 4kHz and the other input is 3.5kHz then a 500Hz Sine wave will be produced on the output with a simple resistor/capacitor low-pass filter.

    $ 1 5.0E-6 1.1208435524800693 50 5.0 50
    154 544 176 672 176 0 2 0.0
    r 672 176 736 176 0 10000.0
    c 736 176 736 240 0 1.0E-7 2.1812757900336486
    g 736 240 736 272 0
    w 736 176 800 176 0
    v 544 192 464 192 0 2 4000.0 5.0 0.0 0.0 0.5
    v 544 160 384 160 0 2 3500.0 5.0 0.0 0.0 0.5
    g 384 160 352 160 0
    g 464 192 352 192 0
    154 544 384 672 384 0 2 5.0
    w 544 192 544 368 0
    v 544 400 464 400 0 2 3000.0 5.0 0.0 0.0 0.5
    g 464 400 352 400 0
    r 672 384 736 384 0 10000.0
    c 736 384 736 448 0 1.0E-7 2.5063545574723354
    g 736 448 736 480 0
    w 736 384 800 384 0
    o 4 8 0 42 5.0 9.765625E-5 0 -1
    o 16 8 0 42 5.0 9.765625E-5 0 -1
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
    1440 x 900 - 171K
    SIM2.JPG 171.1K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-01-06 18:04
    This thread is being moved from the BASIC Stamp forum to the Sandbox Forum as it is off-topic in the original forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • achilles03achilles03 Posts: 247
    edited 2009-01-06 19:09
    Ok, thanks for the move.

    I still haven't come up with the differential equation for the pi network shown above. I might try Beau's idea if I can't come up with the solution.

    Anyone else want to take a shot at it? Just as a refresher, I'm wondering what the equivalent mechanical system would be for the following circuit:

    www.wenzel.com/graphics/pinet.gif

    Thanks in advance!
    Dave
Sign In or Register to comment.