View previous topic :: View next topic |
Author |
Message |
ariza
Joined: 16 Mar 2005 Posts: 13
|
count using interrupt routine |
Posted: Sat Mar 19, 2005 2:48 am |
|
|
Hi all
I have a simple but very important problem in my project. I need to count the push button number in external1(B1) interrupt routine in 18f452 I think i am doing something wrong but i couldn't find where i am wrong.
Any help would be appreciatted
Code: | #int_EXT1 NOCLEAR
void EXT1_isr()
{
x=x+1;diable_interrupts(INT_EXT1);
pc=x;
enable_interrupts(INT_EXT1);
output_high(PIN_B5);
}
| [/quote] |
|
|
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Sat Mar 19, 2005 2:56 am |
|
|
Hi,
If this is a code snippnet form your original programm than You have a spelling misstake = diable instead of disable.
May this causes Your problem as the int will never be disabled so if you have bouncing on the switch the int will come very often
best regards
Andreas |
|
|
ariza
Joined: 16 Mar 2005 Posts: 13
|
|
Posted: Sat Mar 19, 2005 3:10 am |
|
|
Hi,
Sorry a small mistake, the true code is here. When i test this code it only counts one time and i obserce 00000001 in PORTC
[code]#int_EXT1 NOCLEAR
EXT1_isr()
{
x=x+1;disable_interrupts(INT_EXT1);
pc=x;
enable_interrupts(INT_EXT1);output_high(PIN_B5);
} |
|
|
Ttelmah Guest
|
|
Posted: Sat Mar 19, 2005 3:25 am |
|
|
Don't disable the interrupt inside the interrupt handler. This is unnecessary. On the PIC, when an interrupt is executing, the global interrupt enable is disabled, and only re-enabled, when the routine exits. However this would not cause any problem, just waste time.
Remember also, that a switch making, may well trigger five or six counts, if the contact is not clean.
The big problem in what you post, is that you are specifying 'NOCLEAR', which tells the compiler not to clear the interrupt, and you are not then clearing it yourself. Enabling, and disabling the interrupt, _do not_ clear the interrupt flag.
So, this should work:
Code: |
#int_EXT1
void EXT1_isr()
{
x=x+1;
pc=x;
output_high(PIN_B5);
}
|
Best Wishes |
|
|
ariza
Joined: 16 Mar 2005 Posts: 13
|
|
Posted: Sat Mar 19, 2005 4:29 am |
|
|
Thanks your help but i still could't solve my problem. When i did what Ttelmah recommended , after 5 seconds later from first push ,it accepts the new push and increase the value of x. : confused:
[/code] |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Mar 19, 2005 8:05 am |
|
|
Quote: |
Sorry a small mistake, the true code is here. When i test this code it only counts one time and i obserce 00000001 in PORTC
|
The PIC18F452 has the EXT interupts pins in RB0 RB1 and RB2 only.
I guess you are using PORTC...
Best wishes,
Humberto |
|
|
|