Thanks Bruce!
Your idea worked fine but the issue is that it looks like at this PIC the TMR0 input signal should be synchronized with the internal phase clock which I don’t have and can’t have. My input signal is from an independent source. I found in the manual that synchronization issue.
As a result, the timer shows basically random results.
I gave up with TMR0 and will calculate the input pulses just using counting. I changed the program for that and noticed that it works but the problem is that the TMR1H accumulates the value and I can’t realise why. every circle TMR1 does notr have reset despite I put an operator to do that.
The program is below.
Do any have any suggestions? It’s some stupid error…
Define OSC 10
define HSER_TXSTA 20h
define HSER_BAUD 9600
' variables defintion
Counter var byte
TMR1valuelow var byte
TMR1valuehigh var byte
TRISA = %11111111 ' Set all PORT A to input
TRISB = %11111111 ' Set all port B to input
TRISC = %10010000 ' Set all PORT C to output/input for RS232
' ports variables
InputSignal var PORTB.0
clear
main:
Counter = 0
T1CON = %10000000 ' stop TMR1, internal clock, scale 1:1, 16-bit work
TMR1L = 0 ' clear TMR1 low
TMR1H = 0 ' clear TMR1 high
PIR1.0 = 0 ' reset overflow flag for TMR1 just in case
T1CON = %10000001 ' start TMR1 as 16-bits
loop1:
while InputSignal = 0
wend ‘ waiting for rising edge of input signal
Counter = Counter + 1 ' counting rising edges of input pulses
if Counter = 250 then exit ' when 250 input pulses – look at TMR1 values
while InputSignal = 1
wend ‘ waiting for falling edge of input signal
goto loop1 ‘ going back on falling edge
exit:
T1CON = %10000000 ' stop TMR1
TMR1valuelow = TMR1L
TMR1valuehigh = TMR1H
Hserout ["TMR1low =",dec TMR1valuelow, "TMR1high =",dec TMR1valuehigh]
goto main
End
So, what I noticed in here is that it looks like TMR1H does not go to zero when I reset it at each stage clearing TMR1high and accumulates the value. Why is that?
Appreciate your comments.





Bookmarks