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

Interrupt Set-up

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



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

Interrupt Set-up
PostPosted: Mon Dec 01, 2008 8:45 am     Reply with quote

Hi all. My register.c file:
Code:

//Comments - File description
#include .... //included files

#Fuses .... //Configuration bits set-up

//declaration of local function & variables

#INT_TIMER1
void high_isr (void)
{
code here
clear Timer1 Interrupt flag
}

#INT_TIMER3
unsigned char itemp;
void low_isr (void)
{
code here
clear Timer3 Interrupt flag
}

void main(void)
{

while(get_timer1() < 32768)      // Now wait 1 seconds
  {
   get_timer3();      // ...and update Timer3 as well
  }
      
LCD_Clear();      // Clear the display
//strcpypgm2ram((char *)t_string,version);
strcpy(t_string,version);
LCD_String(t_string,0);
}


Timers have been set as:
Code:

TMR1L = 0x00; 
TMR1H = 0x00;
T1CON = 0x4F;

TMR3H = TIMER3_H;    //25ms timeout
TMR3L = TIMER3_L;
T3CON = 0x07;


Interrupt priority have been set up as:
Code:

IPR1 = 0xEF;  // Timer1 set up as high priority
IPR2 = 0xFD;  // Timer3 set up as low priority


My problem is that when I am in while loop in main.c and Timer 3 overflows(indicated by PIR2 = 0x02) causing an interrupt the pc don't go to #INT_TIMER3 executing void low_isr (void) but it jumps at beginning of file where the 'Comments - File description' are found there. Am I doing something wrong in setting up the interrupts or the ISR?
Ttelmah
Guest







PostPosted: Mon Dec 01, 2008 2:32 pm     Reply with quote

Let CCS set the priority for you. Add the keyword 'HIGH' to the interrupt definition, and the phrase #device HIGH_INTS=TRUE to the header definitions.
The problem is that a high priority interrupt vectors to a different address than low priority interrupts. You are overriding the priority, but leaving the code at the default location. Won't work...
You also don't need to clear the interrupt flags. Unless you use the keyword 'NOCLEAR', the compiler will automatically clear the interrupts. You are just wasting time, doing it again.

Best Wishes
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 5:12 am     Reply with quote

Hi. I have changed to the following:

Quote:

#INT_TIMER1 HIGH //line 120
void high_isr (void)...


could you be more specific on where should I add the phrase #device HIGH_INTS=TRUE ? I have added it to my 18f65j90_SFR.h file on phrase
#device PIC18F65J90 HIGH_INTS=TRUE but I get the error:

*** Error 104"18f65j90_SFR.h" Line 5(9,35): Extra characters on preprocessor command line
*** Error 159 "register.c" Line 120(12,17): Invalid interrupt directive requires #DEVICE HIGH_INTS=TRUE

Thanks
Ttelmah
Guest







PostPosted: Mon Dec 08, 2008 5:25 am     Reply with quote

The error message you are getting, _shows_ the syntax required for the high_ints directive. Look at what it is saying....

As a minor comment, _except_ for the processor specific includes, include files should be _after_ the fuses.
The normal 'typical' layour would be:
Code:

#include <processor.h file>
#device statements for ints, ADC etc.
#fuses
#clock
#use rs232

your includes

There can be some 'slight' variations to this, so (for instance), the clock statement, can go in front of the fuses, and the whole 'block', from the #include, to the #rs232, can itself be put into a single 'project' include file. However in general, this order, or close to it, should be used. You must have the 'clock', before the 'RS232', and the 'device' statements, must be before just about anything else. Similarly, clock, RS232, and fuses, must be before you start including general code.

Best Wishes
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 5:54 am     Reply with quote

Good comments. I have changed to the normal 'typical' layout.

When I removed my #DEVICE statement from 18F65J90_SFR.h file and place it on next line I got the following error:

*** Error 128 "18f65j90_SFR.h" Line 12(1,2): A #DEVICE required before this line.

It wants the #DEVICE phrase before the processor specific includes
What am I doing wrong?
Ttelmah
Guest







PostPosted: Mon Dec 08, 2008 7:16 am     Reply with quote

The processor.h file, should only be the _system supplied_ processor.h file, not one of your own.
Basically, this has the processor definition, as it's very first line.

Best Wishes
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 7:56 am     Reply with quote

Quite true. It is found in C:\Program Files\PICC\Devices called 18F65J90.h

I have put that at the very beginning and place my 18f65J90_SFR.h files along with my includes.

Now I've got a list of errors:
Quote:

*** Error 38 "18f65j90_SFR.h" Line 577(17,18): This type can not be qualified with this qualifier C2OUT
*** Error 43 "18f65j90_SFR.h" Line 577(17,18): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 577(18,19): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 577(19,20): Expecting a declaration
*** Error 36 "18f65j90_SFR.h" Line 578(17,18): Expecting a ; or ,
*** Error 43 "18f65j90_SFR.h" Line 578(19,20): Expecting a declaration
*** Error 36 "18f65j90_SFR.h" Line 579(17,18): Expecting a ; or ,
*** Error 43 "18f65j90_SFR.h" Line 579(19,20): Expecting a declaration
*** Error 36 "18f65j90_SFR.h" Line 580(17,18): Expecting a ; or ,
*** Error 43 "18f65j90_SFR.h" Line 580(19,20): Expecting a declaration
*** Error 36 "18f65j90_SFR.h" Line 581(19,20): Expecting a ; or ,
*** Error 43 "18f65j90_SFR.h" Line 581(21,22): Expecting a declaration
*** Error 36 "18f65j90_SFR.h" Line 582(17,18): Expecting a ; or ,
*** Error 43 "18f65j90_SFR.h" Line 582(19,20): Expecting a declaration
*** Error 36 "18f65j90_SFR.h" Line 583(18,19): Expecting a ; or ,
*** Error 43 "18f65j90_SFR.h" Line 583(20,21): Expecting a declaration
*** Error 36 "18f65j90_SFR.h" Line 584(18,19): Expecting a ; or ,
*** Error 43 "18f65j90_SFR.h" Line 584(20,21): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 585(3,4): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 585(4,5): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 596(1,2): Expecting a declaration
*** Error 48 "18f65j90_SFR.h" Line 596(3,12): Expecting a (
*** Error 38 "18f65j90_SFR.h" Line 728(18,19): This type can not be qualified with this qualifier PORTAbits
*** Error 43 "18f65j90_SFR.h" Line 728(18,19): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 728(19,20): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 728(20,21): Expecting a declaration
*** Error 38 "18f65j90_SFR.h" Line 729(18,19): This type can not be qualified with this qualifier
*** Error 43 "18f65j90_SFR.h" Line 729(18,19): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 729(19,20): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 729(20,21): Expecting a declaration
*** Error 38 "18f65j90_SFR.h" Line 730(18,19): This type can not be qualified with this qualifier
*** Error 43 "18f65j90_SFR.h" Line 730(18,19): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 730(19,20): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 730(20,21): Expecting a declaration
*** Error 38 "18f65j90_SFR.h" Line 731(18,19): This type can not be qualified with this qualifier
*** Error 43 "18f65j90_SFR.h" Line 731(18,19): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 731(19,20): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 731(20,21): Expecting a declaration
*** Error 36 "18f65j90_SFR.h" Line 732(18,19): Expecting a ; or ,
*** Error 43 "18f65j90_SFR.h" Line 732(20,21): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 733(3,4): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 733(4,5): Expecting a declaration
*** Error 43 "18f65j90_SFR.h" Line 738(1,2): Expecting a declaration
*** Error 48 "18f65j90_SFR.h" Line 738(3,12): Expecting a (


and lines of code:
Quote:

union {
struct {
unsigned RA0:1;
unsigned RA1:1;
unsigned RA2:1;
unsigned RA3:1;
unsigned RA4:1;
unsigned RA5:1;
unsigned RA6:1;
unsigned RA7:1;
};
struct {
unsigned AN0:1; //line 577
unsigned AN1:1;
unsigned AN2:1;
unsigned AN3:1;
unsigned T0CKI:1;
unsigned AN4:1;
unsigned OSC2:1;
unsigned OSC1:1;
};
struct {
unsigned :1;
unsigned SEG18:1;
unsigned VREFM:1;
unsigned VREFP:1;
unsigned SEG14:1;
unsigned SEG15:1;
unsigned CLKO:1;
unsigned CLKI:1;
};
} PORTAbits;
#locate PORTAbits=0xF80

union {
struct {
unsigned RE0:1;
unsigned RE1:1;
unsigned :1;
unsigned RE3:1;
unsigned RE4:1;
unsigned RE5:1;
unsigned RE6:1;
unsigned RE7:1;
};
struct {
unsigned LCDBIAS1:1;
unsigned LCDBIAS2:1;
unsigned :1;
unsigned COM0:1; //line 728
unsigned COM1:1;
unsigned COM2:1;
unsigned COM3:1;
unsigned CCP2:1;
};
struct {
unsigned :7;
unsigned SEG31:1;
};
} PORTEbits;
#locate PORTEbits=0xF84


Regards
Ttelmah
Guest







PostPosted: Mon Dec 08, 2008 10:19 am     Reply with quote

CCS, is _C_, not _C++_.
Unnamed structure elements (anonymous unions), are not part of C....

Best Wishes
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 5:47 am     Reply with quote

Hi I have found the cause of these errors. I had definitions of PORTAbits and PORTEbits elsewhere aswell. I have shorted that out. Now the normal 'typical' layout is been accepted.

Back to main problem I have done the changes you recomment:
Quote:

Let CCS set the priority for you. Add the keyword 'HIGH' to the interrupt definition, and the phrase #device HIGH_INTS=TRUE to the header definitions.
The problem is that a high priority interrupt vectors to a different address than low priority interrupts. You are overriding the priority, but leaving the code at the default location. Won't work...
You also don't need to clear the interrupt flags. Unless you use the keyword 'NOCLEAR', the compiler will automatically clear the interrupts. You are just wasting time, doing it again.


Still pc at the comments when the interrupt occurs. Do I have to remove any INTCON settings regarding Interrupt priority? Do I have to add any lines as
Quote:

setup_timer1(TMR_INTERNAL,50000);
enable_interrupts(INT_TIMER1);
enable_interrupts(INTR_GLOBAL);


Another funny problem is that after the interrupt occurs and I reset to start simulation all over at the point that I have following statement
Quote:

while(get_timer1() < 4096);

instead of waiting till that value is reached TMR1H is filled with 0x12 and immediatly goes to next line. It is more weird the fact that after waiting 10 miniutes it is working fine

Regards
Thanks
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 10:39 am     Reply with quote

I have corrected this timer1 funny error by using the set_timer1(0) instead of writing individual registers before seting up T1CON register and 'while(get_timer1() < 4096)'.

My register.c file:
Code:

#include "18F65J90.h"
#device HIGH_INTS=TRUE
#fuses
#use delay(clock=8000000)

my includes

//declaration of local function & variables

#INT_TIMER1 HIGH
void high_isr (void)
{
code here

}

#INT_TIMER3
unsigned char itemp;
void low_isr (void)
{
code here
 
}

void main(void)
{

while(get_timer1() < 32768)      // Now wait 1 seconds
  {
   get_timer3();      // ...and update Timer3 as well
  }
       
LCD_Clear();      // Clear the display
//strcpypgm2ram((char *)t_string,version);
strcpy(t_string,version);
LCD_String(t_string,0);


I can see in dissasembly list that when the timer3 interrupt occurs the pc goes at 0018h but not coming back to #INT_TIMER3 but it is stack in a loop cause the interrupt flag never clears.
Ttelmah
Guest







PostPosted: Tue Dec 09, 2008 10:47 am     Reply with quote

You don't ever need to clear the interrupt flags. The compiler _automatically_ does this, unless you tell it no to (NOCLEAR) directive.
Won't matter, but a waste of the instruction.

Your timer behaviour, is because by default the timers are setup in 16bit access mode. The compiler knows about this, and handles it in it's own code, but your attempt to access the 'high' byte, won't work, unless you first access the low byte. What you receive then from the high byte read, is the value 'latched' at the moment the low byte read ocurred.

You don't show what setups you have for timer3, or the duration of your code inside the interrupt?. I'd suspect it is just interrupting too fast, and is then permanently 'true' when the interrupt exits.

Best Wishes
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 11:19 am     Reply with quote

I am really confused now.
My code:
Quote:

set_timer1(0); // Used for 2 seond clock for RTC
// External 32.768KHz crystal
T1CON = 0x4F;

while(get_timer1() < 4096); // Wait a while for Timer 1 to start
// This is necessary due to bug in processor
// That can cause LCD not to start correctly
// if the timer isnt fully up and running

LCDCON = 0x8F; // Enable the LCD, Using Timer 1 oscillator as source was 87
LCDPS = 0x36;
LCDREG = 0x3C;

set_timer3(TIMER3); // Now set up Timer 3 for a 25ms wake timer for sampling the sensors

T3CON = 0x07;
ADCON0 = 0; // Disable ADC for now
ADCON1 = 0x0C; // But prepare its use for sensor sampling

WDTCON = 0x80; // Disable watchdog and enable regulator shutdown in sleep
CMCON = 0x0F; // Disable Comparitor for now
CVRCON = 0x00;

INTCON = 0x00;
INTCON2 = 0xC0; // Disable Port B pull-ups
INTCON3 = 0x00;
PIE1 = 0x01; // TMR1 interrupt enabled for RTC
PIE2 = 0x02; // TMR3 interrupt enabled for 25ms timer
PIE3 = 0x00;
IPR1 = 0xEF;
IPR2 = 0xFD;
IPR3 = 0xFF;

INTCONbits.GIE = 1; // Enable interrupts
INTCONbits.PEIE = 1; // Enable low priority interrupts

//KDL - Setup RS-232 Interrupt
INTCONbits.INT0IE = 1; //

while(get_timer1() < 32768) // Now wait 1 seconds
{
get_timer3(); // ...and update Timer3 as well
}


First while because of using the set_timer() now works fine.
Second while when timer3 interrupt occurs TMR3L = 0x00 and TMR3H = 0xFF. I think timer3 works fine.

I can see in dissasembly list that when the timer3 interrupt occurs the pc goes at 0018h but not coming back to #INT_TIMER3 but it is stack in a loop cause the interrupt flag never clears.
Ttelmah
Guest







PostPosted: Tue Dec 09, 2008 11:33 am     Reply with quote

Seriously, _don't_ access any of the registers directly. Use the compiler code. You are using a compiler, not assembler. If you want to access registers directy, then write in assembler. Though the compiler allows you to directly access registers, this should only really be used, if you have a real need to do things differently. Use the inbuilt setup functions. As you have already found, the set_timer, and get_timer functions are working, while your register accesses are not. Follow the same for everything else...

Best Wishes
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 11:39 am     Reply with quote

thanks I'll try that
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

PostPosted: Wed Dec 10, 2008 9:40 am     Reply with quote

I am doing the changes. Could you please check the following:

Code:
RCON = 0x93;   // Reset control register, enable interrupt priority functions
// What should I use?

//TRISA = 0x0D;
SET_TRIS_A(0x0D);
//TRISB = 0x41;
SET_TRIS_B(0x41);
//TRISC = 0x03;
SET_TRIS_C(0x03);
//TRISD = 0x00;
SET_TRIS_D(0x00);
//TRISE = 0x80;
SET_TRIS_E(0x80);
//TRISF = 0xC0;
SET_TRIS_F(0xC0);
//TRISG = 0x14;
SET_TRIS_G(0x14);

LATA = 0x00;   // Port setup - default values on power up
LATB = 0x00;
LATC = 0x00;
LATD = 0x00;
LATE = 0x00;
LATF = 0x10;
LATG = 0x1C;
PORTG = 0x1C;
//What should I use?


set_timer1(0);
         
//T1CON = 0x4F;
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1);

//LCDCON = 0x8F;                                    
//LCDPS = 0x36;
//LCDREG = 0x3C;
         
//LCDSE0 = 0xFF;   // Enable the used LCD segment pins
//LCDSE1 = 0xFF;
//LCDSE2 = 0x3F;
//LCDSE3 = 0x00;
//LCDSE4 = 0x00;
setup_lcd(LCD_MUX14|LCD_INTRC|LCD_BIAS_3V60|LCD_REG_CLK_INTRC,6,?segments)


//T3CON = 0x07;
setup_timer_3(T3_EXTERNAL | T3_DIV_BY_1);

ADCON0 = 0;      // Disable ADC for now
ADCON1 = 0x0C;      // But prepare its use for sensor sampling
setup_adc(ADC_OFF);
setup_adc_ports(AN0_TO_AN2);

//WDTCON = 0x80;               // Disable watchdog and enable regulator shutdown in sleep
setup_wdt(WDT_OFF);
//using sleep(REG_LOW_POWER); throughout the code

//CMCON = 0x0F;                  // Disable Comparitor for now
//CVRCON = 0x00;
//Could someone explain why CCS 18F65J90.h file gives different register addresses
from data sheet?
#byte   CCP_1    =                      0xfbe       
#byte   CCP_1_LOW=                      0xfbe       
#byte   CCP_1_HIGH=                     0xfbf
#byte   CCP_2    =                      0xfbb       
#byte   CCP_2_LOW=                      0xfbb       
#byte   CCP_2_HIGH=                     0xfbc
#bit    C1OUT = 0xfb4.6
#bit    C2OUT = 0xfb4.7


//INTCON = 0x00;
//INTCONbits.GEIE = 1;
//INTCONbits.PEIE = 1;      // Enable low priority interrupts
enable_interrupts(GLOBAL);   
//what do I use for enabling low/high priority?

//INTCON2 = 0xC0;         // Disable Port B pull-ups
EXT_INT_EDGE(L_TO_H);                              
port_b_pullups(FALSE);

//INTCON3 = 0x00;
?

//PIE1 = 0x01;            // TMR1 interrupt enabled for RTC
enable_interrupts(INT_TIMER1);      // TMR1 interrupt enabled for RTC
   
//PIE2 = 0x02;            // TMR3 interrupt enabled for 25ms timer
enable_interrupts(INT_TIMER3);      // TMR3 interrupt enabled for 25ms timer
   
//PIE3 = 0x00;
?

//IPR1 = 0xEF;
//IPR2 = 0xFD;
//IPR3 = 0xFF;
//It seems like they have enabled priority levels but not the interrupts(except Tmr1 & Tmr3).
//Skip that for now.

//INTCONbits.INT0IE = 1;      //Enable INT0 (Pin RB0)
enable_interrupts(INT_EXT);
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