View previous topic :: View next topic |
Author |
Message |
dangdongho3
Joined: 10 Jun 2018 Posts: 1
|
latch interrupt |
Posted: Sun Jun 10, 2018 10:25 pm |
|
|
I have 2 latching switches (not momentary) and I ORed them on RB0 Interrupt port to use the INT_EXT function. The problem is that when I press the first switch it is executed right, but the interrupt on RB0 remains active since it is latching. How I can deal with latching input interrupt? I do not wish to use the polling system.
I am using the PIC18F452 20MHz crystal. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 11, 2018 12:03 am |
|
|
The most simple solution is to use INT_EXT for one switch and INT_EXT1
for the other switch. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Mon Jun 11, 2018 4:46 am |
|
|
One possible( probable) reason is the noise( bounce) made by the mechanical switches. Normally you'll need to add some R and C to the contacts to remove or dampen or quelch the EMI noise generated when the switch is actuated. Something as simple as a 1K pullup and a .1 across the switch may work though using an oscilloscope and seeing the waveform is really best. Should you decide to really 'play with PICS', save your money and buy a scope. Even a 30 yr old, 20MHz analog one will be a GREAT asset !
Jay |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Mon Jun 11, 2018 6:02 am |
|
|
You have 2 switches which each latch (not momentary). ORing them isn't going to work. You have to XOR them, which requires an external logic gate. If you can tolerate having them run to separate inputs, just do that. You already said that you don't want to poll them but honestly, why? Set up a timer to give you a 10ms 'tick' and use that to poll the switches. More than adequate to give a responsive feel. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Mon Jun 11, 2018 8:53 am |
|
|
As others have said. Think about it. Electrically what you have can't work. One switch made, the signal is pulled down (assuming they pull to ground). Operate the other switch, and nothing will happen. There is nothing for the processor to actually see...
There are lost of choices, and a lot depends on what you actually want to do.
First connect them separately to two pins supporting INT_RB. Then you can tell which switch has operated and which way it has changed.
Alternative, XOR. Problem here is that you'd again have to use INT_RB, otherwise you can only detect one edge of the change.
Alternative. Have separate pull-ups onh the two switches, and connect them via capacitors to the interrupt input. Have a larger pull up on this pin. Then when the switches go 'on' and the signal goes low, the capacitor will generate a pulse on the interrupt pin. Will allow you to detect both switches going on, but you won't know which one. |
|
|
|