Hi all, I have built a RC lawn mower and right now I am doing the electonics. I use a standard RC receiver with PWM output and want to read those signals with the Arduino. The Arduino then controlls two BTS7960 motor controllers. It is differantial steering so the Arduino needs to do a bit of math in every loop to figure out the speed of both motors according to the stick positions on the RC remote.
There were several suggestions to use libraries that use interrupt pins, but some also suggest to just use the “pulseIn” function.
ch1 = pulseIn(5, HIGH, 25000)
My question is, how important is it to use the Interrupt method? Would the controlls be to sluggish by using pulseIn? The lawnmower will be little faster than walking speed. I cannot judge how critical the controlls are. Its not a drone or plane.
I am using a Arduino MEGA, so there are 5 interrupt pins. I could go either way, but I pefer pulsein for simplicity.
Note that pulseIn() has an optional timeout parameter
pulseIn(pin, value, timeout)
which you should use to prevent it from hanging up for any reason.
So you should be able to collect and analyze several channels fairly rapidly. Any example code using pulseIn() for reading r/c pulses would probably show that.
An alternative to investigate is using the PPM signal from your receiver, if it has or can be made to produce one.
Then you could take in all the channels at once. There is help for that, google
Typically RC receivers will output a servo pulse every 20 milliseconds, so a 50 Hz update rate. Some of this 20 milliseconds will be consumed by waiting for and measuring the pulse width for the channel(s) you're interested in, however, if your calculation of motor control parameters takes significantly less than that the update interval of 20 mS (say 2 mS for the calculation), then the latency of mechanical bits responding is probably insignificant.
The net of this is if you're more comfortable using pulseIn(), your calculations are not too time consuming, and there's not much else going on for the microcontroller to handle, it's not obvious that it can't be made to work without using interrupts.
There are some potential "gotchas" either way. e.g. The pulses out of the receiver are probably sequential, so that if channel 2 is read before channel 1 pulseIn() may wait almost an entire 20 ms cycle for channel 1, so the effective update rate would only be half as fast as if they were read in order.