View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
External Interrupt |
Posted: Mon Dec 30, 2013 4:03 pm |
|
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 30, 2013 4:05 pm |
|
|
Post your PIC and your oscillator frequency. That's pretty important. |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Mon Dec 30, 2013 4:42 pm |
|
|
You are right sorry i forgot! Thanks...
I am using pic18f4520 and 20mhz crystal. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Dec 30, 2013 6:44 pm |
|
|
comment.
according to the link you posted...
"In case of an active HIGH interrupt, reverse the diodes and have a pull down resistor to GND instead."
In your first code, it appears you're looking for an 'active low' interrupt, the second an 'active high' but to do that the hardware must be changed. We need to know what configuration you've used.
Also switch 'bounce' can be a problem, giving multiple closures when you think there should only be one. Mechanical switches are very 'noisy' and need debouncing. Typically a capacitor across the contacts and a pullup( or down) resistor are used.
Since the circuit uses several diodes, perhaps you've got one or more in wrong way round ?
You can 'manually check proper operation with a simple DVM or 'scope.Simple observe the pins in the 'normal' mode, then close one switch and check each pin for logic level.Confirm that they follow the 'truth table' that they should.You should remove the PIC for this testing.
hth
jay
hth
jay |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Mon Dec 30, 2013 7:08 pm |
|
|
Temtronic, i submitted the two codes for comparison. I am looking for active low interrupt. As a good is it look fine?all diodes are in the right position and to be sure i also made a pull up resistor on every switch together with a pull up resistor on the INT pin RB0. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Dec 30, 2013 7:37 pm |
|
|
hmmm. Have you disabled all other peripherals attached to the I/O pins you want as digital inputs? Stuff like ADC, comps, etc.?
with not pressed you should get 5 volts, pressed about 0.7 volts ??
hth
jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 30, 2013 8:02 pm |
|
|
1. Post a list of all the PIC pins that have buttons and pull-up resistors
connected to them.
2. Post a list of the buttons that you press to get the #INT_EXT interrupt.
3. Post a list of connections to pins B0, B1, and B2. |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Tue Dec 31, 2013 6:43 am |
|
|
thanks for your feedback. JUst to understand better I draw the connections. Please refer to the image here:
http://postimg.org/image/6jm0v6lsn/
The input switches are on Port A and using THE RB0 hardware interrupt. Hope that I answered all the questions... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Tue Dec 31, 2013 8:14 am |
|
|
hmm..
What's in ..#include <zerocrossing simulation.h> ?
also I don't see where you've disabled any of the analog peripherals.
Good time to show us your entire test program.
something's not right....hard to tell without seeing the whole picture.
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Tue Dec 31, 2013 8:59 am |
|
|
I'd seriously consider doing it the other way up.
Problem is that unless connections are very good, you may well not get the RB0 signal low enough to trigger the interrupt.
The 'low' threshold for this pin is 0.8v (assuming you are using a 5v supply). With the typical silicon diode drop of perhaps 0.66v at room temperature, you don't have a lot of margin.
One of those things that 'ought to work', but in the real world, may well give problems....
Best Wishes |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Tue Dec 31, 2013 9:09 am |
|
|
this is the .h file requested
Code: | #include <18F4520.h>
#device ADC=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(crystal=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=comport)
|
my software 5.007, when select ADC to "NONE" no code will be generated. so I assume that all ADC hardware are being disabled. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Tue Dec 31, 2013 10:09 am |
|
|
comment: Mr. T may be onto the real problem, use a dvm and check what a 'low' really is.You could use Shottky diodes for lower forward voltage drop( .2 ish).Silicon is about .7 ish, Ge about .6 ish.
V5.007 is pretty 'new' might have a bug or two and I do NOT assume anything. I'd hardcode to disable adc, comparators,etc.
hth
jay |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Tue Dec 31, 2013 11:43 am |
|
|
as already stated, the interrupt is executed when I press one button. The problem is that all the code in the interrupt routine is being executed:
Code: | #INT_EXT
void EXT_isr(void)
{
if(!input(PIN_A0))
{
output_toggle(PIN_D2);
}
if(!input(PIN_A4))
{
output_toggle(PIN_D5);
}
} |
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Dec 31, 2013 12:20 pm |
|
|
aaronik19 wrote: | as already stated, the interrupt is executed when I press one button. The problem is that all the code in the interrupt routine is being executed:
Code: | #INT_EXT
void EXT_isr(void)
{
if(!input(PIN_A0))
{
output_toggle(PIN_D2);
}
if(!input(PIN_A4))
{
output_toggle(PIN_D5);
}
} |
|
Now you're getting me confused.
Which version of your code is the one which works?
(The one in this, your latest post, or your original post?)
Mike |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Tue Dec 31, 2013 2:42 pm |
|
|
confused with what? I explained that I tried both active-high and active-low inputs just for testing. What I need is active-low, and also the diagram I sent. What I said is that the ISR Routine is being executed when I press the buttons. I think that the problem is in the code...understand? |
|
|
|