The PWM is fully capable of 0% and 100% duty cycle. However, there is 'trick'.
If you need 0% to be fully 'OFF', you need to make sure the the compare value is 0 and the compare mode set to PWM_x__B_PWM__LESS_THAN.
If you need 100% to be fully 'ON', you need to make sure the the compare value is equal to the period and the compare mode set to PWM_x__B_PWM__LESS_THAN_OR_EQUAL.
You can see if you need to 0% and 100% support without output glitching, you need to change the compare mode appropriately.
Thanks Len. I hadn't thought of changing the mode on detecting an input demand of maximum.
Saves me having to use control registers as my UDBs are almost all gone.
1 of 1 people found this helpful
I have another suggestion.
- Make sure that the period is at least 1 count lower than the maximum value allowed.
- Set compare mode to PWM_x__B_PWM__LESS_THAN. This will allow glitch-free 0%.
- When you want glitch-free 100%, set the compare value to the period value +1. Since the compare is higher than the period and the compare mode is '<' only, the output should be 100% glitch-free.
I have verified this approach. It works!
I tried to change the compare mode dynamically but there is no function.
However, your second suggestion worked thanks. I set the PWM period to 254 and have the PWM setup as LESS THAN compare and it then drives 0 at 0 compare value and 1 at 255 compare value.
Thanks for the help.
If you mark my second suggestion post as "Correct", I will get credit for it. Thanks.