thanks mister_e, this will help me in experimenting the 1ms interval polling. Is there anyone can help me on how to get 1ms interval by polling method for timer1?
thanks mister_e, this will help me in experimenting the 1ms interval polling. Is there anyone can help me on how to get 1ms interval by polling method for timer1?
I modified the Olympic Timer program, by replacing the:
TMR1RunOn.HighByte= $FC
TMR1RunOn.LowByte=$18
and deleted the TMR1RunOn=TMR1Preset+TMR1RunOn, to directly load the TIMER1 preset value into the timer1 register.
This make the timer by the program runs faster than used to. Until I change the value to $FF,$FE, the timer can have the timing interval very close to 1ms, but still slightly delayed, as I compare the timing (seconds) with a watch. The watch is about 2x faster than the timing by the timer.
Attached is the code I wrote by referring to the Olympic Timer by Melanie. Is there any problem with the code? Any solution for that? Thanks in advance.
Last edited by sycluap; - 12th January 2008 at 13:08.
I rewrite a new program to activate Timer1 as free-running timer. I take the TMR1L and TMR1H value directly, and obtain a new result by:
Result = TMR1H*256+TMR1L
May I know, is the RESULT I get is in microsecond? As far as I understand, 4Mhz clock will result in 1us per cycle. Thus, is the value obtained in RESULT is in microsecond? Please correct me if I am wrong, I would like to have the result 1 milliseconds. Below is my code, hope some one can correct my mistake.
ResetTimer:
GoSub SetRe
Last edited by sycluap; - 13th January 2008 at 08:46.
Start the timer before doing anything with the LCD. The LCD commands take time. It'll skew the result quite a bit.Code:StartTimer: LCDOUT $Fe, 1 LCDOUT $FE, $80, "Calculating..." T1CON.0=1
When stopping the timer, you'll also have to account for the extra cycles taken during the GOSUBs and other code to get there...if you want a really accurate result.Code:GetValue: Timer1H=TMR1H Timer1L=TMR1L
And T1 is going to overflow every 65.536us, slightly more than 15 times per second.
If you press the button at 70,000us, you'll get a result of 4,464, not the result you want.
How you plan on accounting for the rollover?
Ok, I will change to Start the timer before doing anything on the LCD. I see, from the explanation, may I know the timer rolloever every 65536 microsecond or 65.536 microsecond? Let's say is it as what Mr.Skimask says, now I understand that the timer will rollover every 65.536 microseconds. May I know how to account the rollover in order to get the incrementing time, instead of keep on doing from 0 to 65.536 microseconds? Is it possible to do something like,
if Result > 65536 then
A=A+1
if A > 65536 then
B=B+1
and so on..... I assume that timer1 from 0 to 65536 then rollover to 0 again, and so on. So, when timer1 reach 65536, then A increment by 1, and timer rollover back to start from 0 again. Then, when the 2nd time timer1 reach 65536, A will increment again, and so on. Is this possible? Let A keep on incrementing until I can trace the reading of the timer back in milliseconds? Or is there any better solution? Thanks in advance.
Last edited by sycluap; - 13th January 2008 at 09:19.
I think you could use the Timer 1 interrupt for that.
But as Miss Melanie says:
Use the CCP.
Been on vacation (looooooooooooong vacation ), now I'm back (not that I'm very useful to the forum, I just ask a lot).
Bookmarks