Custom array of ports using array?


Closed Thread
Results 1 to 23 of 23

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    It's not that it's OK to "Be interrupted", but it's OK to be in the routine that does the interrupting.

    PAUSEUS has a couple shortcomings. One, is that it uses PBP's system variables (R0-R8). So it corrupts PBP's flow if it's used in an ASM interrupt without "Instant Interrupts".

    The second is that PAUSEUS has a minimum delay of around 24us @ 4mhz since it figures out the delay Count at run time.

    The DelayUS macro can pause for a little as 1us by calculating the delay at Compile Time, and adding a single NOP if that's all that's needed. Or a 3cycle loop and 2 NOP's if running at 20mhz. And it doesn't use any PBP system vars.

    It can be useful in other programs as well, so I'll show it here again for those that aren't as diligent as you Steve.
    Code:
    VP_DelayCount  VAR WORD BANK0  ; Used for DelayUS only
    
    ASM
    ;----[Similar to PAUSEUS, but ASM interrupt compatible]---(accurate to 1uS)--
    DelayUS  macro T
      local InstCount, LoopCount, DelayLoop, LoopsDone, LeftOver, Offset
    ; -- Calculate number of 3 cycle loops plus leftover nop's to execute --
    InstCount = ((OSC*10/4)*T+5)/10 ; Inst cycles required for delay (Rounded UP)
    LoopCount = InstCount / 3
        if (LoopCount > 255)
    Offset = (LoopCount >> 8) * 7 + 4
        else
    Offset = 0
        endif
    ; -- Adjust for HighByte --
    InstCount = InstCount - Offset
        if (Offset > (LoopCount & 0FFh))
    InstCount = InstCount - 4
        endif
    LoopCount = InstCount / 3
        if (LoopCount > 255)
    Offset = (LoopCount >> 8) * 7
        else
    Offset = 0
        endif
    LeftOver  = InstCount % 3
    ;-------------------------------------------
        if (LoopCount > 0)
            MOVE?CW  LoopCount, _VP_DelayCount
    DelayLoop
            decfsz   _VP_DelayCount, F               ;  1
            goto     DelayLoop                       ;  2   3 per loop, under 256
        
            if (LoopCount > 255)
                movf     _VP_DelayCount + 1, W       ;  1    
                btfsc    STATUS, Z                   ;  1    
                goto     LoopsDone                   ;  2   4 on last loop
                
                decf     _VP_DelayCount + 1, F       ;  1    
                goto     DelayLoop                   ;  2   7 per highbyte count 
    LoopsDone
            endif
        endif
        if (LeftOver > 0)
            nop
        endif
        if (LeftOver > 1)
            nop
        endif
      endm
    ENDASM
    DT

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Exclamation

    Ok,
    Quote Originally Posted by Darrel Taylor
    It's not that it's OK to "Be interrupted", but it's OK to be in the routine that does the interrupting.
    This makes much more sense than what I was thinking.

    On thing that should be mentioned. It is generally best to keep interrupt service routines (ISR) as short as possible, so that additional interrupts are not "missed" while handling the current interrupt. So putting a pause into an ISR must be used with caution, and with a good understanding of how it will effect other timing related items. One exception to this would be the 16-bit PICs with High and Low priority interrupts (which are supported by PBP), where a pause in a low prority interrupt would not prevent a high priority interrupt from executing. So all the time critical inturrupts could be High Priority.

    Steve

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  3. Custom array of pins
    By bmagistro in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 28th March 2009, 23:15
  4. Crystalfontz LCD
    By jman12 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 9th February 2007, 15:04
  5. Making Array of two ports
    By John7 in forum General
    Replies: 3
    Last Post: - 5th March 2005, 02:20

Members who have read this thread : 2

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