attachInterrupt , digitalPinToInterrupt question

Status
Not open for further replies.

kwiatlab

Member
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.
 

Attachments

  • FEEDBACK_W_MISSED.ino
    7.1 KB · Views: 91
If they arrive at the same time, just use NR and then digital read fast the other pins, then report which one is high. However if any delay in arrival of the signal it might miss read the signals as low. On the teensy all pins are interrupts, but for max performance you can separate them out so they are on different ports, a,b,c or d. There is a thread with this info, but can find it at the moment. But try the digitalreadfast and see if that works.
 
If they arrive at the same time, just use NR and then digital read fast the other pins, then report which one is high. However if any delay in arrival of the signal it might miss read the signals as low. On the teensy all pins are interrupts, but for max performance you can separate them out so they are on different ports, a,b,c or d. There is a thread with this info, but can find it at the moment. But try the digitalreadfast and see if that works.

Hi, sorry for the probably easy question here.

I keep finding multiple places that have the digitalreadfast code to download, and some of them seem pretty iffy. Is there a good official-ish place to get these functions?

Thank you.
 
There is no code , just put digitalReadfast... Not sure if that is correct because of capitals , but will turn yellow if correct if using arduino ide.
 
There is no code , just put digitalReadfast... Not sure if that is correct because of capitals , but will turn yellow if correct if using arduino ide.

Yeah, thanks .. I figured that out but forgot to reply :)

Actually the function seems too slow to read my pulses, but that's ok, because the weird ratio i was measuring before turns out to be actually ... correct.

So, the approach I posted before seems to work, but thank you for all your help anyways!
 
Status
Not open for further replies.
Back
Top