Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Two IRQ per button press... why?
PostPosted: Mon Jul 03, 2006 2:54 pm 
Offline

Joined: Sat Mar 18, 2006 10:05 pm
Posts: 37
I am having some trouble with reading the buttons of the A3 EvalKit with interrupts. I seem to always get one IRQ for pressing the button, and one for releasing it, no matter if I use HIGH/LOW/EDGE sensitive...


My code:

//enable irq+isr
void Din_PIOB_Setup(void)
{
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ; //interrupts need the clock

//AT91C_AIC_SRCTYPE_POSITIVE_EDGE,AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL, AT91C_AIC_SRCTYPE_HIGH_LEVEL,AT91C_AIC_SRCTYPE_EXT_NEGATIVE_EDGE - all = 2 counts/keypress

AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_PIOB, DIN_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL, Din_PIOB_ISR_Entry);

AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_PIOB);

}




// enable irqs for a DIN pin, use setup for the PIO first, then enable pins with this
void Din_PIOB_Enable(unsigned int pin)
{
AT91F_PIO_CfgInput(AT91C_BASE_PIOB, 0x1<<pin); // ODR, PER - disables as output and enables as input


// only affect current pin
// AT91C_BASE_PIOB->PIO_PPUER = 0x1<<pin;
// AT91C_BASE_PIOB->PIO_IFER = 0x1<<pin;

AT91F_PIO_InterruptEnable(AT91C_BASE_PIOB, 0x1<<pin); // IER
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 3:11 pm 
Offline

Joined: Fri Mar 24, 2006 7:33 pm
Posts: 29
Its the debounce my man, delay a bit or add a resistor and cap to the pin.

_________________
Amateurs built the ark...
Professionals built the Titanic...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 3:36 pm 
Offline

Joined: Sat Mar 18, 2006 10:05 pm
Posts: 37
Well, it does not seem like bounce, because if I press and hold the button I get one IRQ, then when I release it I get another one even if I do this several seconds after pressing it... the release should not give any IRQ.... (I guess it could be some kind of "release bounce" that gives an IRQ there.... but I turned on the internal pull up and filtering as you can see...)

Could it be the PIO is doing something tó the signal before it reaches the AIC, or are the HIGH/LOW/EDGE etc settings not valid for PIO inputs??

Any suggstions on how to only get one IRQ (on rising edge or HIGH level) would be welcome.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 2:34 pm 
Offline

Joined: Fri Dec 30, 2005 10:35 am
Posts: 31
any change on a GPIO sets the pin's pending bit.

The PIO interupt is OR-ed version of Pending & Mask bits...

you can set HIGH level or RISING edge for the PIO interrupt, however this has nothing to do with the level or edge on a particular pin.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 9:54 pm 
Offline

Joined: Sat Mar 18, 2006 10:05 pm
Posts: 37
So, I guess there is no way around it then?

(To get IRQ only when a pin goes high, and not when it goes low also.)

Or is there at least some way to know if it was low->high or high->low that caused the IRQ...?

/P


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 9:11 am 
Offline

Joined: Fri Dec 30, 2005 10:35 am
Posts: 31
In general the IRQ tells you that there was at least one change on the pin.
You can check the current level, but there is no way to tell how many changes were from the last IRQ.

However, in your case you don't care about the multiple changes. All you need is to keep your own copy of the last pin level. You need a timer as well for the debounce logic.
In the PIO IRQ when you see a difference between the last level and current level you start the timer. If you do not see another IRQ within 30-40ms you can tell that the key was pressed or released. If there was another IRQ before the debounce time you just restart the timer...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 9:39 am 
Offline

Joined: Sat Mar 18, 2006 10:05 pm
Posts: 37
Thanks a lot!

Would never have figured it would be so coplicated to get a keydown event.... so now I know its not a fault somewhere, and I just have to add more code to detect a keypress.

So, can anyone explain why can we set EDGE/HIGH etc sensitivity for external signals, if does not work, if we always get an IRQ for "everything" anyway???

/PM


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 9:52 am 
Offline

Joined: Fri Dec 30, 2005 10:35 am
Posts: 31
EDGE/HIGH works for IRQx pins and FIQ pin as well...

but when you use the PIO controller for GPIOs you can only have change interrupts.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 2:47 pm 
Offline

Joined: Thu Aug 25, 2005 7:06 pm
Posts: 87
as long as we're on the topic of debouncing and whatnot - does anybody have any code for implementing a button debouncer? I would definitely be interested in seeing it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 5:37 pm 
Offline

Joined: Fri Mar 24, 2006 7:33 pm
Posts: 29
sure,

delay_ms(20);

_________________
Amateurs built the ark...
Professionals built the Titanic...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 12, 2006 8:54 pm 
Offline

Joined: Thu Aug 25, 2005 7:06 pm
Posts: 87
seulater wrote:
sure,

delay_ms(20);

Well that's a great way to waste clock cycles...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 12, 2006 10:25 pm 
Offline

Joined: Fri Mar 24, 2006 7:33 pm
Posts: 29
You don't have a whole lot of choices. De-bounce is a function of time. you have to wait it out, how you decide to wait is up to do.

Personally, i set up a 20ms interrupt. in the interrupt i look at the switches no matter what. that way when i look at the switches again in the next interrupt the debounce will be gone and i will have a valid switch reading.

_________________
Amateurs built the ark...
Professionals built the Titanic...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: