Shop OBEX P1 Docs P2 Docs Learn Events
Generating Digital Sine Waves — Parallax Forums

Generating Digital Sine Waves

darthsnarkeydarthsnarkey Posts: 9
edited 2012-12-22 12:41 in Propeller 1
I have been dabbling in the concept of making a tunable digital sine wave using 3 MCP42100 digital potentiometers. The basic schematic I'm using (for now) is available at:
https://www.circuitlab.com/circuit/565t62/digital-sine-wave/
I have made this public so anyone can edit it and help.

The concept is using variable resistance and voltage dividing to create a rough sine wave (more like steps than curves) then using a capacitor to act as a wave filter and smooth the shape of the wave to a low distortion sine wave. The concept has been proven sound but the hard part is the tuning of the pots in this to the correct (or closest to correct) resistance for several frequencies. the MCP42100 is a 100k ohm resistor and has 2 channels and can handle up to 10mHz each chip has a shift-register to control the wiper and has 256 even steps using 8 bit resolution.

Any Ideas and improvements would be greatly appreciated!

Comments

  • LeonLeon Posts: 7,620
    edited 2012-12-21 02:32
    Software DDS is a better technique.
  • Brian FairchildBrian Fairchild Posts: 549
    edited 2012-12-21 02:50
    Or 'Magic Sinewaves'.
  • Christof Eb.Christof Eb. Posts: 1,201
    edited 2012-12-21 05:58
    Hi,
    if you would like some more detailed answers, I think some more input would be good. What is your aim? Why did you do it like this? How does your circuit work?
  • darthsnarkeydarthsnarkey Posts: 9
    edited 2012-12-21 08:16
    Well I did it mainly out of curiosity. I was looking at doing some synthesizing with the propeller for fun but if there is a better way please share.

    I chose this approach since it is relatively low cost and produces a fairly good sine wave. I suppose I could use flip-flops to accomplish the same thing but it seemed more controllable to do it this way. By using a shift register I can turn on and off all 6 channels with 3 pins and generate a wide variety of sine waves. The main reason I did it this way is I have never heard of Software DDS or Magic Sinewaves.

    The circuit works like a voltage divider and creates "steps" up and down in voltage. While this would be close it is still too rough and by using a capacitor it smooths the difference in voltage and makes a reasonably good sine wave. The origin of this design is found at:

    http://www.falstad.com/circuit/

    It is under "Circuits > Analog / Digital >Digital Sinewave"

    this will also demonstrate the functioning of the circuit.
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-12-21 13:08
    Sine waves are amazingly uninteresting when making sound synthesis. By itself it contains no overtones and you can't apply any filters to make it interesting. That's the reason why it's rarely used in subtractive synthesizers or programmable sound generators. It's better suited as a low frequency oscillators to modulate parameters in the synthesizer. There are of course exceptions like additive synthesis, but it takes a lot of processing power and is extremely hard to program. By modulating sine waves in different ways (Frequency/Phase modulation) you can achieve interesting results though.
  • darthsnarkeydarthsnarkey Posts: 9
    edited 2012-12-21 13:39
    So noted! Thank you I was not sure how much I could do with the sine wave produced. Maybe I should look in a different direction for my sound solution.

    I was going to build this for my dad who built from scratch a synthesizer
  • KeithEKeithE Posts: 957
    edited 2012-12-21 22:09
    darthsnarkey - keep searching the forums. There have been various synthesizer/audio projects that you might want to check out. I'm sort of drawing a blank on some of the names and hopefully someone will respond with a list. But there have been various synthesis engines ( several sidcog or ???), a guy who built a sequencer with multiple props and used leds as both display and touch sensors and it may have supported a digital audio output interface SPDIF - blackbox?, look in the included demos for speech synthesizer and spatial positioning, there have been some effects like a Halloween echo effect, a guitar effects pedal see openstomp website, I'm sure that you could do a long looper with an SD or CF interface (who cares if you burn out an SD card early ;-) I'm sure that I've missed many, but this is a good community with a lot of relevant examples available. Another one - I believe that you can get the Hydra book for free now? That has some synthesis examples you could browse through.

    And there have been some audio playback demos - one that comes to mind based on personal experience is Kye's program to playback wav files from an SD card. On a hunch I took a PIR sensor, demo board, and Kye's code and made a dog detector for my mom's kitchen (I'm not living with her ;-) and my stern voice commanding the dog to leave the kitchen. IT worked, and I subsequently replaced the Prop with a Radio Shack playback module, but could have done interesting extensions with the prop.

    The cool thing is that you won't need a ton of external hardware - unless you want it. e.g. a MIDI interface might be nice to add. No problem for the Prop ;-)

    Edited to add - I think that Brad the author of BST had some success building a guitar tuner. He talked about the ideas but don't believe that he ever posted code.
  • kwinnkwinn Posts: 8,697
    edited 2012-12-21 22:29
    For the hardware side of things you may want to take a look at DAC's (Digital to Analog Converters), particularly Multiplying DAC's
    ( http://www.digikey.ca/scripts/dksearch/dksus.dll?k=multiplying+dac&vendor=0&mnonly=0&newproducts=0&ptm=0&fid=0&quantity=0&PV243=83&PV243=23&stock=1 )

    By outputting values from a table you can create any waveform you want, and by having the output of one DAC as the input to a second DAC you can vary the output amplitude of the second DAC.

    DAC two outputs the the waveform at the frequency you want, and DAC one controls the amplitude of DAC two to create the attack, sustain, and decay envelope.
  • Mark_TMark_T Posts: 1,981
    edited 2012-12-22 05:56
    Its fine to do the multiplying in software on a Prop, its fast enough for audio purposes, and saves a DAC.
  • kwinnkwinn Posts: 8,697
    edited 2012-12-22 12:02
    Mark_T wrote: »
    Its fine to do the multiplying in software on a Prop, its fast enough for audio purposes, and saves a DAC.

    True, but using two inexpensive 8 bit dac's provide a 16 bit (96db) audio output range, while you would need a more expensive 16 bit dac to do the same thing if you use one dac. It also saves a lot of cpu cycles that would be used for multiplying and shifting out 16 bit data.

    As with most things it is a trade off that depends on the project goals.
  • KeithEKeithE Posts: 957
    edited 2012-12-22 12:19
    OpenStomp has schematics and source code to interface with an external Codec. See http://www.parallax.com/tabid/699/Default.aspx
  • Mark_TMark_T Posts: 1,981
    edited 2012-12-22 12:41
    kwinn wrote: »
    True, but using two inexpensive 8 bit dac's provide a 16 bit (96db) audio output range, while you would need a more expensive 16 bit dac to do the same thing if you use one dac. It also saves a lot of cpu cycles that would be used for multiplying and shifting out 16 bit data.

    As with most things it is a trade off that depends on the project goals.

    24 bit stereo DACs are very cheap (WM8723 for instance, 0.66GBP at Farnell/Element14). Why compromise with 16 bits anyway?
Sign In or Register to comment.