PIC with Automatic Context Saving


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    Forgive me for digging up an old thread, but this really interests me.

    I've also a stash of 16f1828s and the auto context register saving intrigues/appeals to me ... my ultimate goal is getting in/out of a timer based interrupt as fast as possible - ie miniscule overhead (the interrupt rate will be happening at about 50khz)....the thought of learning assembly is quite a hurdle, but this seems like this could be a way of easing myself into it...ie my main code can be picbasic with the interrupt being a little bit of assembly.

    But I'm lost!

    How do I set up an interupt, so that when say timer1 overflows it jumps to an assembly type interrupt in my code (all my interrupts to date have been using DT's most excellent interupt routine, but if I'm understanding correctly that way adds some overhead which could be avoided with these new type PICs?)...in the example above it wasn't clear to me how that ASM part was called/found by the PIC/program.
    Last edited by HankMcSpank; - 24th August 2011 at 20:20.

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


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    You define your interrupt type on the top, you may have many interrupt source, but once in the ISR you need to test them.

    Once an interrupt is fired, it will jump the the ISR label specified by the DEFINE INTHAND line. Here RDT
    Steve

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

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    Thanks, funny now you mention it, it's there I just didn't leap out at me...

    Code:
    DEFINE INTHAND RDT
    but there's no colon after the nominated handle/label at the top of the subroutine?

    Code:
    ASM
    RDT                     
      BCF   IOCAF,IOCAF1   ;clear IOCA negative change interrupt flag
      BCF   INTCON,3       ;disable interrupt on change by clearing INTCON bit 3
      BCF   PORTC,5        ;turn on led solid 
      RETFIE               ;return to main
    ENDASM
    also, I'm figuring it must be necessary to have that 'ASM' entered immediately above?

    thanks again looking forward to having a a dabble
    Last edited by HankMcSpank; - 24th August 2011 at 20:34.

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


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    never mind, Thanks Darrel
    Steve

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

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    DT_INTS-14 uses the auto context saving in the 16F1's.

    Since you already know how to use them, try them first.
    There are still a few instruction cycles that can be saved by doing it manually, but you probably won't need to.
    Just use an ASM type INT_Handler. They do not have to save PBP system variables.

    50Khz should be no problem.
    DT

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    Thanks Darrel.

    my fixation is that I want to generate sine waves to very high resolution (DDS) - and all the stuff that abounds on the net seems to be assembly....they all typically generate a fixed timebase by way of an interupt & then in the interupt add a number to an accumulator, do a look up from the result then get out asap. I agree that 50khz is not that onerous...but this is just the first step to total world domination (Mwuahahahaha.) & the interrupt rate will inevitably crank up.

    Towards helping me understand this area, (actually I'm just curious) when you say there are still a few cycles that can be saved by going the way I asked about ....do you have a ballpark figure for the auto context saving and your (still excellent!) auto context embracing routine?
    Last edited by HankMcSpank; - 24th August 2011 at 20:55.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    Well, if you're only going to be using 1 interupt source, it will be better without DT_INTS since you don't need to test for which interrupt was triggered.

    I just did a quick test with an incrementing variable and a SIN lookup with an 1827 running at 32Mhz.

    With DT_INTS ... max = 140Khz
    Without ... max = 220Khz

    With 2 interrupt sources the difference is not as pronounced since it has to check which one triggered and jump over the handler that wasn't. DT_INTS always does that.

    The PWM will have to be running much faster than the interrupts or it will be changing dutycycles before a single cycle has completed. Could be trickey.
    DT

  8. #8
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    Cool (& thanks) ....as it goes I will need two interrupts, one to generate the timebase, plus one UART interrupt, so I can feed in required frequency changes externally.

    I will really only need up to 18khz(ish), so your quoted 140khz max is well above what I need....so I'll stick with DT_INTS!

    As an aside, for anyone who holds an interest in DDS for PIC, the best I've found to date is this chap's site....

    http://www.g4jnt.com/pics.htm (specifically, this http://www.g4jnt.com/PIC_DDS.pdf and his accompanying zip file http://www.g4jnt.com/PIC_DDS.zip which has his assembly source code for a 16f628 DDS ....it'll probably a while before I get to try my DDS exploits, becuase I'm still trying to wrap my head around how he made a pseudo 32 bit accumulator on a 16f628 by lobbing together four 8 bit registers & then making them dance)

    I can feel a serious amount of plagiarism coming on though!
    Last edited by HankMcSpank; - 24th August 2011 at 23:35.

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    Hank, Please note from the first post that an advantage of interrupts without DT_INTS is a major saving in code space. My sample program compiled with 625 fewer program words when using the 16F1828 vs. a 16F690.

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