Square wave to sine wave

Thread Starter

JBmtk

Joined Jun 29, 2009
23
Hello,

I am using a PIC16F877 to create musical pitches. Is is possible to convert the different pulses into a sine wave? I have heard of square wave to sine wave converters, but most of the drawings are biased for a certain frequency. Basically, when a switch is pulled, the PIC will output a certain pulse width, which will be a certain frequency obviously, to a speaker. I planned on driving the speaker with a FET (IRF540) and a push/pull stage.
 
Last edited:

Wendy

Joined Mar 24, 2008
23,421
There are several techniques that can apply here. I don't know anything but the basic about PICs, so I'm sure better input is coming.

There are techniques in wave form generation that involve feeding a digital signal to an DAC, creating a rough picture of the wave form in question. The problem is the clock frequency for the digital signal has to be many times greater than the signal being created, but it is accurate and had decent fidelity. A crude illustration I drew up for another thread looks something like this.



Another way to do it is simple filtering. If you feed a square wave into a good filter, out pops a sine wave. It is possible to make programable filters. This might be a better approach, but I don't have any references handy to help with it.
 

millwood

Joined Dec 31, 1969
0
Is is possible to convert the different pulses into a sine wave?
yes.

1) the easiest (and also the most difficult, depending on where your skills are) is to generate a pwm signal and pass it through a low-pass filter (a rc network). then you will have analog output on the other end.

2) the more difficult one is to generate an analog signal directly, using a r2r network. you will need to have a few more pins: a 3-pin r2r network will have 8 levels, and an 8-pin r2r network 256 levels.

3) you can also use a dedicated dac: it can be via serial interface or parallel interface to the pic.

all depends on how comfortable you feel about your programming / hardware skills and how far you are willing to go. approach #1 is the simplest but it also has the least amount of flexibility in terms of the signal it can generate. approach #3 is the least complicated but also the most flexible and most costly.
 

THE_RB

Joined Feb 11, 2008
5,438
Hi, i've worked a little with musical synth design, the sinewave is really your least desirable wave shape to make. If you make a note using a squarewave or triangle/sawtooth etc it has a lot more high frequency content and can be easily filtered with some simple hardware to give many different musical "timbres".

The typical system generates a note using a squarewave and PWM so you can vary the pulse width from a couple of percent up to 50%, this gives a lot of timbral variation in itself, then use some hardware filtering (usually low-pass) to further adjust the timbre.

Unless you have a specific reason to make sinewaves (like testing speakers etc) they really don't sound very good musically.
 
Top