Calculator Community > TI Z80

Accurate Subsecond Timing

<< < (2/2)

E37:
According to wikiti, TI-OS uses all but 1 timer for its own purposes.

This is the code that Axe uses to input and output to Ans:

--- Code: ---p_StoreAns: ;sets ans to hl
B_CALL(_SetXXXXOP2)
B_CALL(_OP2toOP1)
B_CALL(_StoAns)
ret

p_RecalAns: ;reads ans into hl
B_CALL(_RclAns)
B_CALL(_ConvOP1)
ex de,hl
ret

--- End code ---

thepenguin77:
I do miss figuring out how the hardware works and reverse engineering the OS. I don't miss debugging asm code...

Here's how to use the program that does accurate timing on the TI-84+ like startTmr:

--- Code: ---# Start the timers
Asm(prgmTIMESTRT)

# Store the elapsed time (at 1/128s resolution) into Ans
#   -1 if an error is detected (timers disabled or system clock went backwards)
Asm(prgmTIMEIT)

--- End code ---

Someone should do a whole bunch of testing on this to make sure it's accurate. I've tested all the special cases like 0 and 2^21 (where the final result requires 17 bits to be stored), and they work. But I can't guarantee this works always and forever. I'd probably recommend a basic program that asserts that the outputs from this program are consistently increasing at the same rate and then let that run overnight or something.

Caveats:

* If you change your system clock, this will be inaccurate
* If you let your calculator turn off, the timers are disabled.
* Running other programs that mess with the timers will break this.

The details:

After playing around with the timers, I can see that timer2 get disabled the very first time it overflows which makes it totally useless. This check happens in the interrupt routine and there's no way to stop it.

Timer1 and Timer3 don't get disabled as long as their control port has bit 1 set to 0 (they aren't triggering interrupts), so these are both safe to use as far as I can tell. Presumably they get used somewhere but I'm not sure where.


The program works exactly as depicted in the python code above. There was a mistake in the original post but I've edited it to fix it. Nothing is too complicated, but coding this up in assembly is rough. I kept the full-precision of the internal clock, so in theory, this program can keep track of time for like 2^32 seconds.

The program seems to take 0.0195 seconds to run from within TI-BASIC (just call TIMESTRT then call TIMEIT 10 times and divide ANS by 10). The program stores the timer values as soon as it starts, but whether the slowness is TI-BASIC starting the program or the floating point operations while returning the result I'm not sure.


Code and programs attached. It ended up being around 300 lines and 400 bytes.

newsboys6:
Oh wow Oh wow.

So time start starts the timer once called and then does timeit return the total time elapsed once it is triggered?

I do believe that these are what I need and when I get to work tomorrow morning I will hook everything up and let everyone know how it goes.

Cheap precision is something I have been chasing for a while and the hardware to hook up only requires a few leds, photoresisors, a transistor and a resistor.  Far cheaper than $50 for a single photogate from Vernier (you need two to time something).  I think something like this can benefit elementary schools, middle schools, and high schools.  Especially ones that are underfunded.

So, from the bottom of my heart, thank you.


Ok, don't know if i am using it wrong or not.  It could be a problem that the program I am using to listen to the link port is also storing values in Ans.  When I first ran it I was getting syntax errors when I was calling TIMESTRT after IN took the trigger from the linkport.

I switched things around to start the timer before everything else but being that I have to also call IN to listen to the state of the port may be causing problems.  My posted TI basic code below returns two 3's which is the default state of the linkport.

Not that a beggar can be a chooser but doing your emailed suggestion on having a program that listens and triggers and stores a set number of times in a list in Ans and is triggered by tip tip or ring ring might be the better way to go if possible.

Code and result attached below.


--- Code: ---Lbl 0
ClrHome
Menu("Physics Tools","Car Timer",1,"Pendulum Timer",2,"Drop Timer",3,"Kinetic Energy",4,"Quit",5)
Lbl 1
ClrHome
Pause "Press Enter to Begin"
Asm(prgmTIMESTRT
Asm(prgmIN
While Ans=3
Asm(prgmIN
End
Asm(prgmTIMEIT
Disp Ans
Asm(prgmIN
While Ans=1
Asm(prgmIN
End
While Ans=3
Asm(prgmIN
End
Asm(prgmTIMEIT
Disp Ans
Disp "Press 1 to Time Again"
Disp "Or press 2 to Return to Menu"
Prompt K
If K=1
Goto 1
Goto 0
--- End code ---

Ill attach an image later, it returns to 3's.


Edit (Eeems): Merged double post

thepenguin77:
I think we're going to need the code of the IN program.

Do my programs at least work in isolation for you?

newsboys6:
IN is a program written entirely in hex provided by the youtube video linked up top.  It can be typed directly into the calculator and compiled by the calculator itself the code is as follows:


--- Code: ---PROGRAM:0IN
:AsmPrgm
:DB00
:26006F
:EF9247
:EF5641
:EFBF4A
:C9
--- End code ---

You type that into your calculator and save it.  Then you run: AsmComp(prgm0IN, prgmIN)

And there you go, you have IN which returns a 3 by default when both he tip and the ring are high.

These are the states returned to Ans by IN:

Value     Tip      Ring

0           Low     Low
1           High    Low
2           Low     High
3           High    High

They go low when they are connected to ground.  My little circuit connects the ring to the ground when a car rolls over either of the photoresistors thus triggering the start or end of something when Ans is not equal to 3 (equal to 1).

Thank you again, I can't say that enough.

Navigation

[0] Message Index

[*] Previous page

Go to full version