This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How could i control a sine waveform coming from a pwm signal?

Hi Everybody,
i have the following problem and i hope someone between you have the solution.
IÂ've wrote a programm to generate a sine waveform from pwm signals. This sine waveform has a variable frequency from 10 to 100Hz, with a step of 0.1Hz.IÂ've done this, using a look up table with more than 7000 values,i.e values for 10,for 10.1,for 10.2 ......
My first question is: does somebody know how to do this without using so many values?
I want also to control the amplitude(with a step of 0.5%) of the sine waveform. Do i need another look up table for this? or is there a possibility to do this with the same look up table for the frequencies.
Your Ideas will be a great help for me.
Thanks.
Note that the frequency of the pwm must remain constant.

  • My first question is: does somebody know how to do this without using so many values?<p>

    Well, there are several ways, depending on the accuracy you need.

    You could use a smaller lookup table and interpolate between the data points. A refinement would be an uneven spacing of the points of the lookup table, since a sine can be approximated better by a straight line in the vicinity of 0, pi, 2 pi, ... than in the vicinity of pi/2, 3*pi/2, 5*pi/2.
    Also, due to the symmetry of the sine, a lookup table only needs to contain the value for x=0...pi/2.

    Another way would be to ditch the table completely and use an approximation (for example by using a Taylor series).

    I want also to control the amplitude(with a step of 0.5%) of the sine waveform. Do i need another look up table for this?

    Changing the amplitude of a sine signal is a matter of multiplying the signal with the desired gain factor. No lookup tables are necessary here.

  • You have a lookup table for every frequency. That is not needed. You can instead have a table for a full sine wave (or a half or a quarter).

    Let's say you store the amplitude of a raw sine wave as a 360 units large table. Then you have one sample for each degree.

    When changing the frequency, you will then just have to keep track of the current angle in the range [0..360) and pick up the amplitude at that angle. After that, perform one time step and figure out a new angle to look up.

    As already mentioned, to change the amplitude of the generated output, it is enough to scale the value you get from the lookup table. If your numeric range is enough, you could have a volume value 0..64. Multiply the lookup value with the volume and divide (shift right 6 steps).