Menu

more wait pendantry

Help
2009-08-12
2013-05-30
  • David Stephenson

    For all short delays there will be some "overhead". For microsecond delays this can be quite significant adding 4 to 5 us to each delay (count the number of clock cycles in the routine).
    It would be nice if the overhead is constant however it is not. Every time the high byte loop is executed it adds to the overhead in the delay. Now I have cobbled together the following ASM for microsecond delay delays that does not have this problem.

    Delay_US
        incf    SysWaitTempUS_H, F
        incf    SysWaitTempUS, F
    DUS_START
        nop
        nop
        decfsz    SysWaitTempUS, F
        goto    DUS_START
        nop
        nop
        decf    SysWaitTempUS, F
        decfsz    SysWaitTempUS_H, F
        goto    DUS_START
        return

    Maybe somebody can do better!

     
    • Nobody/Anonymous

      Perhaps this? :

      Delay_US
      incf SysWaitTempUS_H, F
      incf SysWaitTempUS, F
      DUS_START
      nop
      nop
      decfsz SysWaitTempUS, F
      goto DUS_START
      nop
      nop
      nop
      decf SysWaitTempUS, F
      decfsz SysWaitTempUS_H, F
      goto DUS_START
      return

      ... The "long" loop has now 10 cycles (i think)... we are talking about long delays... isn't it?

       
    • Nobody/Anonymous

      Perhaps I should have been clearer in what I was doing...

      if I put in wait of 255 us then a wait of 256 us I would like the second delay to be exactly 1 us longer than the first.

      Going to the oscilloscope wait for 255 us gives 255 us + 15 cycles so about 3 us too long
      for 256 us I get 256 us +19 cycles nearly 4 us too long.

      The extra cycles are unavoidable and could be compensated for if required, but the variation is a bit more difficult to deal with and needs a change in the compiler code.

      What I suggested gives a overhead of about 21 cycles, but it remains constant for 255, 256 and even 4096 us.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.