PIC with Automatic Context Saving


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: PIC with Automatic Context Saving

    Code:
    '****************************************************************
    '*  Name    : Test RDT Interrupt for one-time use                   
    '*  Author  : Dick Ivers                                                         
    '*  Notice  : Copyright (c) 2011                                             
    '*          : All Rights Reserved                                              
    '*  Date    : 1/30/2011                                                         
    '*  Version : 1.0                                                                   
    '*  Notes   : 112 words                                                         
    '*  Device  : 16F1828                                                           
    '****************************************************************
    'set configurat1on
    @  __config _CONFIG1, _FOSC_HS & _MCLRE_ON & _CLKOUTEN_OFF & _WDTE_ON
    @  __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
    
    'set registers
        ANSELA = 0           'all digital inputs
        ANSELB = 0           'all digital inputs
        ANSELC = 0           'all digital inputs
        OPTION_REG.7 = 0     'global pullups enabled
        CM1CON0.7 = 0        'comparator1 off
        CM2CON0.7 = 0        'comparator2 off
        TRISA = %110         'set porta pin 0 as output
        TRISB = %11111111    'set all portb pins as inputs
        TRISC = %11000000    'set portc pins 0,1,2,3,4,5 as output
        WPUA = %110          'porta pins 1,2 pullups enabled 
        WPUB = %11110000     'portb pin pullups enabled
    
        INTCON = %10001000   'global int enabled, IOCI enabled, IOCI flag bit 0 clr
        IOCAF.1 = 0          'flag bit for porta int pin 1 cleared
        IOCAN = %00000010    'porta pin 1 enabled for negative change
    
    
        DEFINE OSC 16         '16 Mhz oscillator
        DEFINE INTHAND RDT
    
        portc.3 = 1           'turn off beeper
    
    'declare variables
        LED VAR PORTC.5
        j   var byte 
         
        LED = 0      'flash red LED for 0.5 sec to check circuit function
        pause 500
        LED = 1
        
        pause 2000    'delay 2 seconds    
    
    Main:
      gosub beep            'play beep for 1/8 second
      PAUSE 1000            '1 second delay
      GOTO Main
    
    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
     
    beep:   for j =1 to 240      'buzzer sound for 1/8 second
            portc.3 = 0          'buzzer on
            pauseus 180          '2.73 khz half period
            portc.3 = 1          'buzzer off
            pauseus 180          '2.73 khz half period
            next 
            return
    
    halt:   END

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

  5. #5
    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.

  6. #6
    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

  7. #7
    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.

  8. #8
    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

  9. #9
    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.

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