Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: fb39ca4 on December 18, 2013, 07:20:49 pm
-
I'm trying to make the main loop of my program run at 30Hz. Here is how I set up timer 1 at the beginning of my app:
;set timer 1 to not loop, not interrupt
ld a, $00
out ($31), a
;set timer 1 to 993Hz
ld a, $41
out ($30), a
;set timer 1 count down from 33 for effective framerate of ~30Hz
ld a, 33
out ($32), a
And at the beginning of my loop (which is copied to appBackupScreen), I have this:
in a, ($32)
cp 0
jp nz, appBackupScreen
ld a, 33
out ($32), a
ld a, $00
out ($31), a
;rest of code goes here
I'm pretty sure what I am doing is setting the timer to 993Hz, disabling repeats and interrupts, and at the beginning of the loop polling the timer until it is zero, then continuing with the rest of the code. However, it gets stuck in the polling loop. According to Wabbitemu's debugger, register A has a value of 33 (decimal), indicating the timer is not counting down. If I jump over the polling loop in my code, everything else runs perfectly.
-
I believe it may be the case that the counter never actually hits 0, and instead goes from 1 straight to the last value that was written to it. Anyway, the proper way to detect if a crystal timer has finished is to check its bit in port 4 (http://wikiti.brandonw.net/index.php?title=83Plus:Ports:04).
-
If it is resetting to the previous value, how do you start it again?
-
Your code to restart it seems fine.
-
If I am understanding this correctly, reading the counter port will not give the current count of the timer, only the value you wrote into it, correct?
EDIT: Thanks, worked perfectly!