Interrupts missing

Status
Not open for further replies.
On my Teensy 3.1 I have one interrupt that runs a lot which sets a flag for the main loop to look at some value.

Code:
  // optical sensor
  pinMode(9, INPUT);
  attachInterrupt(9, pointer_moved, FALLING);

So the pin goes low, the flag gets set, data is read, the pin goes back up.

Code:
volatile boolean mouse_has_data = true;

void pointer_moved() {
  mouse_has_data = true;
}

This works great, except when other interrupts fire.

Code:
  // rotary encoder
  pinMode(16, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  attachInterrupt(16, read_encoder, CHANGE);
  attachInterrupt(17, read_encoder, CHANGE);

So I turn the encoder, and the value gets updated.

Code:
volatile int scroll_steps = 0;

void read_encoder() {
  int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
  static uint8_t old_AB = 0;
  uint8_t dir;

  old_AB <<= 2;                   //remember previous state
  old_AB |= ( GPIOB_PDIR & 0x03 );  //add current state
  scroll_steps += ( enc_states[( old_AB & 0x0f )]);
}

But these two things together makes the first one miss sometimes. So then the flag is not set, no data is read, the pin stays low. BAD.

What can I do to not miss interrupts?
 
Maybe, it's connected to the ADNS-9800, and the sample code and video did not have any software or hardware pull-ups as far as I can tell.
I tried, and it still happens.

The symptoms of that would be different I think.

I did a serial print of the mot pin and the value of mouse_has_data.
After it stopped working, it kept spewing a LOW value for mot and a false value for mouse_has_data, meaning the handler did not run on the falling edge.

This is weird, as I thought interrupts would set a flag, even if another one is running or they are dissabled, and it would run after the other one, or when interrupts are turned on again.
 
my wild guess: try disabling interrupts within the interrupthandlers, clearly they steal from one another..

Code:
void pointer_moved() {
   __disable_irq();
  mouse_has_data = true;
   __enable_irq();
}
 
Last edited:
Status
Not open for further replies.
Back
Top