Hi, Vlad
@ 5 Hz ... period is 200 ms ... Timer1 has a 65536 µs range, so just can use a prescaler value of 4 ...
to read Timer1 ... better try :
Code:
mainloop:
If counter = 2 then
T1CON.0 = 0
time.LowByte = TMR1L
time.HighByte = TMR1H
TMR1L = 0
TMR1H = 0
lcdout $FE, 1
lcdout $FE, $82, dec time, " "
pause 300
counter = 0
endif
Goto mainloop
note ,here, you only read the Pic Timer ... you have to add 2 times 65536 units ( timer overflows )
so, your count value is not good ...
200000 = 3.05 ... times 65536 ! AND overall you do not stop timer @ the end of the period ... but just when counter reaches value of 2 ...
so, doing it like you began to ...
1) TMR1 interrupt just has to increment the "counter" value
2) you must use another interrupt ( RB0 INT i.e.) to start or stop your timer1 ...
AND
3) ON Interrupt cannot be used for a precise timing measurement as it waits for the current PbP Command to complete ... so latency is variable, and overall ... far from negligible.
So, ....
Talking Frankly ... this way to measure pulses won't give satisfactory results ...
a ( much ) simpler way would be to try ...
Code:
MeasLoop:
Pulsin PortB.0,1,PulsHi
RCTime PortB.0,0,Pulslo
Time = PulsHi+PulsLo
LCD Out $FE,$82, dec Time ' etc,etc ...
Pause 500
Goto measLoop
and result will be Time X 10 µsecs ... I encourage you to read your relevant Manual chapters to understand what's happening with this short example ...
You know what ??? pulse measurements with interrupts are not exactly the best way to begin learning PbP ...
Alain
Bookmarks