The code is simple, just randomly start/stop a PWM in an infinite loop:
#!/usr/bin/python import RPi.GPIO as gpio import time import random gpio.setmode(gpio.BCM) gpio.setup(21, gpio.OUT) pwm = gpio.PWM(21, 100) num_start = 0 num_stop = 0 while True: mode = random.randint(0, 1) if mode: num_start += 1 print("start %d" % num_start) pwm.ChangeFrequency(100) pwm.start(50) else: num_stop += 1 print("stop %d" % num_stop) pwm.stop() time.sleep(0.1)
The circuit is also simple: GPIO21 and ground is directly connected to a LED.
After several hundreds of start/stop, the PWM on GPIO21 will not starts again. But if you exit python and restart the program, it will recover.
Why this behavior occurs? Is it lies on the software side or circuit side?