Using arduino nano with multiple components that require timing

Hi!
I'm trying to write my own ardupilot for a quadcopter (just as a hobby, not because I want it to be better than existing ones) and, even though some things worked in isolation, putting them together causes issues.

I have 4 main components:

  • IMU: Communicates using SCA/SCL triggered by an interruption on pin 2
  • 4 ESCs: Need to output 1000-2000us pulses each 20ms or so
  • 6 RC channels: Input of 1000-2000us pulses each 20ms or so
  • HC-05: "Software" serial communication (not sure on the specifics, but the lib I'm using uses timers to send pulses)

Libraries usually don't work well together because all of them wants to use TIMER1 (16 bits) and they end up conflicting.
I thought about trying to merge their timer functions together, but in the end I don't think this would be much different than just running all my measument of inputs and updating of outputs in the main loop.

This doesn't seem easy to do/debug, but the best way I thought about doing this is, for each loop, check the input pins and count how much time they stayed up; and also set the output pins on/off based on how long ago this happened before.

No interrupts at all.

Is there a better approach to this?

Thanks!

There often exist variants of libraries which use different timers or documented ways to change which timer a library is using. E.g. If you were thinking of using Servo.h (timer1) you could instead use ServoTimer2.h (guess which timer that one uses).

Since you don't say exactly which libraries you're trying to use it's difficult to offer more detail.

Steve

Hm, but given that the arduino nano has only one 16-bits timer, is it even possible in theory for the libraries to not clash?

I'm using PinChangeInt to attach handlers for "CHANGE" interruptions on pins (from the RC receiver) and AltSoftSerial to control the HC-05 serial pins (because SoftwareSerial is not compatible)
As for the ESCs, I coded it using delayMicroseconds() myself, but it was clashing with RC interruptions. For instance, I did "delayMicroseconds(1300)" but the motor was oscillating (if I disable the RC interruptions, it stops oscillating) - so I guess it was getting interrupted in the middle of the delay and the pulse was getting bigger than it should.

Thanks