Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Russ Cooper
01/04/08 05:56
Read: 1154 times
Phoenix, Az
USA


 
Msg Score: +2
 +1 Informative
 +1 Good Answer/Helpful
#149032 - A related trick
Responding to: Jae-yong Kim's previous message
Following is a cute trick for doing software delays with really fine resolution. Of course interrupts have to be disabled, etc., etc., etc.

Please note that this sort of thing is a good idea only in certain special circumstances. In general, it's much, MUCH better to implement delays based on interrupts from a timer or the PCA or whatever.

-- Russ
;------------------------------------------------------------------------------
;                                 fdelay.s03
;------------------------------------------------------------------------------
; DESCRIPTION:  This module contains a little function to that gives a variable
;               delay with the same resolution as the SYSCLK period (on a
;               single-clocker, that is).  It's called with the number of
;               periods to delay in R7.  It works by jumping into the middle of
;               a big string of NOPs at a position that varies with the input
;               parameter.  There's a RET following the NOPs that returns to
;               the caller.
;
; REVISIONS     13 Sep 06 - RAC - Genesis, after a hint picked up on the
;                                  Silicon Labs user forum.
;------------------------------------------------------------------------------

                RSEG    RCODE

                PUBLIC  do_fine_delay
do_fine_delay:
                MOV     A,R7            ; Get input parameter
                CPL     A               ; Take two's compliment
                INC     A
                MOV     DPTR,#NOPS      ; Point DPTR at the NOP table
                JMP     @A+DPTR         ; Jump into table

;-----  256 NOPs (op code 0) coded in a semi-concise manner

NOPS:
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

                RET

                END



List of 27 messages in thread
TopicAuthorDate
Number of CPU cycle for 8051 function call      Jae-yong Kim      01/04/08 01:03      
   Do it in assembler      Andy Neil      01/04/08 03:00      
   Delay functions      Andy Neil      01/04/08 03:07      
   A related trick        Russ Cooper      01/04/08 05:56      
      Offset      Andy Neil      01/04/08 07:03      
         Offset      Russ Cooper      01/04/08 07:23      
            Sure      Andy Neil      01/04/08 07:40      
               Over Drive?      Neil Kurzman      01/04/08 10:20      
      a refinement      Erik Malund      01/04/08 07:58      
      NOPs are so bad waste of space...      Jan Waclawek      01/04/08 08:51      
         waste of space... waste of time      Erik Malund      01/04/08 09:24      
            fixed delay      Jan Waclawek      01/04/08 09:54      
               Variable delay      Russ Cooper      01/04/08 11:04      
                  determinism of the cache      Jan Waclawek      01/04/08 11:36      
               there are no cache misses in 'linear code'      Erik Malund      01/04/08 11:16      
                  I got only ONE cache miss...      Jan Waclawek      01/04/08 11:39      
      Old Keil Thread      Jon Ward      01/06/08 18:29      
   What about a Delay like this.      Jerry Black      01/07/08 05:31      
      No, it won't.        Christoph Franck      01/07/08 05:55      
         Ok.      Jerry Black      01/07/08 07:08      
         also      Erik Malund      01/08/08 06:47      
      Also ...      Christoph Franck      01/08/08 07:01      
         Actually...      Brett Wallace      01/08/08 08:02      
            will.      Jerry Black      01/08/08 08:21      
               ANSI C      Maarten Brock      01/10/08 05:58      
                  Keil option: Disable ANSI casts      Andy Neil      01/10/08 07:08      
         typo.      Jerry Black      01/08/08 08:24      

Back to Subject List