Closed BFjacky closed 2 years ago
Does there exist someway of calculating the real duty cycle of gpio-pin's output value?
In general, look at the simulation time whenever the pin goes high/low, and then derive duty cycle from that.
e.g. if the pin has been low for 10 ms, then high for 20 ms, then low for 10 ms, then high for 20 ms, the duty cycle would be the sum of the high times (20 + 20 = 40) divided by the total time (10+20+10+20=60), or 2/3 (66.66%).
You can see an example of doing it with code here: calculating LED brightness by measuring the duty cycle of PWM signal
I execute code on rp2040js like that:
As I expected, the duty cycle of pwm should be 10%. But i don't konw how to verify the result that i expect. I try to addListener on gpio-pin, then i receive a lot of output value of gpio-pin.Does there exist someway of calculating the real duty cycle of gpio-pin's output value?