+TheBF Posted April 8 Author Share Posted April 8 I messed up my ticker. In my last version of the kernel I thought I could make a single timer that ran with 1mS resolution and save some space. That was a mistake. In order to not block any other processes the timer always called PAUSE to give other tasks a turn while waiting. If the time to get back from servicing all the tasks is greater than 1MS which it almost always is, this messes up the delays. They become way longer than they should be. To prevent this I have decided it is best to reduce the resolution of the timer to 32mS so that even under the worst circumstances when multitasking the MS delays will be closer to real time . I will post new version of the kernel and the super-cart kernel after I am satisfied with the result. It should be ok since 16mS was used in the distance past. The upside I guess is that I invented a little code word that makes the loop faster so we are wasting less time in the delay loop itself. For the curious here is the code \ TICKTOCK.HSF TMS9901 hardware timer interface for Camel 99 Forth \ credit to: http://www.unige.ch/medecine/nouspikel/ti99/tms9901.htm#Timer \ improvements based on code from Tursi Atariage \ TMR! now loads from the Forth stack \ Apr 2023 Went back to a new TICKS word that is more efficient. \ MS min= 32 milliseconds \ timer resolution: 64 clock periods, thus 64*333 = 21.3 microseconds \ Max Duration : ($3FFF) 16383 *64*333 ns = 349.2 milliseconds [CC] DECIMAL TARGET-COMPILING CODE TMR! ( n -- ) \ load TMS9901 timer from stack 0 LIMI, R12 CLR, \ CRU addr of TMS9901 = 0 0 SBO, \ SET bit 0 to 1, Enter timer mode R12 INCT, \ CRU Address of bit 1 = 2 , I'm not kidding TOS 14 LDCR, \ Load 14 BITs from TOS into timer -1 SBZ, \ reset bit 0, Exits clock mode, starts decrementer 2 LIMI, TOS POP, NEXT, ENDCODE CODE TMR@ ( -- n) \ read the TMS9901 timer 0 LIMI, TOS PUSH, R12 2 LI, \ cru = 1 (honest, 2=1) -1 SBO, \ SET bit 0 TO 1, Enter timer mode TOS 14 STCR, \ READ TIMER (14 bits) -1 SBZ, \ RESET bit 1, exit timer mode 2 LIMI, NEXT, ENDCODE [PRIVATE] CODE DT ( T1 T2 -- n) *SP TOS SUB, \ t1-t2 TOS ABS, *RP TOS SUB, \ subtract from value on Return stack NEXT, ENDCODE [PUBLIC] : TICKS ( n -- ) \ ** n(max) = 4000 ~= 100 ms ** >R TMR@ BEGIN TMR@ DT 0< WHILE PAUSE REPEAT R> 2DROP ; \ 1500 TICKS ~= to 32mS : MS ( n -- ) 5 RSHIFT 0 ?DO 1500 TICKS LOOP ; 2 Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.