How to generate a sinusoidal PWM with variable frequency?
I'm trying to generate a sinusoidal PWM on STM8, but it's for an equipmetn that the user will change the frequency of the output sine wave while the PWM is running. I was able to generate a sinusoidal pwm easily for a fixed frequency, using a table I calculated before starting the PWM.
But I'm not having success in changing the output frequency, because for that I need to recalculate the table and this is a slow process. I also tried to calculate the value every PWM cycle, but since I'm using 15kHz for the carrier wave, the calculation is too slow.
I've also thought about using two tables, so that one is used while the other is being recalculated, but this use more than the 1kB of microcontroller RAM.
Has anyone ever faced something like this and could indicate some way to be followed to solve the problem?
PS.: I'm using the STM8S003F3, and besides the PWM I need to read an ADC channel and communicate some bytes via UART, so I need to worry about leaving a little space for that too...
Regards,
