Sine wave


Closed Thread
Results 1 to 9 of 9

Thread: Sine wave

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Darren,

    I've played with the numbers from the website you started with.
    And either I got it wrong, or that's one "messed up" example.

    To start with, it's not the way an R2R network is supposed to be laid out. Which accounts for the lower amplitude.
    A description of a proper R2R network can be found here ...
    http://en.wikipedia.org/wiki/Resistor_Ladder
    But his way does have fewer parts.

    Barring the fact that his binary numbers are all backwards ...
    With the program from that web page, it doesn't make a Sine wave.
    But it's not a bad "Triangular" wave.

    Here's a spreadsheet of my results. (html)

    http://www.pbpgroup.com/Calculators/...R_SineWave.htm

    The top section calculates the voltage output for each of the digital possibilities.
    These numbers seem quite different than what the web page author came up with.

    The resistor values can be changed to test different conditions. If you change them to exact multiples (1000, 2000, 4000, 8000), you can see that Vout is very linear, although still low amplitude.

    The section below the graphs calculates Vout for the "SIN" sequence.
    These numbers can be changed, and might help test your calculated SIN values.

    But I have to wonder if a 4-bit sine wave at 50hz is going to be what you want. It'll look more like a staircase than a sine wave. You could add a lot more capacitance to the filter, but at 300 hz it may be too much.

    hth,
    DT

  2. #2
    Join Date
    Mar 2004
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Thanks Daryl,
    I will give it a go when I get a spare hour. One concept that I had completely overlooked is the fact that the outputs go low (silly me). I was only calculating using the hi 5v state and not the low 0v (GND) state which will completly change my calculations.
    Thanks, I will let you know how I go

  3. #3
    Join Date
    Mar 2004
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Daryl,
    I had a go using your data and got the same result (not what I was hoping for a sine wave). I decided to increase to 6 bit and have another stab at it. I got the same triangle wave that you had on your example. (still not the expected sine wave). I then divided 180 degrees down to the same number of samples, used the sine function, added 1 (then no negative voltages), and scaled to same as actual voltages. I had a new set of data that I used to base my output on. essentialy I picked the closest actual value to the calculated value. I graphed the new data and got the attached waveform (more like a sine wave). This was acheieved by repeating some of the samples with the same voltage and on some skiping voltages. Now I am not sure how the best way to implement it is? do I create a table using this data and simply step through? or do I use the sine function in the pic basic to calculate the output?
    Attached Files Attached Files
    Last edited by Darrenmac; - 18th May 2009 at 02:01. Reason: forgot attachment

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The SIN function will be the easiest.
    It's what the FREQOUT statement uses to generate its sine waves.

    It's essentially a pre-made lookup command. So it'll save you some work.
    The result is an 8-bit number so you could just shift right twice and have your 6-bit value. But 8-bit would be better at such low frequencies.

    You may also want to look at this from sirvo ...
    http://www.picbasic.co.uk/forum/show...5843#post65843

    I've pointed to the video of the finished project, but further up you can see how he did it.

    It uses a lookup, and 10-bit PWM (with 8-bit values) instead of R2R.
    I wish I had a scope like that.
    DT

Similar Threads

  1. To Generate Sine Wave Using PCPWM of PIC18F4331 (Issue)
    By Cyborg in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd March 2014, 13:39
  2. Generating 3-phase sine wave..
    By sirvo in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 6th November 2008, 14:07
  3. square to sine wave help
    By TONIGALEA in forum General
    Replies: 6
    Last Post: - 2nd July 2006, 09:32
  4. Replies: 1
    Last Post: - 16th February 2005, 20:05
  5. PBP Dampened Sine Wave
    By Keith55555 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd April 2004, 20:01

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts