View previous topic :: View next topic |
Author |
Message |
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
External Interrupt |
Posted: Thu Nov 04, 2004 3:57 am |
|
|
I just can't get the external interrupt
There is the simple code:
Is there any problem with the configuration?
void main(void)
{
Init();
while(1)
{
}
}
void Init(void)
{
TRISB = 0x01 ; //RB0 input for Interrupt
//ext_int_edge(H_TO_L);
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
}
#int_ext
void ext_isr()
{
PORTB = 0XFF;
} _________________ Alex |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Thu Nov 04, 2004 5:44 am |
|
|
The only time you assign a value to port B is inside the interrupt handler. If the value of portb was 0xFF before the interrupt then there would be no noticable change.
how about doing something like this:
Code: | #include <some processor...>
#fuses HS,NOWDT...add your fuses here
#use delay(clock=enter CPU SPeed here....);
short found_it;
void main(void)
{
Init();
while(1)
{
if (Found_it)
{
PORTB = ~PORTB;
delay_ms(500);
Found_it = false;
}
}
}
void Init(void)
{
Found_it = false;
PORTB = 0x00; // some value in PORTB
TRISB = 0x01 ; //RB0 input for Interrupt
//ext_int_edge(H_TO_L);
enable_interrupts(GLOBAL);
clear_interrupt( INT_EXT ); // clear the interrupt flag
enable_interrupts(INT_EXT);
}
#int_ext
void ext_isr()
{
Found_it = true;
} |
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Thu Nov 04, 2004 5:54 am |
|
|
I just put a breakpoint in the isr, and the program does not ever come there.
Also, the INTF bit in the INTOC register, whish indicates that the external interrupt occured is not set after I simulate the interrupt by shorting the RB0 to GND _________________ Alex |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Nov 04, 2004 6:36 am |
|
|
Quote: | I simulate the interrupt by shorting the RB0 to GND | You expect an interrupt on the falling edge, which is default setting so should be ok. Do you have an external pull-up resistor connected? The internal pull-up resistors are disabled by default and you don't enable them....
Please always mention the processor type you are using. |
|
|
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Thu Nov 04, 2004 6:40 am |
|
|
ckielstra wrote: | Quote: | I simulate the interrupt by shorting the RB0 to GND | You expect an interrupt on the falling edge, which is default setting so should be ok. Do you have an external pull-up resistor connected? The internal pull-up resistors are disabled by default and you don't enable them....
Please always mention the processor type you are using. |
I am using PIC16F877A.
I have tryed with/without internal pullups of PORTB, Tryed with/without the external pullup. Tryed number of different PICs. No interrupt
The interesting thing is that when I have got the pull up external or intenal, I have got the 1.5V on the RB0. _________________ Alex |
|
|
Guest
|
Re: External Interrupt |
Posted: Thu Nov 04, 2004 7:26 am |
|
|
alexz wrote: |
void main(void)
{
Init();
while(1)
{
}
}
void Init(void)
{
TRISB = 0x01 ; //RB0 input for Interrupt
//ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT); // Enable External Int
enable_interrupts(GLOBAL); // Then enable global Int's
}
#int_ext
void ext_isr()
{
PORTB = 0XFF;
} |
|
|
|
Guest
|
|
Posted: Thu Nov 04, 2004 7:33 am |
|
|
alexz wrote: |
The interesting thing is that when I have got the pull up external or intenal, I have got the 1.5V on the RB0. |
You did not mention the value for the pull up resistor ?
Sounds like the call to set Tris_B is not correct and the pin is somehow set as output not input.
Try
set_tris_b(0X01); |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Thu Nov 04, 2004 7:35 am |
|
|
alexz wrote: |
The interesting thing is that when I have got the pull up external or intenal, I have got the 1.5V on the RB0. |
Assuming you are actually loading your code into the PIC (are you?) then it sounds like you have a hardware fault. Incorreclty wired, shorted to an adjacent pin that sort of thing. Try a simple program to set an output bit and toggle it every second. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Guest
|
|
Posted: Thu Nov 04, 2004 7:38 am |
|
|
Anonymous wrote: | alexz wrote: |
The interesting thing is that when I have got the pull up external or intenal, I have got the 1.5V on the RB0. |
You did not mention the value for the pull up resistor ?
Sounds like the call to set Tris_B is not correct and the pin is somehow set as output not input.
Try
set_tris_b(0X01); |
Also look at the circuit driving RB0 iit may be pulling the pin low. 1.5V is not correct for a 5t or 3.3 Volt system.
I think you need to investigate the driving circuit to ensure it is really allowing RB0 to go back to 5 V (or 3.3V whatever the Vdd is for your system)
Put a scope on RB0 and make sure the driving signal has a clean edge. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Nov 04, 2004 7:58 am |
|
|
You should also post a "Complete" test program. Who in the world knows what you set PORTB or TRISB to? What are the fuse settings? Post a complete program and you might get your problem solved. |
|
|
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Thu Nov 04, 2004 8:01 am |
|
|
Mark wrote: | You should also post a "Complete" test program. Who in the world knows what you set PORTB or TRISB to? What are the fuse settings? Post a complete program and you might get your problem solved. |
That was the complete program. Nothing else exept this.
Don't ever use fuses. I set those in the configuration bits menu _________________ Alex |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Nov 04, 2004 8:07 am |
|
|
Quote: | That was the complete program. Nothing else exept this.
|
Hum, how does the compiler know what PIC you are using?
Hum, how does the compiler know what PORTB is?
Hum, how does the compiler know what TRISB is?
Hum, how does the compiler know what INT_EXT, GLOBAL........s?
I think it is not a complete program. There must be some header file included somewhere. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Thu Nov 04, 2004 8:26 am |
|
|
Quote: |
Hum, how does the compiler know what PIC you are using?
Hum, how does the compiler know what PORTB is?
Hum, how does the compiler know what TRISB is?
Hum, how does the compiler know what INT_EXT, GLOBAL........s?
|
+ Hum, how does the compiler know what FUSES config are you using?
Before start debugging the code, you must read 5V in PIN_B0 with the pushbutton open
and 0V with the pushbutton closed, -with the internal pull ups resistors enabled-.
Humberto |
|
|
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Thu Nov 04, 2004 8:33 am |
|
|
Humberto wrote: | Quote: |
Hum, how does the compiler know what PIC you are using?
Hum, how does the compiler know what PORTB is?
Hum, how does the compiler know what TRISB is?
Hum, how does the compiler know what INT_EXT, GLOBAL........s?
|
+ Hum, how does the compiler know what FUSES config are you using?
Before start debugging the code, you must read 5V in PIN_B0 with the pushbutton open
and 0V with the pushbutton closed, -with the internal pull ups resistors enabled-.
I guess so, but I have just tested, I have got 1.5V on the Microchip PIC Development board without a PIC in the socket at all.
Humberto |
_________________ Alex |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Thu Nov 04, 2004 10:09 am |
|
|
Hi alexz
There are different ways to code a debouncing routine. One very original
to my taste was posted by Neutone a time ago.
Search "Debouncing routine refinement"
Posted: Fri Aug 29, 2003 5:27 pm
It�s not so easy for a beginner, just to learn how to. It�s very fast and code effective.
Best wiashes,
Humberto |
|
|
|