16F to 18F context saving differences


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2006
    Posts
    20

    Default 16F to 18F context saving differences

    Hi, I am trying to move my PicBasic Pro programs from 16F876 to 18F2525. I am unclear as to the difference in context saving/restoring with interrupts. In the PicBasic Pro manual it says that:

    "If a 14-bit core PICmicro MCU has more than 2K of code space, an
    interrupt stub is automatically added that saves the W, STATUS and
    PCLATH registers into the variables wsave, ssave and psave, before
    going to your interrupt handler. Storage for these variables must be
    allocated in the BASIC program:"

    wsave var byte $20 system
    wsave1 var byte $a0 system ‘ If device has RAM in bank1
    wsave2 var byte $120 system ‘ If device has RAM in bank2
    wsave3 var byte $1a0 system ‘ If device has RAM in bank3
    ssave var byte bank0 system
    psave var byte bank0 system

    My original intrrupt rountine, which seems to have worked fine for years had the following code in an included file containing my inerrupt rountines in assembly language.

    ;======= System variables: ======================
    wsave VAR BYTE $70 system
    ssave VAR BYTE bank0 system
    psave VAR BYTE bank0 system

    I had no context saving intering the routine as I believe PBP is doing this for me.

    Upon exit I have the following:
    intsrvx bcf STATUS,RP0 ;select Bank 0
    bcf STATUS,RP1
    movf psave, W ;restore the state of everything
    movwf PCLATH
    swapf ssave, W
    movwf STATUS
    swapf wsave, F
    swapf wsave, W
    retfie

    The interrupts I am using are Timer1(16F876) and Serial Recieve. In my intrrupt rountine I am writing to EEProm too.

    As I said I believe all is well here. My question is, can anyone recommend what will be required to do for the 18F2525 to provide the context save/restore to accomplish the same thing? Do I supply the context saving as well as restoring. Does anyone have any recommended methods?


    Thanks for any help you can provide, Bob

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    usually the datasheet give some example of it... sorry to sound like a broken record

    Have a look to Darrel's instant interrupt code...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Lightbulb Don't save your context!!!!!!!!!!

    Hi,

    Hope you are using high priority interrupts only. (That is no way of a low priority interrupt interrupted by a high priority). Then this should suffice:

    Code:
    retfie fast
    18F series have a single level shadow register stack which saves your w,status and bsr automatically on interrupt.
    Regards

    Sougata

  4. #4
    Join Date
    Feb 2006
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Don't save context??

    Thanks for your reply, am I to understand that if I am using only high priority interrupts that I don't have to save and restore context at all? Only 'retfie fast'.

    Should I avoid save/restore altogether. Is there a time when I should save/restore context or only restore? If so what are the predetermined variables to restore?

    If you could point me to a datasheet were this is explained I would appreciate it. I have looked through the docs and started to make the transition to the 18F but have seen some times when I am viewing EEProm in the Microcode studio ICD that I get random address writes. It's kind of stange the value is written to zero then back to what it was on the next pass. I'm not sure if it's the ICD or my program as the value never remains changed. It only seems to happen when I have my interrupts enabled so I may be doing something wrong. I have run the program overnight without the ICD and the interrupts enabled and examined the EEProm data the next day and everything looks fine. I just want to make sure I understand what I need to do in interrupt handling with the 18F.

    I have two interrupts, serial receive and a timer. I'm still very new to the 18F series and not to sure about the archetecture as yet so I have to check to see if they are considered high priority. In the 16F everything in my asm interrupt routine is in bank0. Is the scheme the same in the 18F?

    Thanks again for your help ,Bob

  5. #5
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Go through the PIC18 reference manual

    Quote Originally Posted by brittons View Post
    If you could point me to a datasheet were this is explained I would appreciate it.
    Hi,
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1510&stc=1&d=117539433 5">

    Could you post your code snippets so that we could discuss this stuff in detail. Also try using Darrel Taylor's Instant Interrupt. As you are already familiar with asm. A review of Darrel's Code would make things much clear. I will get back to this thread.
    Attached Images Attached Images  
    Regards

    Sougata

Similar Threads

  1. 16F to 18F transition pains
    By lurker in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th December 2008, 01:35
  2. changing code from 16F to 18F microprocessor
    By SCC_699 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 14th May 2008, 13:27
  3. Upgrading 16F to 18F
    By Ron Marcus in forum General
    Replies: 1
    Last Post: - 29th March 2006, 09:44
  4. I think my interrupt is not saving context properly?
    By royly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th December 2004, 17:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts