3
\$\begingroup\$

I am using an STM32F405 based board (OpenPilot revo) to receive PWM signals from a joystick receiver.

I have to capture five PWM signals using only two timers, timer 8 and timer 12. I've already succeeded capturing a PWM signal and computing the duty cycle on only a channel for each timer using the example provided with the standard library (PWM INPUT).

But I couldn't use multiple channels for each timer. How do I configure the channels? It would be great if someone has an example with more than a channel used for PWM input.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ As a possible simplification, there's a decent chance that your channels fire sequentially, not in parallel. (In the old days, that was a given, as they were time multiplexed over an analog channel, but today the PWM will be locally synthesized by the receiver MCU, so in theory could overlap). In this day and age, you might want to look at directly re-implementing the receiver by talking to the appropriate (2.4 GHz?) chip module rather than capturing an output meant for servos. Code for doing this for whatever radio brand you use is likely already available online. \$\endgroup\$ Commented Oct 23, 2014 at 2:59
  • \$\begingroup\$ Some RC receivers also output a PPM waveform which is amazingly easy to decode with just a single timer. Just trigger a timer capture on each rising edge, subtract the previous capture time and you have the pulse lengths for every channel. Using interrupts for this is recommended. This format is the same that @ChrisStratton referred to with "they were time multiplexed over an analog channel" \$\endgroup\$
    – jms
    Commented Sep 19, 2016 at 12:16

1 Answer 1

1
\$\begingroup\$

Instead of using two capture units to capture rising and falling edges separately, use a capture unit to react to both edges of the signal(s) and determine the state inside the interrupt handler. Or use an external interrupt (pin-change) to react to either signal change and use a free-running timer to capture the counter value in software. If there is a lack of interrupts, you could OR (diodes) the signals to one interrupt input and check the source with regular inputs (one for each signal).

\$\endgroup\$
2
  • \$\begingroup\$ Pay attention to how interrupts are handled (priority) for the case where several signals change state exactly at the same time. \$\endgroup\$
    – handle
    Commented Sep 19, 2016 at 11:31
  • \$\begingroup\$ one µs more or less of latency is probably not an issue with servo PWMs. \$\endgroup\$
    – JimmyB
    Commented Feb 17, 2017 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.