Simple asm delay ?


Results 1 to 23 of 23

Threaded View

  1. #9
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Google came up with an interesting piece of code.
    I did some tests and it seems to do the trick.

    If called using "@ wait 0" it delays 1uS,
    if called using "@ wait 1" it delays about 2,5uS,
    if called using "@ wait 2" it delays about 3uS.

    Code:
    asm
    shortwait macro del  ; used by main wait macro
        if (del>3) && (del<8) 
            call del7+(7-(del)) 
        endif 
        if del <4 
            if del>=2 
                goto $+1
            endif
            if ((del) & 1) == 1
                nop
            endif
        endif
        endm
    endasm
    
    asm
    wait macro del 
    ;    if (del)<0 error 'negative delay' 
    ;    endif 
        if (del)>=8 
            movlw ((del)-8) /4 
            call delay
            shortwait ((del-8) % 4) 
        else
            shortwait (del)
         endif
        endm
    
    delay  
        addlw 0xff 
        skpnc 
        goto delay
        return
     
    del7 goto del5      ; 7 cycle delay
    del6 goto del4      ; 6 cycle delay
    del5 nop            ; 5 cycle delay
    del4 return         ; 4 cycle delay
    ENDasm
    So, the delay is not the problem anymore.
    However, when called from picbasic like :
    Code:
    led1 var word
    led2 var word
    
    led1 = 2
    led2 = 2
    
    start:
    
    GPIO = %01
    @ wait _led1
    GPIO = %10
    @ wait _led2
    
    goto start
    The delay is about 33uS instead of 2. I understand that the delay would be longer, but 30uS extra ??

    Can someone, please, point me in the right direction ?
    Last edited by ultiblade; - 12th November 2009 at 14:18. Reason: Typo

Similar Threads

  1. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 08:57
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 16:23
  3. RF Transmitter
    By et_Fong in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2005, 17:34
  4. Memory Space of the PIC16F84...
    By Tear in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st July 2005, 20:55
  5. Problem with saving to EEPROM...
    By Tear in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st July 2005, 01:10

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