PWM zero duty cycle not zero?

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
alanwms
Posts: 144
http://meble-kuchenne.info.pl
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 26 times
Been thanked: 7 times

PWM zero duty cycle not zero?

Post 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 2856 times

BenR
Matrix Staff
Posts: 1936
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 506 times
Been thanked: 688 times

Re: PWM zero duty cycle not zero?

Post 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.

alanwms
Posts: 144
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 26 times
Been thanked: 7 times

Re: PWM zero duty cycle not zero?

Post by alanwms »

Thanks Ben. I believe I will disable the PWM when at zero. Your sanity check, checked MY sanity

Post Reply