Can only get one interrupt pin working

I have a Rabid Prototype Tau board, which is supposed to be Zero compatible, so I hope this is the correct forum.

I’m trying to measure time between a few different signal edges from some comparators using the micros() function with some interrupts.

Below is a simplified sketch using a single pin to read time from. It just reports micros() at the time of the interrupt and the state of the pin using a little OLED display to output readable information.

If I define T0 as pin three and jumper my input to that pin, I get the expected results of the state change and the micros() count increasing each interrupt. Other pins show the state change as expected, but the micros() value sits at zero, as if the interrupt never happened.

I know pin 4 doesn’t support interrupts, but I believe all the others should. Ultimately, I’d like to monitor 4 inputs.

Any suggestions? Thanks!

#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#include <Adafruit_GFX.h>

#define SDA 16
#define SCL 17

#define T0      9

unsigned long t0;

void setup()
  pinMode(T0, INPUT_PULLUP);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setCursor(0, 0);
  display.println("Hello World");   //  just to see display works

  attachInterrupt(digitalPinToInterrupt(T0), time0, FALLING);

void loop()
  display.setCursor(0, 0);
  display.print("micros: ");        //  this should display micros @ interrupt
  display.print(digitalRead(T0));   //  display state of interrupt pin

void time0()
  t0 = micros();

If it’s any help, I’m using Arduino 1.8.13 and this is what it reports when uploading:

Sketch uses 18648 bytes (14%) of program storage space. Maximum is 131072 bytes.
Atmel SMART device 0x1001000b found
Device : ATSAMD21E17A
Chip ID : 1001000b
Version : v2.0 [Arduino:XYZ] May 4 2016 05:47:47
Address : 8192
Pages : 1920
Page Size : 64 bytes
Total Size : 120KB
Planes : 1
Lock Regions : 16
Locked : none
Security : false
Boot Flash : true
BOD : true
BOR : true
Erase flash
done in 0.405 seconds

Write 18916 bytes to flash (296 pages)
[==============================] 100% (296/296 pages)
done in 0.121 seconds

Verify 18916 bytes of flash with checksum.
Verify successful
done in 0.012 seconds
CPU reset.

You can do it the easy way and use the timer/counter to do the work for you. This is directly from the arduino online reference: "pulseIn() Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or 0 if no complete pulse was received within the timeout.

The timing of this function has been determined empirically and will probably show errors in shorter pulses. Works on pulses from 10 microseconds to 3 minutes in length. Please also note that if the pin is already high when the function is called, it will wait for the pin to go LOW and then HIGH before it starts counting. This routine can be used only if interrupts are activated. Furthermore the highest resolution is obtained with short intervals.
This should work assuming I understood your question.

Thanks for the reply, Gil. What I have is a number of different signals on different pins, and need to measure, for example the time between falling edge on signal A to falling edge of signal B. Then time from edge B to edge C, etc. I will then control other elements based on that time difference. I don’t think the pulse width will help. I suppose I could add some flip flops to hardware turn things into pulse widths, but I’d rather not complicate things if I can get multiple interrupts to work.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.