2
\$\begingroup\$

I need to handle PWM output from a single channel of an R/C receiver. I want to count the width of the pulse roughly in 4ms increments, and based on different widths take action by switching LEDs (20-40 mA) on and off.

I know how to do this using an Arduino but would like to know if it is possible to do the same thing using a simpler (and cheaper) programmable device such as a CPLD or small-scale FPGA. Basically I need to time the pulse edges and manage the on-off states of outputs. If the outputs can sink the LED current so I don't need to add transistors, that would be a plus. Ideally I'd like to be able to handle steady state as well as flashing.

There seem to be a lot of parts that can generate PWM (i.e. motor drivers) but not as many examples of PWM decode, apart from Arduino examples. Which device(s) would you use to solve this problem?

\$\endgroup\$
5
  • 3
    \$\begingroup\$ Usually FPGAs and CPLDc are 1) more expensive. 2) The tools are more expensive. 3) More difficult to work with. So I think your assumptions do not hold. But yes, of course it is possible. There is nothing microcontroller can do FPGA can't. \$\endgroup\$
    – Eugene Sh.
    Commented Jan 11, 2016 at 19:08
  • \$\begingroup\$ The FPGAs I'm used to having other people work on such as Altera Cyclone series are definitely out of the range for now. I'm trying to start with something I can work on with free tools and inexpensive adapters. One option seems to be the Atmel ATF16V8B series but before jumping into working with one of these I am not sure what other options there might be, or even whether devices in the low-cost range might be capable of this type of task. Thanks for your reply! \$\endgroup\$
    – Henry G
    Commented Jan 11, 2016 at 19:26
  • \$\begingroup\$ Today you can get a $10 eval board with a decent Cortex-M4 MCU on it, and simple USB programming, solving your problem in zero time. Why overcomplicate? \$\endgroup\$
    – Eugene Sh.
    Commented Jan 11, 2016 at 19:28
  • \$\begingroup\$ STM32 MCU has built in timer function for this. Input pulses -> output PWM ratio. \$\endgroup\$ Commented Jan 11, 2016 at 19:33
  • \$\begingroup\$ @HenryG Avoid SPLDs like the 16V8 for new designs. They're extremely old, limited, and difficult to work with. \$\endgroup\$
    – user39382
    Commented Jan 11, 2016 at 20:54

2 Answers 2

2
\$\begingroup\$

With 4ms timing a micro-controller will be fine. Use an arduino for the least complex and time consuming method of reading your 4ms pulse. I'm not sure how the timers work but here is some info: http://playground.arduino.cc/Code/Timer1

I know the stm32f4 nucleo boards have 32 bit timer on a few of the pins if you really need the accuracy. Compilers are harder to find for those boards but I think that they have one for the nucleo's now that is free. You will spend more time finding\getting familiar with the tools.

If you really want to use an FPGA, the MAX10's from altera are one of the best bets. you can get a dev board and a programmer for 100$ And the tools will work for free (quartus prime web edition) as long as you don't want to put anything fancy on the board like an arm core (you can still run their paid IP but you have to be tethered to their software). You will probably spend 20 hours minimum getting familiar with the tools if you have never worked with an HDL before. Another option is lattice that has a usb stick with a CPLD on it, but I can't vouch for their tools

\$\endgroup\$
5
  • \$\begingroup\$ Thanks, that's a lot of very useful directions for me to investigate further. The STM32F4 looks good. Having a compiler is helpful but I am fine with writing assembler as well. FPGA seems like overkill at this point and would also require use of an eval board or a custom PCBA, which I was hoping to avoid. The stm32f4 in tssop20 looks like it might work with very minimal additional parts and also supports I2C. \$\endgroup\$
    – Henry G
    Commented Jan 11, 2016 at 21:06
  • \$\begingroup\$ GCC supports the stm32 series, so tool support is easy. You don't need an F4 for this, something cheap like an F103 has the necessary timer hardware (interrupt on change, capture/compare). \$\endgroup\$ Commented Jan 12, 2016 at 3:49
  • \$\begingroup\$ I suspect that a plain AVR would be fine too with its 16 bit timers and a change-interrupt. You could program the chip with the Arduino IDE but don't try to time the pulses with a busy-loop, use Timer1 instead. It even has capture inputs last I looked. \$\endgroup\$ Commented Jan 12, 2016 at 3:50
  • \$\begingroup\$ if you want to use a CPLD, there are $10-$15 dev boards available (XC9572XL?) that I'm sure would be capable of this too. Most CPLDs have closed (gratis but not libre) toolchains, but there are Lattice ICE parts with a fully-open toolchain. \$\endgroup\$ Commented Jan 12, 2016 at 3:53
  • \$\begingroup\$ Lattice also has an XO board for 25$ that has some power to it, they also have some USB sticks for 25$ if you need something 'portable'. I've never used their toolchain however. \$\endgroup\$
    – Voltage Spike
    Commented Jan 20, 2016 at 21:54
2
\$\begingroup\$

4ms increments won't be useful with a typical RC receiver output, perhaps you meant 4 us. (The PWM pulse typically ranges from 0.5 to 2 ms).

This ought to be doable with any basic MCU with a built-in timer, clocked at 1 MHz or more, you could get 1 us increments if necessary.

\$\endgroup\$
1
  • \$\begingroup\$ Depending on how much work the MCU has to do (other than timing) for simple LED on /off / flashing I'd use anything from the 6 pin MCU's upwards. In theory that's supply, MCU, resistor, LED. Decoupling Cap.... you don't get much simpler than that. \$\endgroup\$
    – Spoon
    Commented Jan 12, 2016 at 12:27

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.