Simple asm delay ?


Closed Thread
Results 1 to 23 of 23

Hybrid View

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

    Default Simple asm delay ?

    Hi All !

    I'm kinda stuck @ the moment. I have a 12F683 and i need to do a variable delay ranging from 1us to 1000us.

    The problem is that at 8Mhz the pauseus can't go as low as 12us.

    Does anybody have a asm routine or macro that can be used here ?

    Something like :
    Code:
    Macro delay(time in us)
    if time = 1 then
    nop
    nop
    if time = 2 then
    nop
    nop
    nop
    nop
    if time = 3 then
    
    etc, etc ...
    Thanks !

  2. #2
    Join Date
    Jun 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Use a FOR NEXT

    I think that you could use something like.

    Delay Var Word ' Pause in us
    Counter Var Word

    FOR Counter = 1 to Delay
    @nop
    @nop
    NEXT Counter

    It's untested so I'm guessing it should work but I don't know how long the LOOP will add to the pause.

    Regards, Mike
    Last edited by mikendee; - 10th November 2009 at 10:52. Reason: Revision

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    Assuming a 8MHz clock, some ASM macros
    Code:
    delay1us macro
        goto $+1      ;  2 cycle delay
                    endm
    
    delay2us macro
        delay1us
        delay1us
                   endm
    
    delay4us macro
        delay2us
        delay2us
                   endm
    
    delay8us macro
        delay4us
        delay4us
                   endm
    Now, you may want to get something like 5 us. For that you can
    @ delay4us
    @ delay1us
    in your code

    Hope this is helpful to you.

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


    Did you find this post helpful? Yes | No

    Default

    Wow, Thanks.

    I'm gonna try this. Tried the for..next just yet but it won't go below 5us delay.

    Jerson, i think this would do the trick, but i need to figure out how to let the software 'choose' the right delay .. I need to be able to feed the number of uS to delay to the asm macro.

    Something like ...
    Code:
    ASM
    Delay1us  macro time
    for x = 0 to time
        goto $+1
    next
    ENDASM
    Last edited by ultiblade; - 10th November 2009 at 12:36. Reason: Typo

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    The 683 has a TMR1 and also a CCP module ...

    just use one of them for variable delays !!!

    see asm examples in the relevant Datasheet chapter ...

    may be 1 and 2 microseconds will need a "special treatment" ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    You are so right !

    The thing is however, i have tmr1 setup as a counter and i use its overflow to sync the whole program on 100hz.

    I have three different led's that are driven by fet's. Each led has it's own channel and due to the design of the driver, at a given moment only 1 led me be high.

    To be able to shift the colors around, i turn on a certain channel for a certain ammount of time.

    Code:
    RED con %001
    GRN con %010
    BLU con %100 
    
    loop60
        if ledred = 0 then goto noRED
        GPIO = red
        pauseus ledred
    noRED:
        if ledgrn = 0 then goto noGRN
        GPIO = grn
        pauseus ledgrn
    noGRN:
        if ledblu = 0 then goto noBLU  
        GPIO = blu
        pauseus ledblu  
    noBLU:
    goto loop60
    Once interrupted the ledred / ledgrn / ledblu values are altered, but always in a way that ledred+ ledgrn + ledblu = 1000, the timer get's a reset and it then jumps back into the loop.

    The example above works but pauseus can't delay faster then 12us ...

Similar Threads

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