I’m making a quadcopter with redundant flight control systems. The quad has 8 motors (2 on each arm) and 3 flight controllers. I’m trying to use the Arduino mega as a “voter” to determine if the flight controllers agree and which signals to send to the motors. Therefore, I have to interpret 24 PWM signals.
I found this code which uses pin change interrupts to interpret and print 4 PWM signals from a receiver: Reading PWM Receiver Signal Using Arduino with Interrupt - Part 2 - YouTube
and I extended it to make this:
The code uses pin change interrupts, and I need all 24, but pin change interrupt pins 11-15 don’t correspond to any pins on the Arduino (based on the pinout diagram for the ATmega2560); they’re pins on the microcontroller that don’t have any breakout points. I solved that problem by connecting the individual microcontroller pins to some unused digital pins’ breakout points and scraping away the traces to those breakout points.
It seems to work fine when I remove channels 16-24, but the data are just crazy when I try to use all the channels. All the pulse lengths should be about 1000us when the motors aren’t spinning (2000us for 100% rpm), but when the quad is disarmed, these are the data I’m getting:
(In the image, channel 9 has a bad connection and that's why it's all zeroes)
The project "Read PWM, Decode RC Receiver Input, and Apply Fail-Safe" by Joop Brokking indicates that the ISRs take more time when you use more channels. The trend he described suggests that each ISR would take around 31us when using all 8 channels. Is that too much?
I suspect that the Arduino just isn’t fast enough to be up to the task, but I can’t figure out how to prove that, and I’m really at a loss for ideas.
If anyone has any insight into my problem it would be greatly appreciated. I’m a high school student working on a difficult science fair project.