Jump to content
Radik Yanai

Problem : Isr Or Pic16f690

Recommended Posts

Hello,

Trying to insert inline assembler code into ISR in order to preserve W,status and pclatch registers.

(Do I need this code at all when using C-compiler ???)

I try several combinations .... ('_', 'asm','_asm' .....)

Do i need to include some additional header files ?

 

Code :

--------

#include <system.h>

#include "utils.h"

#include "fsr4.h"

 

#pragma CLOCK_FREQ 4000000

#pragma DATA _CONFIG, _CP_OFF & _CPD_OFF & _BOR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _FCMEN_OFF & _IESO_OFF

 

//=============================================================

// Interrupt context saving

char context[ 3 ]@0x0000;

// w_temp - context

// status_temp - context+1

// pclath_temp - context+2

//=============================================================

 

void interrupt()

{

 

asm

{

movwf _context // save off current W register contents

movf _status,w // move status register into W register

movwf _context+1 // save off contents of STATUS register

movf _pclatch,w // move pclath register into W register

movwf _context+2 // save off contents of PCLATH register

}

 

//

// ISR 'C' code here

//

asm

{

movf _context+2,w // retrieve copy of PCLATH register

movwf _pclatch // restore pre-isr PCLATH register contents

movf _context+1,w // retrieve copy of STATUS register

movwf _status // restore pre-isr STATUS register contents

swapf _context,f

swapf _context,w // restore pre-isr W register contents

}

}

 

void main(void)

{

.... my code

.... my code

}

 

 

I get the following error after build :

-----------------------------------------

 

Clean: Deleting intermediary and output files.

Clean: Done.

Executing: "E:\Program Files\SourceBoost\boostc.pic16.exe" fsr4.c -O1 -W1 -t 16F690

BoostC Optimizing C Compiler Version 6.84 (for PIC16 architecture)

http://www.sourceboost.com

Copyright© 2004-2007 Pavel Baranov

Copyright© 2004-2007 David Hobday

 

Licensed to Radislav Yanai under Single user Pro License for 1 node(s)

Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited

 

 

fsr4.c

E:\MPL_Prj\fsr4\fsr4.c(23): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(25): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(34): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(35): error: unknown assembly identifier '_pclatch'

E:\MPL_Prj\fsr4\fsr4.c(36): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(38): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(39): error: error in built-in assembly

 

failure

BUILD FAILED: Tue Feb 05 23:45:22 2008

 

Thank you all in advance,

Radislav Yanai.

Share this post


Link to post
Share on other sites

A number of problems

BoostC saves context automatically so you dont have to.

The file is called pclath not pclatch

Saving context at location 0 onwards is not a good idea because you have to deal with file banking (and thus destroy the status file contents). You would do better saving in the common memory area. IE the area mirrored across all files.

 

 

 

Hello,

Trying to insert inline assembler code into ISR in order to preserve W,status and pclatch registers.

(Do I need this code at all when using C-compiler ???)

I try several combinations .... ('_', 'asm','_asm' .....)

Do i need to include some additional header files ?

 

Code :

--------

#include <system.h>

#include "utils.h"

#include "fsr4.h"

 

#pragma CLOCK_FREQ 4000000

#pragma DATA _CONFIG, _CP_OFF & _CPD_OFF & _BOR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _FCMEN_OFF & _IESO_OFF

 

//=============================================================

// Interrupt context saving

char context[ 3 ]@0x0000;

// w_temp - context

// status_temp - context+1

// pclath_temp - context+2

//=============================================================

 

void interrupt()

{

 

asm

{

movwf _context // save off current W register contents

movf _status,w // move status register into W register

movwf _context+1 // save off contents of STATUS register

movf _pclatch,w // move pclath register into W register

movwf _context+2 // save off contents of PCLATH register

}

 

//

// ISR 'C' code here

//

asm

{

movf _context+2,w // retrieve copy of PCLATH register

movwf _pclatch // restore pre-isr PCLATH register contents

movf _context+1,w // retrieve copy of STATUS register

movwf _status // restore pre-isr STATUS register contents

swapf _context,f

swapf _context,w // restore pre-isr W register contents

}

}

 

void main(void)

{

.... my code

.... my code

}

 

 

I get the following error after build :

-----------------------------------------

 

Clean: Deleting intermediary and output files.

Clean: Done.

Executing: "E:\Program Files\SourceBoost\boostc.pic16.exe" fsr4.c -O1 -W1 -t 16F690

BoostC Optimizing C Compiler Version 6.84 (for PIC16 architecture)

http://www.sourceboost.com

Copyright© 2004-2007 Pavel Baranov

Copyright© 2004-2007 David Hobday

 

Licensed to Radislav Yanai under Single user Pro License for 1 node(s)

Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited

 

 

fsr4.c

E:\MPL_Prj\fsr4\fsr4.c(23): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(25): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(34): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(35): error: unknown assembly identifier '_pclatch'

E:\MPL_Prj\fsr4\fsr4.c(36): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(38): error: error in built-in assembly

E:\MPL_Prj\fsr4\fsr4.c(39): error: error in built-in assembly

 

failure

BUILD FAILED: Tue Feb 05 23:45:22 2008

 

Thank you all in advance,

Radislav Yanai.

Share this post


Link to post
Share on other sites

As Picxie says, let the compiler do it for you.

 

If you really want to write your own context saving code, add the linker option "-isrnocontext" to stop the linker adding in the code.

 

You cannot save your context at 0x0000 as this is the SFR area of the chip.

You can use the common RAM area from 0x70-0x7f as this is available (for the 16F690) irrespective of what file address is selected.

 

You can save context at 0x0020 (bank 0), but you must save the status register first, clear RP0 and RP1, save other registers, otherwise you will get some RAM corruption if the interrupt occured while a bank other than 0 was selected at the time.

 

If you a putting assembler code within braces {} terminate the lines of code with a colon.

For some reason the colon seems to only be required if there is a destination specified i.e. ,W or ,F

Perhaps Dave or Pavel know why.

 

Regards

 

Reynard

Share this post


Link to post
Share on other sites
If you really want to write your own context saving code, add the linker option "-isrnocontext" to stop the linker adding in the code.

This option is only available for PIC18.

Share this post


Link to post
Share on other sites

So it is Picxie. Kinda knocks it all on the head.

 

ps. Read previous reply as semi-colon. Silly me.

Edited by Reynard

Share this post


Link to post
Share on other sites
If you really want to write your own context saving code, add the linker option "-isrnocontext" to stop the linker adding in the code.

This option is only available for PIC18.

 

One has to ask "Why?".

 

I could save at least 10 instructions in one of my interrupt routines if I could do it myself... No array indexing or pointers, so no need to save FSR. PCLATH is never used in the program so no need to save or set it. clrf status instead of two bit clears.

 

This was significant when I had a budget of 120 instructions to handle the interrupt.

 

Orin.

Share this post


Link to post
Share on other sites
One has to ask "Why?".

 

I could save at least 10 instructions in one of my interrupt routines if I could do it myself... No array indexing or pointers, so no need to save FSR. PCLATH is never used in the program so no need to save or set it. clrf status instead of two bit clears.

 

This was significant when I had a budget of 120 instructions to handle the interrupt.

 

Orin.

 

This option was available on the old C2C but then again at one time that had a bit of a problem with interrupts on PICs that didnt have a common bank, eg PIC16F873.

 

There is a way round but it is somewhat involved.

Share this post


Link to post
Share on other sites

Yeah...

Out of curiosity I was just checking the overhead in my interrupt function. It takes 16 ticks of my tmr0 and 13 ticks respectively to go in to and out from my interrupt function. Ideally this should be as small as possible, of course. Altogether my interrupt function takes 45 ticks, leaving about 200 until it's called again. There any tricks to reduce this overhead? inline it :( (kidding, of course!)

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...