Most Efficient Way to Generate Varying Duty Cycle and PWM

Technical questions regarding the XTC tools and programming with XMOS.
kuba
Junior Member
Posts: 6
Joined: Sat Aug 27, 2011 5:51 pm

Post by kuba »

kster59 wrote:Anyway, how about varying duty cycle with optimal spacing (50% duty should be 1010101 etc, 25% should be 100010001000, etc)? Usually this is done in hardware with a NCO with adding a number to a base and if the number overflows then set it to 1
There's nothing globally optimal about having 50% duty cycle represented as 010101... For some applications it makes sense -- say if you're using PWM to emulate a DAC, it keeps the quantization noise as far away as possible from the baseband.

If you're using the PWM output to drive a mosfet power switch, you'll be wasting TONS of power. Precisely, you'll be wasting fBITSTREAM/fPWM times more power. Suppose your PWM would be running at 1kHz, and you run the BITSTREAM at 10MHz. You're producing 10E3 more transitions -- each transitions needs to charge or discharge the gate on the power switch, and dissipates a fixed amount of energy.

If all you want is an easy-to-filter sine wave, then you should look into using magic sine waves http://www.tinaja.com/magsn01.asp. Those are sequences of zeroes-and-ones that are optimized not to generate any harmonics between fundamental and a chosen high harmonic. Higher frequencies are much easier to filter out. Don Lancaster's website, linked above, has online calculators for those, as well as provides theory necessary to generate such sequences (it's not trivial, and no closed-form solutions are known to exist so far).