centralising the PWM pulse within the PWM sample duration
I did some experimentation with single sided and double sided PWM schemes. Double sided gave much better distortion, but single sided gave much better noise. I thought that the advantage that double sided gave to the distortion, was perhaps because the centre of it's pulse kept basically in the same place. So I tried it doing this with single sided PWM and was able to get the best of both worlds.
Here's an explanation with waveforms.
If you look at the +ve pulses, for a -ve sample the centre of the +ve pulse is near the start of the cycle, for a zero sample it's a 1/4 of the way through the cycle, and for a +ve sample, the centre of the +ve pulse moves out past 1/4 of the way through the cycle.
Code: Select all
_/---\_______/---\_______/---\_______/---\_______/---\_____ Single sided PWM -ve sample
_/-----\_____/-----\_____/-----\_____/-----\_____/-----\___ Single sided PWM zero sample
_/-------\___/-------\___/-------\___/-------\___/-------\_ Single sided PWM +ve sample
So I thought I'd try to keep the centre of the +ve pulse at the centre of the PWM cycle. This means changing the turn on and off time of the PWM depending on the sample value.
Code: Select all
__/---\_______/---\_______/---\_______/---\_______/---\____ Single sided PWM (centred) -ve sample
_/-----\_____/-----\_____/-----\_____/-----\_____/-----\___ Single sided PWM (centred) zero sample
/-------\___/-------\___/-------\___/-------\___/-------\__ Single sided PWM (centred) +ve sample
And I got much better results!