EmbeddedRelated.com
Forums

AT91RM9200: PIO: im getting two interrupts when i press the switch once :-(

Started by Mayank Kaushik January 10, 2005
Hi,

im learning how to use the AT91RM9200..right now im trying to tackle
the AIC. iv set everyhting up, earmarking PIOA0 for an external
interrupt through a switch connected to it, so that theoretically
whenever the switch is pressed, an interrupt is generated that sends a
string via the debug port to hyperterminal.

everythings fine, but when i press the switch once, i get 2
interrupts...one whenthe switch is down, the other when i release
it..ive tried this in all modes, level sensitive, edge sensitive, high
level, positive edge, etc, all possible ones..
i dont suppose its due to a contact bounce, since im getting symmetric
interrupts like this..im using the exact libraries provided by atmel
(irq_pio.s and irq.mac)..

kindly advise what could be going wrong..
Thanx in anticipation

Mayank

On 10 Jan 2005 04:37:28 -0800, "Mayank Kaushik"
<prehistorictoad2k@yahoo.com> wrote in comp.arch.embedded:

> Hi, > > im learning how to use the AT91RM9200..right now im trying to tackle > the AIC. iv set everyhting up, earmarking PIOA0 for an external > interrupt through a switch connected to it, so that theoretically > whenever the switch is pressed, an interrupt is generated that sends a > string via the debug port to hyperterminal. > > everythings fine, but when i press the switch once, i get 2 > interrupts...one whenthe switch is down, the other when i release > it..ive tried this in all modes, level sensitive, edge sensitive, high > level, positive edge, etc, all possible ones.. > i dont suppose its due to a contact bounce, since im getting symmetric > interrupts like this..im using the exact libraries provided by atmel > (irq_pio.s and irq.mac).. > > kindly advise what could be going wrong.. > Thanx in anticipation > > Mayank
You need to read the data sheet more closely. The PIO pins on this microcontroller only have an "input change" interrupt. The only choice you have is to disable the interrupt for a particular input or to enable it. If it is enabled you will get an interrupt every time the input changes, and that means once when you press the switch and once when you release it. That's the way the part works, and there is no way to change it. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
:-O oh boy i didnt know that!

Thanx a ton, jack..im an undergrad student, this is my first
microcontroller..ive had lots of help from you and other guys at this
group, thanx a ton!

regards
Mayank

or i could put a toggle flip-flop between the switch and the pio
pin..hmm, that should work

"Mayank Kaushik" <prehistorictoad2k@yahoo.com> wrote in message 
news:1105419246.769159.159420@c13g2000cwb.googlegroups.com...
> or i could put a toggle flip-flop between the switch and the pio > pin..hmm, that should work >
Not a good idea since a switch is "bouncy" (i.e. mechanical bounce). Look up switch de-bounce, or switch mechanical bounce, as a topic. The point is that the switch does not have a clean open-close transition. It "chatters" open/close many, many times, over long periods (can be 10's of ms). So, if you put a toggle flop between the switch and the pio pin you will simply do a divide-by-2 of the total number of transitions and the state of the flop will be random when compared to the state of the switch (the number of bounces is not predictable). TC
> > Not a good idea since a switch is "bouncy" (i.e. mechanical bounce). Look
up
> switch de-bounce, or switch mechanical bounce, as a topic. > > The point is that the switch does not have a clean open-close transition.
It
> "chatters" open/close many, many times, over long periods (can be 10's of > ms). So, if you put a toggle flop between the switch and the pio pin you > will simply do a divide-by-2 of the total number of transitions and the > state of the flop will be random when compared to the state of the switch > (the number of bounces is not predictable). > > TC >
A Small "key" controller maybe! There are some "real" interrupts available as well, and they should be configurable as edge or level triggered. The Pin change interrupt are not. "TC" <noone@noplace.com> skrev i meddelandet news:x51Fd.4898$C52.2544@newsread2.news.atl.earthlink.net...
> > "Mayank Kaushik" <prehistorictoad2k@yahoo.com> wrote in message > news:1105419246.769159.159420@c13g2000cwb.googlegroups.com... > > or i could put a toggle flip-flop between the switch and the pio > > pin..hmm, that should work > >
Ulf Samuelsson wrote:
> >> Not a good idea since a switch is "bouncy" (i.e. mechanical >> bounce). Look up switch de-bounce, or switch mechanical bounce, >> as a topic. The point is that the switch does not have a clean >> open-close transition. It "chatters" open/close many, many times, >> over long periods (can be 10's of ms). So, if you put a toggle >> flop between the switch and the pio pin you will simply do a >> divide-by-2 of the total number of transitions and the state of >> the flop will be random when compared to the state of the switch >> (the number of bounces is not predictable). > > A Small "key" controller maybe! There are some "real" interrupts > available as well, and they should be configurable as edge or > level triggered. The Pin change interrupt are not.
Virtually all debouncing schemes depend on timing, and thus can be beaten. The one really immune circuit is the break before make SPDT switch, used to set/reset a flip-flop. You can build the flop out of two nand gates, or even by polling two i/o pins. REPEAT IF bit AND resetsig THEN bit := false ELSE IF NOT bit AND setsig THEN bit := true; (* Do something else *) UNTIL hellfreezesover; where setsig and resetsig are created from the closure of the two switch throws. Because the switch is break before make they cannot occur simultaneously. -- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!