avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Wait for a Particular Interrupt


From: Thomas D. Dean
Subject: [avr-gcc-list] Wait for a Particular Interrupt
Date: Fri, 9 May 2008 23:24:29 -0700 (PDT)

I want to wait for a particular interrupt.  I have a one shot trigger
connected to POTRB[0] and Q back to INT2.  The one shot is around 3
msec.

I can make the interrupt happen.  However, it is one of many.  INT2
happens some 3 to 4 msec after the trigger to the one shot.

The one shot triggers every time, but, the int2_start() routine does
not wait for the falling edge of the one shot.  The trailing edge of
the one shot happens several msec after the trailing edge of PORTA[1]

main() {
...
  MCUCSR &= ~_BV(ISC2);  // falling edge
  GICR   |= _BV(INT2);   // enable INT2
...
  int2_start();
...
}

volatile uint8_t flag;

void int2_start() {
  PORTA |= _BV(01);  // scope trace
  PORTB |= _BV(00);  // one shot trigger up 10 ns Ok.
  PORTB &= ~_BV(00); // one shot trigger down
  flag = 1;
  while (flag) {\
    // can get an interrupt here
    cli();
    if ((flag) && (!(GIFR & _BV(INTF2)))) {  // make sure INT2 did not happen
      sleep_enable();
      sei();  // the next instruction is guaranteed
      sleep_cpu();
      sleep_disable();
    }
    // if the interrupt happened above, flag will be cleared.
  }
  PORTA &= ~_BV(01);  // scope trace
}

ISR(SIG_INTERRUPT2) {
  PORTA |= _BV(02);   // scope trace
  flag = 0;
  PORTA &= ~_BV(02);  // scope trace
}

What am I doing wrong?

tomdean




reply via email to

[Prev in Thread] Current Thread [Next in Thread]