CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Flaky int_ext

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mat72



Joined: 19 Jan 2006
Posts: 11

View user's profile Send private message

Flaky int_ext
PostPosted: Sun Jan 22, 2006 8:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 22, 2006 9:09 pm     Reply with quote

See my post in the middle of this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=25631&highlight=interrupts+use+delay
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Flaky int_ext
PostPosted: Sun Jan 22, 2006 10:02 pm     Reply with quote

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







PostPosted: Mon Jan 23, 2006 7:38 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Mon Jan 23, 2006 9:23 am     Reply with quote

I use int_ext for my keypad like this
http://www.edn.com/contents/images/601828f1.pdf

The debounce is done with the 2.2uf
But I don't know how much "BOUNCE" the mag switch will have.
mat72



Joined: 19 Jan 2006
Posts: 11

View user's profile Send private message

PostPosted: Tue Jan 24, 2006 5:35 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

hardware debouncers
PostPosted: Tue Jan 24, 2006 5:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 25, 2006 1:29 pm     Reply with quote

mat72-not logged in wrote:
Is there a hardware debounce solution for a single pole switch?


the sledgehammer approach:
http://www.linear.com/pc/productDetail.do?navId=H0,C1,C1003,C1144,C1129,P10330

Cool

jds-pic
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group