I have a simple Python script to run PWM (on RPI 5 8GB):
which generated a nice PWM: now if I run something (for example camera stream), PWM gets ruined/corrupted:
At least other (SPI) communications are not affected. Is this Python PWM generation somehow affected by CPU interrupts? Its seems that duty cycle is being altered, off and on intervals are not same (in second picture some 1 signals last for shorter time).
How can I fix this?
Code:
from gpiozero import PWMLEDfrom signal import pausefrom time import sleep# Define GPIO pin numbersGPIO_PIN1 = 25GPIO_PIN2 = 8FREQUENCY = 60 # Note: gpiozero sets default PWM frequency to 100Hz# Set up PWM on the GPIO pinsled1 = PWMLED(GPIO_PIN1, frequency=FREQUENCY)led2 = PWMLED(GPIO_PIN2, frequency=FREQUENCY)# Set duty cycle to 50%led1.value = 0.5led2.value = 0.5sleep(115)
which generated a nice PWM: now if I run something (for example camera stream), PWM gets ruined/corrupted:
At least other (SPI) communications are not affected. Is this Python PWM generation somehow affected by CPU interrupts? Its seems that duty cycle is being altered, off and on intervals are not same (in second picture some 1 signals last for shorter time).
How can I fix this?
Statistics: Posted by burst_again — Fri Feb 14, 2025 6:58 pm — Replies 1 — Views 67