I have a circuit that has 2 IR receivers with the idea that there's twice the chance of getting a correctly received message (the distance is 15+ metres, so chance of error is high).
The circuit uses an Atmega328P with Uno bootloader running at 8Mhz using the internal clock and the receivers are on pins 2 & 3, so I should be able to use interrupts on both pins. I'm using IRLib2.
I soon realised that this wouldn't be trivial because most of the work is handled by the recvGlobal struct. I then changed this to an array recvGlobal[2]. Receiver and decoder class constructors were changed to take an index_ variable. recvGlobal was changed to recvGlobal[index_] in the classes. I could then create 2 receiver and 2 decoder objects in my Arduino sketch.
This all compiled and worked successfully. However..... I found that the results were significantly worse than using just 1 receiver.
I have 2 theories about what could be happening:
Having 2 blocking interrupts triggering at the same time is causing timing inaccuracies in reading the incoming signal. This might be made worse by only running at 8Mhz using the flakey internal clock.
There's an error in my code or I've failed to understand part of the library!
I was wondering if anyone has successfully used 2 receivers with this library and has any tips for debugging my issues. Happy to upload any of my modified code if required. Obviously there's a lot of it, as recvGlobal is used in a lot of places.
When an interrupt is called, no other code can be called until the interrupt is complete (under standard conditions). So if you're reading sensitive timings on 2 inputs using interrupts, this blocking could cause issues if the interrupt code takes a long time to complete.
Nothing in the library documentation, although I have posted on the uses GitHub.
I won't post the code for now, as I think @DrDiettrich has a much better solution!
Yes, that is why input capture timer hardware exists. It latches the value until the interrupt can respond.
The good Dr.'s suggestion will work, but not if one RX is receiving weakly. Then it will interfere with the one that is receiving correctly. Also the module output may not be common collector so you may not be able to simply parallel them.
Ah this is a good point thanks. I've just checked the library and the interrupt just uses micros() to set the time.
OK I think I'll test both methods: 1) Library as is (1 interrupt), with receivers in parallel 2) Rewrite the interrupt routine and test with 2 interrupts.