| ??? 01/04/08 12:56 Read: times Msg Score: +2 +1 Informative +1 Good Answer/Helpful |
#149032 - A related trick Responding to: ???'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
|
| Topic | Author | Date |
| Number of CPU cycle for 8051 function call | 01/01/70 00:00 | |
| Do it in assembler | 01/01/70 00:00 | |
| Delay functions | 01/01/70 00:00 | |
| A related trick | 01/01/70 00:00 | |
| Offset | 01/01/70 00:00 | |
| Offset | 01/01/70 00:00 | |
| Sure | 01/01/70 00:00 | |
| Over Drive? | 01/01/70 00:00 | |
| a refinement | 01/01/70 00:00 | |
| NOPs are so bad waste of space... | 01/01/70 00:00 | |
| waste of space... waste of time | 01/01/70 00:00 | |
| fixed delay | 01/01/70 00:00 | |
| Variable delay | 01/01/70 00:00 | |
| determinism of the cache | 01/01/70 00:00 | |
| there are no cache misses in 'linear code' | 01/01/70 00:00 | |
| I got only ONE cache miss... | 01/01/70 00:00 | |
| Old Keil Thread | 01/01/70 00:00 | |
| What about a Delay like this. | 01/01/70 00:00 | |
| No, it won't. | 01/01/70 00:00 | |
| Ok. | 01/01/70 00:00 | |
| also | 01/01/70 00:00 | |
| Also ... | 01/01/70 00:00 | |
| Actually... | 01/01/70 00:00 | |
| will. | 01/01/70 00:00 | |
| ANSI C | 01/01/70 00:00 | |
Keil option: Disable ANSI casts | 01/01/70 00:00 | |
| typo. | 01/01/70 00:00 |



