I have three input signals, all arriving at the same time, RND0, RND1, and NR. The experiment is pulsed, and either RND0 OR RND1 (but never both) goes high every "trial", and stay high for maybe 200 ns. The NR signal occurs rarely, but when it does, it starts at the same time as the RND0 or RND1 pulse, but only lasts 50 ns. What I want to do is, upon arrival of the NR signal, see what that trials RND value was (RND0 or RND1).
So, currently I have attached interrupts to three pins as follows:
attachInterrupt(digitalPinToInterrupt(RND0pin), RND0isr, RISING);
attachInterrupt(digitalPinToInterrupt(RND1pin), RND1isr, RISING);
attachInterrupt(digitalPinToInterrupt(NRpin), NRisr, FALLING);
Whenever RND0 or RND1 goes high, I have an interrupt change a variable to 0 or 1, depending on which goes high. 50 ns later, IF NR went high, it will have a falling edge, NRisr will execute, and I can then store the value of the RND0/RND1 variable. The problem is, with this configuration -- my results are not what I expect to see at all. I see vastly more RND0's occurring then RND1's.... when they should be occurring at roughly the same rate.
When I change the NR interrupt to RISING however, it seems to work. This is counter intuitive to what I think is going on inside the microprocessor, and I can't figure out why. I changed NRisr to execute on the falling edge because RND and NR occur at the same time, and I don't want them to conflict, so ... why doesn't this work?
One thing I can think of is that I have RND0 as Pin 2, RND1 as Pin 3, and NR as Pin 4. On this page https://www.arduino.cc/en/Reference/AttachInterrupt it says that Pin 4 isn't interrupt capable for most chips ... and I am unsure as to which one of those applies to Teensy.
Anyways, any suggestions as to how to handle simultaneous interrupts would be nice, or any obvious problems with my approach. I have attached the code if anyone is interested.
So, currently I have attached interrupts to three pins as follows:
attachInterrupt(digitalPinToInterrupt(RND0pin), RND0isr, RISING);
attachInterrupt(digitalPinToInterrupt(RND1pin), RND1isr, RISING);
attachInterrupt(digitalPinToInterrupt(NRpin), NRisr, FALLING);
Whenever RND0 or RND1 goes high, I have an interrupt change a variable to 0 or 1, depending on which goes high. 50 ns later, IF NR went high, it will have a falling edge, NRisr will execute, and I can then store the value of the RND0/RND1 variable. The problem is, with this configuration -- my results are not what I expect to see at all. I see vastly more RND0's occurring then RND1's.... when they should be occurring at roughly the same rate.
When I change the NR interrupt to RISING however, it seems to work. This is counter intuitive to what I think is going on inside the microprocessor, and I can't figure out why. I changed NRisr to execute on the falling edge because RND and NR occur at the same time, and I don't want them to conflict, so ... why doesn't this work?
One thing I can think of is that I have RND0 as Pin 2, RND1 as Pin 3, and NR as Pin 4. On this page https://www.arduino.cc/en/Reference/AttachInterrupt it says that Pin 4 isn't interrupt capable for most chips ... and I am unsure as to which one of those applies to Teensy.
Anyways, any suggestions as to how to handle simultaneous interrupts would be nice, or any obvious problems with my approach. I have attached the code if anyone is interested.