# Papers on the Mathematical Basis for Using PWM for Sine-Wave Generation

Gold Member
@sophiecentaur I'll describe it with a little more detail.
-
I was using an 8 bit D/A with sine values stored in ROM. The address of the sine lookup table was also 8 bits wide but was derived from a 24 bit (or wider, can't recall) counter. I simply took the most significant 8 bits from this counter every 50 microseconds and used this as the address for the sine lookup table. Depending on how I stepped through the 24 bit counter would determine the frequency I wanted to synthesize. If you hadn't put it together yet, it's a numerically controlled oscillator.
-
Now where it got interesting is if I stepped through the counter in such small steps that the sine value didn't change from one 20 microsecond step to the next. I didn't really worry about it since the frequencies I wanted to synthesize were not in the range this occurred.

Gold Member
I was using an 8 bit D/A
50 microseconds
I see. You were using a sample rate of 20kHz and a quantisation of 1/28 relative to maximum value. For synthesising a 50Hz sinusoid, that would be very healthy. That makes 400X oversampling (or perhaps you could say 200X). Not surprising that many of the samples were 'repeated', near +1 and -1. The value of sin x doesn't change a lot around max and min. With 200X oversampling, you can throw away a lot of the resolution per sample.

Single bit DACs generate (of course) a lot of quantisation noise (distortion) but the power spectrum is spread out over the gap between zero and the sampling frequency. The final low pass filtering reduces the amount of noise power pro-rata, according to the base band bandwidth. Very low demands on the filter, in many cases if you can handle the high sample frequency.

As a matter of interest, what sort of maximum frequency will your synthesiser deliver?

Gold Member
I generally don't need it to generate anything above 3 KHz so the filter was set up to start cutting slightly above this. If I recall it was a 4 pole salen-key. However, that is not to say that if you plug the right numbers into it you can generate above that. It can go down into millihertz but there was really no need. Down to 75 or 80 Hertz was good enough.
-
Edit: For those following this, you probably realize that if there is no need to go down to millehertz then you may wonder why the counter is so large at 24 bits. After all, it takes forever to overflow a counter that size clocking through one count at a time every 50 uSeconds. The reason is for fine resolution within the band of interest. Numerically controlled oscillators are a fascinating subject. To me at least.

Last edited:
sophiecentaur