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 support@ccsinfo.com

Constant interrupt 16F690

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



Joined: 29 Aug 2010
Posts: 2

View user's profile Send private message

Constant interrupt 16F690
PostPosted: Sun Aug 29, 2010 10:21 pm     Reply with quote

Hi,

I'm having an annoying problem with my PICkit2 starter kit (low pin count demo board). I'm trying to get some useful function out of the port B interrupts, but it constantly fires. I've tried all kinds of things: nothing connected to ANY port B pins, pullups enabled..interrupt constantly fires. Clear RABIF (using "clear_interrupt(INT_RB)" and even manually) even though i shouldn't have to....interrupt constantly fires.

I even saw another thread that suggested to enable port A interrupts (although not assign an isr) so I tried that and same thing....interrupt fires continually.

I'm beginning to suspect a hardware problem, although I have checked with my volt meter and B4-7 seem to remain at constant voltage even while the interrupt fires. I wish I had an oscilloscope to take a closer look at the voltages on those pins, but alas I do not. I've posted my code below, although it's about as basic as possible.

Code:

#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)                                                 
                                 
int toggle=0;

#int_RB
void chA_isr(){
   if(toggle==0){
      toggle = 1;
      output_high(PIN_C1);
      delay_ms(500);
   }else if(toggle==1){
      toggle = 0;
      output_low(PIN_C1);
      delay_ms(500);
   }
}

void main()
{   
   port_b_pullups(0xF0);
   delay_us(10);           //wait for pullups to pull up
   
   //These lines to enable interrupts:
   clear_interrupt(INT_RB);
   enable_interrupts(INT_RB);     //enables interrupt on port B
   enable_interrupts(global);     //enables interrupts globally
   
   while (TRUE) {
     output_high(PIN_C0);
     delay_ms(500);
     output_low(PIN_C0);
     delay_ms(500);
   }

}


It's all part of a bigger picture but the code, as posted above, elicits the problem behavior. Even with NOTHING attached (ok, so i soldered some leads to B4-6, but they're not connected to anything) the interrupt fires constantly (led for C1 blinks) and never allows the main program to execute (led for C0 never so much as flickers). As I write this, the code above is running, its mocking blink edging me ever closer towards insanity. To be sure, I just poked pins B4-7 with the volt meter and all read a constant 5V (ok, 4.91, but I feel like that should be close enough).

Oh, and from ".lst":
Code:
CCS PCM C Compiler, Version 4.093, 5967               29-Aug-10 22:02


Any ideas?

Thanks in advance!

-K
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 30, 2010 12:56 am     Reply with quote

If you searched the internet or this forum you would have found that many people have problems with the PortB interrupts. These interrupts are a bit different in that two actions are required to clear the interrupt:
data sheet chapter 4.4.2 wrote:
The user, in the Interrupt Service Routine, clears the interrupt by:
a)Any read or write of PORTB. This will end the
mismatch condition.
b)Clear the flag bit RABIF
Clearing the RABIF is something the CCS compiler does for you, but it is up to you to read the I/O port (and determine the pin that changed, causing the interrupt).
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

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

PostPosted: Mon Aug 30, 2010 12:58 am     Reply with quote

You need to read port B to clear the interrupt. eg "input_b" or "input(PIN_Bx)".
_________________
Andrew
jumpus



Joined: 29 Aug 2010
Posts: 2

View user's profile Send private message

PostPosted: Mon Aug 30, 2010 9:30 am     Reply with quote

Well... I feel like an idiot now. That's ok, though. It works!

In my defense, I actually saw that I should be reading that port (in the data sheet and on this forum) but I interpreted it as either read the port or clear RABIF. Live and learn...

Thanks guys!

-K
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Aug 30, 2010 12:51 pm     Reply with quote

As an aside it is almost never a good idea to put a delay_ms in an isr. If you have a mechanical device aka switch remember it will need debouncing since each bounce may trigger a new interrupt.
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