Hello,
I am using timer 0 and timer 1 for pwm waveform generation. Until the pwm is running all is well and good. But when I stop the pwm, the ports associated with pwm are land on some random position either low or high. I have given the code to low the ports but still the ports are at random position each time I stop the pwm.
I have tried to give delay ranging from 1 ms to 1000 ms. Used different types of techniques for lowering the ports. But at each time the code executes the ports are at random positions. The ports are PD5, PD6, PB1 and PB2.
Thanks in advance for your help.
We can just guess that you have setup PWM operation somehow, not shown in the posted code snippet. Stopping the timer doesn't release this connection, apparently neither a simple port write. A similar behavior would be observed with many processors implementing port mux, it's not surprising so far. You need to reprogram the port mode.
You are only showing part of the complete code. It is not clear if there is any other section of the program (eg interrupt handler) that might be reloading the duty-cycle value, and consequently returning those pins from general I/O to dedicated PWM outputs.
We can just guess that you have setup PWM operation somehow, not shown in the posted code snippet. Stopping the timer doesn't release this connection, apparently neither a simple port write. A similar behavior would be observed with many processors implementing port mux, it's not surprising so far. You need to reprogram the port mode.
The processor is atmega328p microcontroller.
There is a problem with the "stop" method of "pwm" class. In the stop method only clock source has been disconnected from PWM but the ports are not reconnect to GPIO. I have changed the code and now it's working fine.
Thanks again