See the documentation here: http://docs.micropython.org/en/latest/l ... mer.deinit
I've written the following code which sets a PWM going on pin X2. I see the signal, as I expect, on my oscilloscope.
I expect the PWM to be stopped when I call the timer's deinit() but it doesn't. My workaround it to set the PWM to a 0/100 ratio but I expected the deinit() to "Stop the timer, and disable the timer peripheral" as described in the documentation.
Can someone explain where I'm wrong please? I've searched the forum and assume I'm mistaken somewhere.
Code: Select all
from pyb import Timer, Pin
# Set a PWM output going on pin X2
tim2 = Timer(2,prescaler=83,period=40500)
ch2 = tim2.channel(2,Timer.PWM,pin=Pin('X2'),pulse_width_percent=25)
# Pin X2 outputting the PWM
# Count to 10 (seconds) to give me time to see the PWM on oscilloscope
for x in range (1,10):
pyb.delay(1000)
print(x,end='')
print()
# Stop the timer ######### THIS DOESN'T DO WHAT I EXPECT:
tim2.deinit()
# Count to 10 (seconds) to give me time to see if the PWM has stopped.
for x in range (1,10):
pyb.delay(1000)
print(x,end='')
print()
# Flat-line the PWM by setting it to 0/100 ratio.
ch2.pulse_width_percent(0)