View previous topic :: View next topic |
Author |
Message |
Sophi
Joined: 14 Jun 2005 Posts: 64
|
interrupt help- pin B0 |
Posted: Fri Jun 17, 2005 1:58 pm |
|
|
Hi-
I'm trying to use Pin B0 on a PIC16C74A for a pushbutton switch.
Code is as follows:
/* Interrupt Routine- come here when push button switch */
#INT_EXT // interrupt on push button
rb_isr() { // set up int service routine
output_low (PIN_C5); // go high on pin C5 for testing
while(!input(PIN_B0)) // see if push button is pressed (grounded)
{
delay_ms (1); // delay for debounce
}
output_high (PIN_C5); // go low on pin C5 for testing
} //end isr_rb
And further down:
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
My code doesn't work- it gets stuck at enable_interrupts(GLOBAL). Any suggestions or advice?
Thanks-
Sophi |
|
|
valemike Guest
|
|
Posted: Fri Jun 17, 2005 2:07 pm |
|
|
I notice you didn't put the following instruction in the beginning of your main() when you set up your ports:
Code: |
ext_int_edge(H_TO_L);
|
|
|
|
Sophi
Joined: 14 Jun 2005 Posts: 64
|
|
Posted: Fri Jun 17, 2005 2:39 pm |
|
|
Thanks Valemike!
I did have that line but then commented it out, uncommented, my code still gets stuck-
Sophi |
|
|
valemike Guest
|
|
Posted: Fri Jun 17, 2005 3:26 pm |
|
|
your program seems small enough. Can you post the program?
One thing i noticed is that you have the following loop in your ISR:
Code: | while(!input(PIN_B0)) // see if push button is pressed (grounded)
{
delay_ms (1); // delay for debounce
} |
If i read it right, you want the loop to continue running until you release the pushbutton, right?
This is awkward to do in an interrupt service routine. You are starving the rest of the program from running. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Jun 17, 2005 4:03 pm |
|
|
Code: |
#INT_EXT // interrupt on push button
rb_isr()
{ // set up int service routine
output_low (PIN_C5); // pin C5 Low for testing
} //end isr_rb
main()
{
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1)
{
do
{
delay_ms(1);
}while( !input(PIN_B0) ); // see if push button is pressed (grounded)
output_high(PIN_C5); // pin C5 High for testing
}
}
|
|
|
|
bfemmel
Joined: 18 Jul 2004 Posts: 40 Location: San Carlos, CA.
|
|
Posted: Fri Jun 17, 2005 4:18 pm |
|
|
Sophi,
Since it is happening when you enable interrupts I can think of a few things. First, do you have another interrupt that the program is getting stuck in? Is there a interrupt enabled for which there is no ISR defined. Could it be that the line you are looking at in the ISR, (PIN_B0) is already low and the ISR never leaves because the while loop test is never false?
Just thoughts, good luck.
Bruce |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Fri Jun 17, 2005 9:55 pm |
|
|
A 1ms debouce period is way too small for debouncing a mechanical switch. If you have an oscilloscope you may want to have a look at what is happening. 20ms is a lot more realistic value.
Rgds, Andrew _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Sophi
Joined: 14 Jun 2005 Posts: 64
|
interrupt fixed |
Posted: Sun Jun 19, 2005 6:49 am |
|
|
Thanks to all who responded- and with helpful info for me!
Valemike- the line
ext_int_edge(H_TO_L); stayed
Andrew- good thought, I didn't check that yet but will
Bruce-
What actually fixed this code was
1) starting over on a new file (copying all the code over except the interrupt section)
2) changing the order of the functions and the interrupt. Previously I had the code ordered Functions, Interrpts, then main. Now it is interrupt, then functions...
Sophi |
|
|
|