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

Interrupt problems with PIC 16F690

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



Joined: 21 Nov 2005
Posts: 15
Location: Montreal, Canada

View user's profile Send private message Send e-mail

Interrupt problems with PIC 16F690
PostPosted: Sun Nov 29, 2009 11:25 pm     Reply with quote

I'm tryng to get a simple "PORT B change" interrupt working on a pic16F690 using the Pickit2 demo board. Since I had no luck with my original code, I used the simulator and stimulus available in Microchip MPlab 8.40. When I animate the code and fire the RB4 stimulus to emulate a change on the port b on, nothing happens. I'm using CCS 4.030. Any ideas or comments?
Code:

/****** dummy code ****/
int count;

#int_RB
RB_isr()
{
count--;//dummy code
}

void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ);

     while(1)
   {
   count++;//dummy code
   count--;//dummy code
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 30, 2009 2:55 pm     Reply with quote

Use the program in the link below as a guide to make a test program for
the 16F690. This program is for #INT_RA, so you need to change it to
use #INT_RB for your PIC.
http://www.ccsinfo.com/forum/viewtopic.php?t=39835&start=3
mewanchyna



Joined: 21 Nov 2005
Posts: 15
Location: Montreal, Canada

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 30, 2009 4:29 pm     Reply with quote

I tried out the sample code and it worked fine. I found out that if we "enable_interrupts(INT_RB);", I was unable to invoke the ISR with any stimulus, ie firing B4, B5, B6, or B7. When I used the line "enable_interrupts(INT_RB4);", the code worked as it was supposed to. I'm not sure how the "enable_interrupts(INT_RB);" line is supposed to work. Do all 4 line have to change at the same time? I would have thought that any change on any one of those pins should call the ISR. Anyhow, I will move forward from here. Thanks for the help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 30, 2009 4:58 pm     Reply with quote

Quote:
I would have thought that any change on any one of those pins should call the ISR.

enable_interrupts(INT_RB4);

That line sets up the IOCB mask register. Only the selected pin will cause
an interrupt. This feature is an improvement over Microchip's original
PortB interrupts, which had no masking capability on the 4 pins. It was
all 4 pins or nothing. Now you can select individual pins (with the more
modern PICs that have this feature).

Here is the code for vs. 4.030:
Code:

.................... enable_interrupts(INT_RB4);
001A:  BSF    0B.3   // Enable PortA/PortB interrupts in INTCON
001B:  BSF    03.6   // Switch to SFR Bank 2
001C:  BSF    16.4  // Enable RB4 interrupts (only) in IOCB register
Guest








PostPosted: Tue Dec 01, 2009 4:10 pm     Reply with quote

Hi,

When I was using 4.099 I had to use "#INT_RA" as well before my ISR to get portB-change to work in F690 and others.

Code:

#INT_RA <-Should not be needed
#INT_RB
RB_isr()
{ ... etc

Hope this doesn't add to the cofusion.. Very Happy

/BdeB
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 01, 2009 4:43 pm     Reply with quote

Quote:

When I was using 4.099 I had to use "#INT_RA" as well before my ISR to
get portB-change to work in F690 and others.

I just installed vs. 4.099 and compiled the following test program with
just #int_rb and then with both #int_rb and #int_ra. I then compared
the .LST files with ExamDiff. It doesn't show any difference in the
generated ASM code. The only differences in the .LST files is the
time of compilation and the additional #int_ra line in the 2nd test.

Test program:
Code:

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

//#int_ra    // Add this  line for testing.
#int_rb
void rb_isr(void)
{
int8 value;

value = input_b();
}

//============================
void main()
{
int8 temp;

temp = input_b();
clear_interrupt(INT_RB);
enable_interrupts(INT_RB4);
enable_interrupts(GLOBAL);

while(1);
}


Versions 4.100 and 4.101 have bugs in the Interrupt-on-Change (IOC)
interrupts for the 16F690 and many other PICs. They write to incorrect
registers in the interrupt_enable() and interrupt_disable() functions.
These bugs were not present in vs. 4.099. I emailed CCS about this
today. My advice is to use 4.099 until they fix it, if you need to use the
IOC interrupts.

Update: CCS says these problems will be fixed in the next release,
presumably vs. 4.102.
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