View previous topic :: View next topic |
Author |
Message |
nicksen
Joined: 23 Nov 2009 Posts: 3
|
interrupt-on-change problem with 12F609 |
Posted: Mon Nov 23, 2009 8:46 am |
|
|
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
|
|
Posted: Mon Nov 23, 2009 9:10 am |
|
|
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
|
|
Posted: Tue Nov 24, 2009 4:11 pm |
|
|
I wish I could get PCM programmer's opinion. |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Tue Nov 24, 2009 4:31 pm |
|
|
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
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 24, 2009 4:46 pm |
|
|
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
|
|
Posted: Tue Nov 24, 2009 5:06 pm |
|
|
oops, my bad. |
|
|
nicksen
Joined: 23 Nov 2009 Posts: 3
|
|
Posted: Wed Nov 25, 2009 12:03 pm |
|
|
Vdd is +5V. RA0 and RA1 get clean 0V and +5V signals. Verified with o'scope. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 25, 2009 1:34 pm |
|
|
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. |
|
|
|