View previous topic :: View next topic |
Author |
Message |
mat72
Joined: 19 Jan 2006 Posts: 11
|
Flaky int_ext |
Posted: Sun Jan 22, 2006 8:54 pm |
|
|
I have the following simple program which performs an ADC on channel 0 and has an external interrupt on RB0/INT0
Code: | #include <18F4550.h>
#include <ctype.h>
#fuses HS,NOPROTECT,NOLVP, NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
unsigned value=0;
unsigned adc = 0;
/*************************Interrupt Functions*************************************/
#INT_EXT
void ext_isr(){
value++;
delay_ms(10);
//printf("PULSE\n\r");
}
void main() {
set_tris_b(0xFF); // port b as input;
enable_interrupts(INT_EXT);// turn on interrupts
enable_interrupts(GLOBAL);
ext_int_edge(H_TO_L); // init interrupt triggering for button press
output_d(0xff);
delay_ms(20);
printf("Sampling:\n");
while(true){
adc = Read_ADC();
delay_ms(100);
printf("Value: %u \r",value);
}
}
|
The ISR is not called unless I remove the ADC stuff
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
What is causing this?
Thanks,
Matt
[/code] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: Flaky int_ext |
Posted: Sun Jan 22, 2006 10:02 pm |
|
|
mat72 wrote: | Code: | /*************************Interrupt Functions*************************************/
#INT_EXT
void ext_isr(){
value++;
delay_ms(10);
//printf("PULSE\n\r");
} |
|
The delay in your ISR might cause you to loose the next external interrupt. Is the purpse of the delay to debounce the switch? |
|
|
mat72-not logged in Guest
|
|
Posted: Mon Jan 23, 2006 7:38 am |
|
|
The purpose is to debounce. The switch is a magnetic sensor from an exercise bike. Is there a hardware debounce solution for a single pole switch?
Also I still have the problem without the delay. Right now its the ADC stuff that affects it. If I remove all ADC code then the interrupt works fine.
Thanks,
Matt |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
|
mat72
Joined: 19 Jan 2006 Posts: 11
|
|
Posted: Tue Jan 24, 2006 5:35 pm |
|
|
I've replaced "setup_port_a( ALL_ANALOG );"
with "setup_adc_ports(AN0);"
This solved my problem. Why wouldn't "setup_port_a( ALL_ANALOG );" work?
Also I've removed the delay which didn't effect anything.
Thanks,
Matt |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
hardware debouncers |
Posted: Tue Jan 24, 2006 5:45 pm |
|
|
mat72-not logged in wrote: | Is there a hardware debounce solution for a single pole switch? |
There is information about hardware debouncers in this threadhttp://www.ccsinfo.com/forum/viewtopic.php?t=24103 |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
|
|
|