Page 1 of 1

PWM zero duty cycle not zero?

Posted: Mon Mar 15, 2021 1:45 am
by alanwms
I have noticed on all of my PWM channels that they produce a very fine PWM pulse when a value of zero is loaded? The width is 240ns

Pic24Fj64GB002 10 bit StetDutyCycle = 0
Changing the duty cycle to 1 makes no change.
Changing the duty cycle to 2 changes the pulse width to double time 480ns

Is the compiler not allowing zero?
Scope Trace.jpg
Scope Trace.jpg (108.62 KiB) Viewed 2862 times

Re: PWM zero duty cycle not zero?

Posted: Mon Mar 15, 2021 11:09 pm
by BenR
Hello,

Yes when the duty is 0 we actually change the value to be 1 instead of 0. We do this as a duty of 0 on the 16-bit PIC hardware seems to generate some strange output waveforms which aren't 0% duty. I've just tried it here as a sanity check and some very odd things happen.

If you must have absolute 0% duty then it might be better to disable the PWM channel instead of assigning 0 duty.

Re: PWM zero duty cycle not zero?

Posted: Tue Mar 16, 2021 5:25 pm
by alanwms
Thanks Ben. I believe I will disable the PWM when at zero. Your sanity check, checked MY sanity