Another Timer Question
Posted: Thu Jan 08, 2009 4:21 pm
Hello Guys,
I have another timer question.
I’m using a 877a with the E-blocks and have made a simple flowcode program that I want to measure the time between pressing switch a1 (timer on) and a2 (timer off)
The first attempt was made with Timer 1:
Loop till A1 is 1
start timer (in C)
tmr1h = 0x00; // make Timer 1H value 0
tmr1l = 0x00; // Make Timer 1L value 0
t1con = 0x3B; // Start timer with 1:8 prescaler
Loop till A2 is 1
stop timer (in C)
t1con = 0xFE; //Stop Timer1 Counting
FCV_T1_COUNT_L = tmr1l; //Store LSB
FCV_T1_COUNT_H = tmr1h; //Store MSB
Then I’m trying to read out these values on the LCD. (At this stage I’m only interested in reading the L and H value).
Both these values show consistently 0 and 0. I presume that this is caused by the timer that overflows before I can even stop the timer and this is the reason it is showing 00
I have made the same program for timer two and indeed I actually get a reading. The problem here is that this timer doesn’t time higher then FF and then starts over again.
At this stage I have a few questions:
- Is my assumption on Timer 1 correct. (no reading due to overflow);
- If so, how can I overcome this?
- What is the best approach to make this program so I can measure between 2 and 30msec. (use T1 or T2)?
Thanks for all the help
Henk
I have another timer question.
I’m using a 877a with the E-blocks and have made a simple flowcode program that I want to measure the time between pressing switch a1 (timer on) and a2 (timer off)
The first attempt was made with Timer 1:
Loop till A1 is 1
start timer (in C)
tmr1h = 0x00; // make Timer 1H value 0
tmr1l = 0x00; // Make Timer 1L value 0
t1con = 0x3B; // Start timer with 1:8 prescaler
Loop till A2 is 1
stop timer (in C)
t1con = 0xFE; //Stop Timer1 Counting
FCV_T1_COUNT_L = tmr1l; //Store LSB
FCV_T1_COUNT_H = tmr1h; //Store MSB
Then I’m trying to read out these values on the LCD. (At this stage I’m only interested in reading the L and H value).
Both these values show consistently 0 and 0. I presume that this is caused by the timer that overflows before I can even stop the timer and this is the reason it is showing 00
I have made the same program for timer two and indeed I actually get a reading. The problem here is that this timer doesn’t time higher then FF and then starts over again.
At this stage I have a few questions:
- Is my assumption on Timer 1 correct. (no reading due to overflow);
- If so, how can I overcome this?
- What is the best approach to make this program so I can measure between 2 and 30msec. (use T1 or T2)?
Thanks for all the help
Henk