I'm new to the ADuC841, my prior experience is with Cortex-M based microcontrollers.
I'm using ADuC841 with the dual 8-bit PWM mode on pins P3.4 and P3.3 (configured in sfr CFG841).
For a simple 50% duty cycle with full 8-bit resolution I use this code:
PWM1L = 100; // output resolution PWM0 PWM1H = 100; // output resolutionPWM1
PWM0L = 50; // dutycycle PWM0
PWM0H = 50; // dutycycle PWM1
PWMCON = 0x53; // PWM on, Mode 5, Clk/1, Clk = Fosc
This results in a nice square wave with frequency = f_xtal / 100 and just about 50% duty cycle, see screenshot:
However, when I set duty cycle to 0%, there's still a small pulse output on the pins, see screenshot:
Instead I expect the PWM pins to stay permanently at low level.
Please advise how to set PWM output to 0% duty cycle.
For PWM0, there is no workaround since the pin will always go HIGH when the PWM counter is 0. This should be the same case in PWM1 but it will be in reference to PWM1H/L. If you want a 0%, it is best…
By the way, 100% duty cycle works as expected.
So far my workaround for a duty cycle of 0% is to disable PWM and to set GPIOs to output TTL low:
P33 = 0;
P34 = 0;
PWMCON = 0x03;
PWMs can not be disabled individually, so I have to disable PWM completely. That's not a problem at my particular application but excludes this workaround for general applications.
Any other ideas?
For PWM0, there is no workaround since the pin will always go HIGH when the PWM counter is 0. This should be the same case in PWM1 but it will be in reference to PWM1H/L. If you want a 0%, it is best to disable the PWD and put then configure the pins as output and then force it LOW.
Thanks for your reply. Strangely, I did not get any notification about it. Therefore my late reply.
I'm glad I did not see any "ghosts". Basically you are confirming that there's an issue with PWM at 0% and that it's not possible to set one channel to a perfect 0% and the other to a value greater 0%. Thanks.