Show Posts
Pages: 1 2 [3] 4 5 6
31  Using Arduino / Programming Questions / Re: interrupt still happening after detached. on: April 23, 2011, 12:20:29 pm
(Believe it or not, some people actually program things other than Arduino boards and with compilers other than avr-gcc, and they like to keep things vendor-independent wherever it's practical.  Really.)

Thanks for the clarification.   smiley-lol
32  Using Arduino / Programming Questions / Re: Interrupt still happening after detached. (fix now available) on: April 23, 2011, 11:57:46 am
I would think, eventually, the fix should be included in the attachInterrupt() routine itself, unless there is some unforseen down-side.  (As Nick mentioned, as unlikely as it may seem, maybe some sketches out there are using the pre-triggered interrupts?)
33  Using Arduino / Programming Questions / Re: interrupt still happening after detached. on: April 23, 2011, 11:42:57 am
I ran 12 permutations of the 4 clearing methods against each interrupt and both interrupts simultaneously.  (Just to make sure nothing unexpected happened)  (Of course, there are probably more conditions I didn't think of.)

Both of these methods work, and work exclusively on the interrupt flag they are meant to clear.

EIFR = 1;   //use before attachInterrupt(0,isr,xxxx) to clear interrupt 0 flag
EIFR = 2;   //use before attachInterrupt(1,isr,xxxx) to clear interrupt 1 flag

or
 
EIFR = (1 << INTF0);   //use before attachInterrupt(0,isr,xxxx) to clear interrupt 0 flag
EIFR = (1 << INTF1);   //use before attachInterrupt(1,isr,xxxx) to clear interrupt 1 flag


Which method would be better to advise users in the Arduino's attachInterrupt() documentation?

In my opinion, even though the first method looks more straight forward, the latter keeps the 0 and 1 aligned with the interrupt numbers, so would be less prone to an accidental mismatch.  There are probably other advantages to the latter method as well?
34  Using Arduino / Programming Questions / Re: interrupt still happening after detached. on: April 23, 2011, 10:38:03 am
Thanks for the replies.   
So then would this be the final code then? :

// put these 2 lines before Setup? or in Setup?
#define INTF0 0
#define INTF1 1

EIFR = (1 << INTF0);   //use before attachInterrupt(0,isr,xxxx) to clear interrupt 0 flag
EIFR = (1 << INTF1);   //use before attachInterrupt(1,isr,xxxx) to clear interrupt 1 flag

35  Using Arduino / Programming Questions / Re: interrupt still happening after detached. on: April 22, 2011, 07:29:38 pm
Bug?  Feature?  Someone else will have to decide.  In my opinion it's a bug because the behaviour deviates from what is expected.

@Loudhvx: What do you want?  Are you looking for a solution to this problem?  Or are you trying to report a bug?

I agree, as far as I'm concerned, it's a bug in the Arduino system. Not an Atmega bug, but as far as anyone programming an Arduino using the Arduino Reference documentation, it's a bug.  

I don't think it matters if the input is a de-bounced switch or not. The same bug would happen with any pulsing input were applied.  I produced the input pulse several seconds before the false interrupt happened. The same could happen with an encoder etc.

I think there should be some sort of note in the Attach/Detach Reference if an interrupt can be triggered by some event that happened before the attach statement.  It may save someone a lot of frustration.  I chose Arduino because it's aimed at non-programmers like me.  

...maybe just a note to clear the flag or whatever before doing the attach statement.  Dave's and Nick Gammon's notes will surely be in my personal notes on the Arduino. Thanks for that.  I agree, I would have assumed that should have been taken care of in the Attach routine.

EIFR = 1;   // for interrupt 0
EIFR = 2;   // for interrupt 1

What would be better, or different etc.  using Dave's bit-shift statement (if that's what it is) or just Nick's simple assignment?
36  Using Arduino / Programming Questions / Re: interrupt still happening after detached. on: April 22, 2011, 12:39:26 pm
I wonder if this would explain some of the interrupt headaches so many seem to have. (me included)
37  Using Arduino / Programming Questions / Re: interrupt still happening after detached. on: April 22, 2011, 12:37:46 pm
UNO board with Duemilanove bootloaded atmega328.

Further test show evidence this may be a bug (if it's not a programming issue on my part).  

It is not a hardware issue (ie floating pin).  I added a counter to the isr that increments every time the isr is called.  I also added a flag to indicate attached or detached, and another counter to increment every time the isr is called while interrupt is detached. These would be invalid interrupts.

While the interrupt is attached, the interrupt counter increments each time I ground the pin (many times actually, due to contact bounce). This is expected.

However, if I ground the pin multiple times while the interrupt is detached, the interrupt counter only increments 1 time, as does the invalid-interrupt counter. (If I don't ground the pin at all, there is no increment.)

This would imply there is at least one interrupt that will occur after the interrupt is detached (if the interrupting action occurs).  This would be a bug, no?
 
38  Using Arduino / Programming Questions / Re: interrupt still happening after detached. on: April 22, 2011, 11:54:48 am
pin 2 is pulled up. I'm pulling down by touching a ground wire to it while the led is off (3 second interval).

The pin should be stabilized in that amount of time.

39  Using Arduino / Programming Questions / Interrupt still happening after detached. ( fix now available) on: April 22, 2011, 11:37:18 am
EDIT: The problem is an interrupt is happening when it is not expected. Actually, as Dave explains, it's being triggered before the attach call, not after the detach call (which I first thought). There is now a work-around available.


I wrote a simple sketch to play with interrupts.  When the led is on, the interrupt is attached. When the led is off, the interrupt is detached.  However, if I pulse the input pin low while the interrupt is detached, the isr still gets called.  Any insight?

Let's see if this "copy for forum" option works.
Quote

volatile long interrTime;   //micros() when isr0 is called

void setup() {
  pinMode(2, INPUT);         //interrupt 0
  pinMode(13, OUTPUT);       //LED
  digitalWrite(2, HIGH);      //pullup 2
  Serial.begin(9600);
}

void loop() {
  digitalWrite(13, HIGH);                //led on
  attachInterrupt(0, isr0, FALLING);     //enable interrupt
  delay(3000);                           //wait 3 seconds
  detachInterrupt(0);                    //disable interrupt
  digitalWrite(13, LOW);                 //led off

  Serial.print("interrTime = "  );      //print time of isr being called. "0" if not called.
  Serial.println(interrTime, DEC  );
  Serial.println(""  );
 
  interrTime = 0;                       //clear the interrupt time
  delay(3000);                          
}

void isr0 () {
  interrTime = micros();               //record time isr called
}




40  Using Arduino / Microcontrollers / Re: using 20k pullup with analog input. on: April 20, 2011, 12:52:28 pm
Thanks James,
I tried it and it works fine, with 1.1v or 5v selected as reference. (The pullup is always 5v, of course.)

For anyone interested:
In my case, I just wanted to use the pullup as part of a voltage divider so I could use an on-off-on, 3-position switch, 1 resistor, and two wires to give me 3 states.  Without the internal pullup I would have had to use 2 resistors and a 3rd wire.  It's just nice to minimize things.

With a 1.1v reference, a 2.7k resistor to ground on the input will quantize to about 400. A 4.7k to ground will quantize to about 600.  With a 5v reference, a 4.7k to ground will quantize to about 125. A 20k will quantize to about 370.  This suggests there is another resistance somewhere or the ADC is taking some current.  Further experiments would be needed to find out.

Also, I noticed even when appying a very low-impedance source, which forces the input pin to stay at the same voltage, with or without the pullup, the pullup activated still causes the quantization value to raise slightly (about 10% in some cases).  So that is more evidence of another resistance and/or loading by the ADC.  Maybe this is documented, but I haven't checked.

The pullup on one analog pin does not seem to affect other analog inputs, so the isolation seems good.
 
41  Using Arduino / Microcontrollers / Re: Is "HIGH" a valid mode for AttachInterrupt() ? on: April 19, 2011, 10:09:56 am
I meant to say the minimum pulse is about 15 to 20, but since I have to do a few things in between edges, I'll only have 5 to 10 to detect the trailing edge.

I really just needed confirmation that HIGH was not an option.  I'll try a few of the suggestions and see what I get.

Thanks.
42  Using Arduino / Microcontrollers / Re: Is "HIGH" a valid mode for AttachInterrupt() ? on: April 19, 2011, 02:04:53 am
Alright, thanks.
43  Using Arduino / Microcontrollers / Re: Is "HIGH" a valid mode for AttachInterrupt() ? on: April 19, 2011, 01:15:16 am
PulseIn() looks interesting. 
If I'm looking for a low pulse, can I call PulseIn() after the pin has already gone low (thus the timing will start immediately when PulseIn is called)?
44  Using Arduino / Microcontrollers / Re: Is "HIGH" a valid mode for AttachInterrupt() ? on: April 19, 2011, 01:03:38 am
Thanks BenF.

That's an interesting approach, but I may have to return to the main program between reading the leading edge and trailing edge, in case the pulse is very long.

If I use one ISR for both detections using CHANGE, I think then, whichever pin state test I do second will always be late by at least 4 micorseconds. While I can tolerate a late result, I wouldn't want every result to be late.  I suppose I could subtract a set amount of usec to compensate for that, though. 

I may tinker with that. Thanks.
45  Using Arduino / Microcontrollers / Re: Is "HIGH" a valid mode for AttachInterrupt() ? on: April 19, 2011, 12:54:00 am
Thanks Coding Badly. That's interesting.
I'm only using the interrupts to avoid unnecessary external circuitry. I have a working system with external hardware, but I was just toying with eliminating some of it through using interrupts.

I would only be using 1 external interrupt (at this point in the sketch), and the ISR is one, maybe two lines of code, so it's about as lean as it can be.  But I am trying to capture the trailing edge of a potentially 15 to 20 microsecond pulse, and half of that pulse time is used up after detecting the leading edge and updating a couple variables.  So that leaves me with about 7 to 10 ish microseconds.  I've run tests where the polling method gave me a reliable 8 usec return. Using Interrupts, I could only  get it down to 12 usec. (If memory serves.)  I can accept a late result, but not a missed result.

I think for now, I will stick with the polling method I've been using (with external circuitry to generate the interrupt).

Thanks all, for the replies.
Pages: 1 2 [3] 4 5 6