InterruptRequest
Member
I am working on porting an Arduino ProMini (16MHz) project to the Teensy 3. My requirement is to sample a pin value within 750 ns of a pin triggered interrupt.
Trying to implement this using the Arduino AttachInterrupt() and digitalRead() didn't cut it. The ISR latency was way too great.
After reading Bill Grundmann's Blog about the topic (http://billgrundmann.wordpress.com/2009/03/02/the-overhead-of-arduino-interrupts/)
I utilized techniques from his article and also had to further control timing by writing an ISR with NAKED attribute. I was counting clock cycles and writing inline assembly in the ISR. I managed to meet my requirements on the ProMini using these techniques.
I now face the same problem on the Teensy 3. Even though Teensy 3 is much faster, the latency using AttachInterrupt() and digitalRead() is still not cutting it. Using a logic analyzer and pattern generator I have concluded the fastest the Teensy 3 can sample a pin is approximately 1.3 us. This is much much better than the 16MHz ProMini but still not good enough.
I have some ideas on how to accomplish this on the Teensy 3 but require help on the technical coding details.
I have studied the AttachInterrupt() code and the associated portX_isr() code in the pins_teensy.c file. I see that first it has to determine which pin it is that caused the interrupt and then call the function defined for that pin interrupt.
Since I don't have a requirement for many pins for this project I can dedicate an entire port like port A or port B (Port A only has 4 pins on the Teensy 3 and port B only has 7 pins on the Teensy 3). I can use any one of these pins to trigger the interrupt and I don't need to know which pin it is except knowing which port its on. Hence I can write my ISR directly in the portX_isr() function. In essence I am redefining portX_isr() in the pins_teensy.c file.
I will also be using this technique: eight = GPIOD_PDIR & 0xFF (from Tutorial on digital I/O thread)
to read the sampling pin faster within the ISR .
I just can't figure out how to do this within the framework of the Arduino environment. For example where to declare variables and where to define ISR so that it compiles properly.
Trying to implement this using the Arduino AttachInterrupt() and digitalRead() didn't cut it. The ISR latency was way too great.
After reading Bill Grundmann's Blog about the topic (http://billgrundmann.wordpress.com/2009/03/02/the-overhead-of-arduino-interrupts/)
I utilized techniques from his article and also had to further control timing by writing an ISR with NAKED attribute. I was counting clock cycles and writing inline assembly in the ISR. I managed to meet my requirements on the ProMini using these techniques.
I now face the same problem on the Teensy 3. Even though Teensy 3 is much faster, the latency using AttachInterrupt() and digitalRead() is still not cutting it. Using a logic analyzer and pattern generator I have concluded the fastest the Teensy 3 can sample a pin is approximately 1.3 us. This is much much better than the 16MHz ProMini but still not good enough.
I have some ideas on how to accomplish this on the Teensy 3 but require help on the technical coding details.
I have studied the AttachInterrupt() code and the associated portX_isr() code in the pins_teensy.c file. I see that first it has to determine which pin it is that caused the interrupt and then call the function defined for that pin interrupt.
Since I don't have a requirement for many pins for this project I can dedicate an entire port like port A or port B (Port A only has 4 pins on the Teensy 3 and port B only has 7 pins on the Teensy 3). I can use any one of these pins to trigger the interrupt and I don't need to know which pin it is except knowing which port its on. Hence I can write my ISR directly in the portX_isr() function. In essence I am redefining portX_isr() in the pins_teensy.c file.
I will also be using this technique: eight = GPIOD_PDIR & 0xFF (from Tutorial on digital I/O thread)
to read the sampling pin faster within the ISR .
I just can't figure out how to do this within the framework of the Arduino environment. For example where to declare variables and where to define ISR so that it compiles properly.