Hi
I'm a nooby in programing and I was wondering if it was possible to read PWM signal using a pyBoard ?
I have found timerchannel.pulse_width_percent but i dont know if it's useful.
thx in advance for your respond
ps. sorry for my english
Reading PWM signal
Re: Reading PWM signal
If you know the frequency and just want to read the duty cycle, then https://docs.micropython.org/en/latest/ ... e_pulse_us will do the trick.
This should be enough to (for example) read a servo signal.
This should be enough to (for example) read a servo signal.
Re: Reading PWM signal
You can also use the IC (input capture) mode of the hardware timers to do this. Here's an example that generates servo style pulses and measures them:
https://github.com/dhylands/upy-example ... ic_test.py
https://github.com/dhylands/upy-example ... ic_test.py
Re: Reading PWM signal
Thanks a lot for your fast responds !
I will try later when I have more time
I will try later when I have more time
Re: Reading PWM signal
So I tried both methods, but I only was successful with dhylands method. I think I made something wrong with machine.time_pulse_us, so if someone have an example of code with it, it would be super cool !
I'm trying to read PWM signal from an airplane receiver, so the frequency should be 50Hz
I'm trying to read PWM signal from an airplane receiver, so the frequency should be 50Hz
Re: Reading PWM signal
Using the timer capture mode is definitely a better approach, so stick with that.
I'm curious as to why time_pulse_us didn't work, perhaps the likelyhood of starting a measurement mid-pulse is too high. I'll investigate myself sometime.
Re: Reading PWM signal
Just wanted to thank you for pointing me to time_pulse_us() in order to read the PWM from a RC Receiver.
Works great on the Microbit, but had to find out first to set the input port to digital: pinX.read_digital().
Works great on the Microbit, but had to find out first to set the input port to digital: pinX.read_digital().