R32V2020 Timers
Jump to navigation
Jump to search
Contents
Timer Unit
There are multiple timers in the Timer Unit.
- x3800 - Elapsed Time Counter (FPGA clocks)
- x3801 - Microsecond Counter
- x3802 - Millisecond Counter
- x3803 - CPU Cycle Counter
Sample Code
Microsecond Counter
; ; delay_uS - delay for the number of uSecs ; pass mSec delay in r8 ; Uses routine uses r9 (saved and restored) ; delay_uS: push r9 push PAR lix PAR,0x3801 ; address of the uSec counter lpl r9 ; read the peripheral counter into r9 add r8,r9,r8 ; terminal counter to wait until is in r8 loop_delay_uS: lpl r9 ; check the elapsed time counter cmp r8,r9 blt loop_delay_uS pull PAR pull r9 pull PC
Millisecond Counter
; ; delay_mS - delay for the number of mSecs passed in r8 ; pass mSec delay in r8 ; Uses routine uses r9 ; delay_mS: push r9 push PAR lix PAR,0x3802 ; address of the mSec counter lpl r9 ; read the peripheral counter into r9 add r8,r9,r8 ; terminal counter to wait until is in r8 loop_delay_mS: lpl r9 ; check the elapsed time counter cmp r8,r9 blt loop_delay_mS pull PAR pull r9 pull PC
CPU Cycle Counter
; ; readCPUCycleCounter ; return CPU cycle counter in r8 ; Useful function for counting the number of CPU cycles it take to do something ; readCPUCycleCounter: push PAR lix PAR,0x3803 ; address of the uSec counter lpl r8 ; read the peripheral counter into r8 pull PAR pull PC
Elapsed Time Counter
; ; readElapsedTimeCounter ; return timer count in r8 ; readElapsedTimeCounter: push PAR lix PAR,0x3800 ; address of the uSec counter lpl r8 ; read the peripheral counter into r8 pull PAR pull PC