For a little more clarity here is the actual code I used as my example.
EVENT1 CLR R12 CRU base of the TMS9901 SBO 0 Enter timer mode LI R1,>3FFF Maximum value INCT R12 Address of bit 1 LDCR R1,14 Load value DECT R12 There is a faster way (see below) SBZ 0 Exit clock mode, start decrementer EVENT2 CLR R12 SBO 0 Enter timer mode STCR R2,15 Read current value (plus mode bit) SRL R2,1 Get rid of mode bit LDCR R12,15 Clear Clock register, and exit timer mode S R2,R1 How many cycles were done?
My apparently unique use is to let the timer run continuously.
When I want to time something, I read the timer with code like EVENT2 , but I don't subtract anything, I simply store the timer value.
Then some time later (less than 349 mS) I just read the timer again, subtract both readings and get the ABS value.
Simple and faster than reloading each time.
Here is the actual code in RPN assembler. Notice I had to disable interrupts.
CODE: TMR! ( -- ) \ load TMS9901 timer to max value 3FFF W 3FFF LI, \ load scratch register W with MAXIMUM timer value R12 CLR, \ CRU addr of TMS9901 = 0 0 LIMI, 0 SBO, \ SET bit 0 to 1, Enter timer mode R12 INCT, \ CRU Address of bit 1 = 2 , I'm not kidding W 0E LDCR, \ Load 14 BITs from R1 into timer R12 DECT, \ go back to address 0 0 SBZ, \ reset bit 0, Exits clock mode, starts decrementer 2 LIMI, NEXT, \ 16 bytes END-CODE CODE: TMR@ ( -- n) \ read the TMS9901 timer TOS PUSH, R12 CLR, 0 LIMI, 0 SBO, \ SET bit 0 TO 1, ie: Enter timer mode TOS 0F STCR, \ READ TIMER (14 bits plus mode bit) into W TOS 1 SRL, \ Get rid of mode bit 0 SBZ, \ SET bit 1 to zero 2 LIMI, NEXT, END-CODE