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-on-change problem with 12F609

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



Joined: 23 Nov 2009
Posts: 3

View user's profile Send private message

interrupt-on-change problem with 12F609
PostPosted: Mon Nov 23, 2009 8:46 am     Reply with quote

Code:

#include <12F609.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES IOSC4                    //INTOSC speed 4 MHz
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOPUT                    //No Power Up Timer

#use delay(clock=4000000)
#define HALL_S0   PIN_A0
#define HALL_S1   PIN_A1
#define DIG_OUT   PIN_A2
#define GREEN_LED   PIN_A4
#define RED_LED   PIN_A5

#byte GPIO     =  0x05
#byte TRISIO   =  0x85

#INT_RA
void RA_isr(){
   int8 temp;
   temp = GPIO & 0x03;
   output_low(GREEN_LED);   
}


void main(){
   int8 temp;
   TRISIO = 0x0B; 
   
   output_low(DIG_OUT);   
   output_high(RED_LED);      //LEDs are active LOW
   output_high(GREEN_LED);
   
   temp = GPIO;
   
   clear_interrupt(INT_RA);
   enable_interrupts(INT_RA0);//enable interrupts from both hall sensors
   enable_interrupts(INT_RA1);
   enable_interrupts(GLOBAL);
     
   for( ; ; ){                               
   }   
}


Compiler version is 4.050. Interrupts-on-change don't fire. What I am missing? Any help will be greatly appreciated!


Thank You
Ttelmah
Guest







PostPosted: Mon Nov 23, 2009 9:10 am     Reply with quote

You _either_ have to use the separate RA0/1 interrupt handler routines, or just enable INT_RA.
Using INT_RA0 or RA1, tells the compiler to add code to the global handler, to decode which pin has changed, and route to the corresponding handler. You are telling the compiler to do this, then not putting in these corresponding handlers....

Best Wishes
nicksen



Joined: 23 Nov 2009
Posts: 3

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 4:11 pm     Reply with quote

I wish I could get PCM programmer's opinion.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 4:31 pm     Reply with quote

If you navigate to PICC/Devices directory, and look up the device header file, you will see there are several definitions:
Code:

#define INT_RA.....etc.
#define INT_RA0
#define INT_RA1
#define INT_RA2
#define INT_RA3
#define INT_RA4
#define INT_RA5

So if you do this
Code:

enable_interrupts(INT_RA0); //enable interrupts from both hall sensors
enable_interrupts(INT_RA1);

You also have to place proper interrupt handlers - i.e.
Code:

#INT_RA0
void ra0_isr()
{
//mycode
}

#INT_RA1
void ra1_isr()
{
//mycode
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 4:44 pm     Reply with quote

There are no individual handlers. There is only the #INT_RA handler:
http://www.ccsinfo.com/forum/viewtopic.php?t=39835&start=3
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 4:46 pm     Reply with quote

Quote:

Interrupts-on-change don't fire. What I am missing? Any help will be greatly appreciated!

1. What is the Vdd voltage of your PIC ?

2. What are the voltage levels of the signals on pins RA0 and RA1 ?
Look at them with an oscilloscope.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 5:06 pm     Reply with quote

PCM programmer wrote:
There are no individual handlers. There is only the #INT_RA handler:
http://www.ccsinfo.com/forum/viewtopic.php?t=39835&start=3

oops, my bad.
nicksen



Joined: 23 Nov 2009
Posts: 3

View user's profile Send private message

PostPosted: Wed Nov 25, 2009 12:03 pm     Reply with quote

Vdd is +5V. RA0 and RA1 get clean 0V and +5V signals. Verified with o'scope.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 25, 2009 1:34 pm     Reply with quote

I compiled your program with versions 4.050 and 4.101 and compared
the .LST files with ExamDiff.

There are some problems in your version, as explained below.
Code:

.................... void main(){ 
0044:  CLRF   04
0045:  MOVLW  1F
0046:  ANDWF  03,F

0047:  MOVLW  62
0048:  BSF    03.5
0049:  MOVWF  10  // Set OSCTUNE = 0x62  (***Bug )
004A:  BCF    03.5

004B:  CLRF   1A
004C:  CLRF   1C

This code above is the start-up code. It writes to the OSCTUNE register
as if it's the OSCCON register (which doesn't exist in this PIC). That's
wrong. There's no reason to write to OSCTUNE. You should fix this in
your code by doing this:
Code:

#byte OSCTUNE = 0x90

void main()
{
OSCTUNE = 0;    // Fix bug in start-up code with vs. 4.050

That bug should be fixed, but I don't think it will affect your problem.
(This bug is not present in vs. 4.101).

There is another problem, and it's that the ANSEL register is left in it's
power-on reset state, which is "All analog". This affects pins RA0 and
RA1. CCS normally sets ANSEL to "all digital" in the start-up code. But
they don't do it in your version. In fact, they don't do it in vs. 4.101
either. You can fix it with this:
Code:

#byte ANSEL = 0x9F

void main()
{
ANSEL = 0;  // Make all Analog pins be digital i/o pins

I'll report this ANSEL setup problem to CCS.
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