View previous topic :: View next topic |
Author |
Message |
alexerty
Joined: 24 Jan 2008 Posts: 8
|
Help to use external interrupt |
Posted: Mon Apr 19, 2010 1:32 am |
|
|
Hello:grin:
I post a new topic because I trying to validate my external interrupt program.
I have a function when my button RB0(INT0) to press that my LED (on RB1) can work.
It's a simple program just to validate external interrupt.
Unfortunately, when I simulate my program as Isis, it doesn't work.
This my code...
Main.h
Code: |
#include <16F88.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc
#FUSES NOPUT //No Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#use delay(clock=8000000) |
Main.c
Code: |
#include "D:\projet c\main6.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#use delay(internal=8M)
#int_EXT
void EXT_isr(void)
{
output_toggle(PIN_B1);
delay_ms(500);
clear_interrupt(INT_EXT);
}
#int_TIMER0
void TIMER0_isr(void)
{
}
#int_TIMER2
void TIMER2_isr(void)
{
}
void main()
{
enable_interrupts(global); //GIE=1
enable_interrupts(INT_EXT); //INTE=1
ext_int_edge(L_TO_H);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,156,16);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER2);
setup_oscillator(OSC_8MHZ|OSC_INTRC);
// TODO: USER CODE!!
while(1)
{
}
}
|
Could you help me please? |
|
|
Charlie U
Joined: 09 Sep 2003 Posts: 183 Location: Somewhere under water in the Great Lakes
|
|
Posted: Mon Apr 19, 2010 10:23 am |
|
|
Start by adding: enable_interrupts(GLOBAL); following the existing enable_interrupts calls. You have enabled the individual interrupts, but not the global interrupt. |
|
|
alexerty
Joined: 24 Jan 2008 Posts: 8
|
|
Posted: Mon Apr 19, 2010 10:30 am |
|
|
if you look my code I put enable_interrupts(GLOBAL) |
|
|
Charlie U
Joined: 09 Sep 2003 Posts: 183 Location: Somewhere under water in the Great Lakes
|
|
Posted: Mon Apr 19, 2010 11:02 am |
|
|
Oops.
I am used to enabling the individual interrupts then the global last. I overlooked the earlier call.
Sorry. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 19, 2010 12:17 pm |
|
|
Do you have a pull-up resistor on the External interrupt pin ?
You need one. Here is the circuit that you need:
Code: |
+5v
|
<
> 4.7K
< ___ Push button switch
To | _|_|_
PIC -----------------o o------
pin |
--- GND
-
|
|
|
|
alexerty
Joined: 24 Jan 2008 Posts: 8
|
|
Posted: Tue Apr 20, 2010 3:06 am |
|
|
Thanks for your responses
I haven't a pull-up resistor on the External interrupt pin but a pull-down as I trig interruption from Low to high voltage (ext_int_edge(L_TO_H); )
Code: |
Push button switch
To _|_|_
PIC ----------------------------------o o--------------------->+5v
pin |
<
> 4.7K
<
|
--- GND
-
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
alexerty
Joined: 24 Jan 2008 Posts: 8
|
|
Posted: Wed Apr 21, 2010 5:13 am |
|
|
well I try with your code
Code: | #include <16F88.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(internal=8M)
#INT_EXT
void ext_isr(void)
{
output_toggle(PIN_B1);
}
//=======================
void main()
{
[b]output_high(PIN_B1); // Initially set Pin B1 high[/b]
ext_int_edge(L_TO_H);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1);
} |
But it doesn't work: B1 still on high state when I press button on RB0
I have tried also to linking /MCLR on 5V but it doesn't work either
thank you for your help again
[/img] |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Apr 21, 2010 5:24 am |
|
|
What happens if you reduce the program to just blinking the LED? Code: | #include <16F88.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(internal=8M)
void main()
{
while(1)
{
output_toggle(PIN_B1);
delay_ms(500);
}
} |
Also post your compiler version number. |
|
|
alexerty
Joined: 24 Jan 2008 Posts: 8
|
|
Posted: Wed Apr 21, 2010 6:51 am |
|
|
ckielstra wrote: | What happens if you reduce the program to just blinking the LED? Code: | #include <16F88.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(internal=8M)
void main()
{
while(1)
{
output_toggle(PIN_B1);
delay_ms(500);
}
} |
Also post your compiler version number. |
This program work perfectly .
I manage to do all interrupt timers (1,2,3) and convert analog
My only issue , this is external interruption
I'm not at home
I'll give you my compiler version number as soon as I get home |
|
|
alexerty
Joined: 24 Jan 2008 Posts: 8
|
|
Posted: Wed Apr 21, 2010 10:57 am |
|
|
So the compiler version number is 4.038 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 21, 2010 12:22 pm |
|
|
I installed vs. 4.038, and used the program you posted just above
the schematic. I used my switch schematic, because that's how
the PicDem2-Plus board is wired. It worked.
To make it work reliably in hardware, I had to add a small debounce
delay as shown below in bold. Normally we don't like to put delays in
an interrupt routine, but for this program it's OK.
Quote: | #INT_EXT
void ext_isr(void)
{
output_toggle(PIN_B1);
delay_ms(10); // Debounce delay
}
|
Also, on the PicDem2-Plus board, I didn't use the on-board LEDs.
I added a separate LED with a series resistor on pin B1.
So, except for the switch wiring, it's very similar to your schematic. |
|
|
alexerty
Joined: 24 Jan 2008 Posts: 8
|
|
Posted: Thu Apr 22, 2010 2:53 am |
|
|
Thank PCM Programmer
I begin to wonder if the problem does not come from Isis which doesn't support external interruption.
There is no reason for not working here.
I will try to run your program on my personal card development. |
|
|
alexerty
Joined: 24 Jan 2008 Posts: 8
|
|
Posted: Fri Apr 23, 2010 4:14 pm |
|
|
So , it does work now
I have resolved my issue
The problem was a bug from Isis
You can close the topic if you want
Thank you for your help |
|
|
|