PDA

View Full Version : Get elapsed time while TIMER samples pulses



RodSTAR
- 15th October 2007, 18:25
hi fellows,
this is a shorter and clearer way to expose my question:

Does any Interrupt or Timer variable let me capture elapsed time ?
[modified code taken from mister_e post]

Start:
TMR1L=0 ' Clear Counter
TMR1H=0 ' Clear Counter
'
TMR1ON=1 ' START counter
...DO_THINGS ' <----Do other things in unknown time while counting in background
...FOR..NEXT...LCDOUT.... ' ....things happen
hserout pulseRATE
TMR1ON=0 ' STOP counter
'
CounterA.HIGHBYTE=TMR1H ' Get results
CounterA.LOWBYTE=TMR1L '

LapTIME = ELAPSED_TIME ' Get ms <---- Something like this is what I wish... does it exist?
'so I can do the following:
pulseRATE = CounterA / LapTIME ' this would be heaven... :) [pseudocode]
'pulseRATE is the pulse rate in this cycle.
'
' Blah blah blah
'
goto start



The idea is to handle a sort of variable (LapTIME) that handles the elapsed time(ms) while TMR1ON=1 (between START and STOP). to make accurate calculations like pulse rate, speed.. (for quadrature encoders)

well, that is it
thanks for your time
regards,

RodSTAR

paul borgmeier
- 16th October 2007, 03:46
>>to make accurate calculations like pulse rate

Many PICs have capture modules that capture the time between incoming rising (or falling) pulse edges. Look at the datasheet for your PIC and see if it has this capability. These modules are relatively easy to setup (and work great).

RodSTAR
- 16th October 2007, 04:33
Paul, I'll have a look for that at the datasheet.
By the way I plan to use a 16F628A. Im my desktop I have 8 16F628A's, some 16F876A, 16F877A, 18F252, 18F4550, 18F4685, 12F509, and planning to get a 18F4431 or 2431, which have hardware built-in QEI pins (Quadrature Encoder Interface), 8 14-bit PWM modules (thru RB & RD ports), I know those monsters are made for what I need, but I think there's still a chance with theese theese brave warriors and polular PIC16F628A's.

Thank you Paul,

Watching datasheet,
RodSTAR

RodSTAR
- 16th October 2007, 08:38
now I am self suggesting,
maybe is it possible to use different timers?
for example
1)start TMR0 to measure time
2)start TMR1 to count pulses
3)process other things while TMR0 and TMR1 measure in background..
4)stop TMR0 to measure time
5)stop TMR1 to count pulses
6)get measured time from TMR0
7)get counted pulses from TMR1

maybe an advanced user may help me

infinitrix
- 27th March 2009, 16:27
rodstar,do u has code for your solution..