I'm working on a rudimentary flight stabilization system for an airplane, which reads in 4 PWM inputs from an R/C receiver. The problem is, the pulseIn command is taking far too long to execute, so I need an alternative method of reading the four inputs. With all the code running except the PWM, my entire cycle takes ~ 45ms, however adding the four pulseIn(pin, HIGH)
calls leads to ~250ms cycle times, which isn't working out for me. Is there an alternative, perhaps an interrupt-driven, way to read the duty cycle time of the PWM lines?
Tell me more
×
Electrical Engineering Stack Exchange is a question and answer site for
electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.
|
|||||
|
the pulseIn is a blocking command that waits for it to complete, plus its overhead. Sounds like you should directly set up and us the Input Capture Interrupts. They capture the exact time of the edge, creating an interrupt. And some time (soon) after the Service of the interrupt reads the latch time. See example InputCapture.ino. From this example you can scale it capture all the inputs, assuming you have enough Input Capture Pins. If you don't need exact (nano second) then you can use PinChangeInt to get an interrupt and at time of Interrupt service record the time stamp. A bit latent, but may have the precision you require. |
|||
|