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.
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).