kevj
- 22nd February 2008, 08:09
I'm a bit confused on the actual use and syntax when using WORD sized variables.
I'm going to measure a timed event, then use that time as a basis for a pass/fail trial of another timed event. I need to measure the time (16-bit), then manipulate it (subtract a few microseconds), then use that manipulated result to continually pre-load the timer and see if the event happens again within the similar allotted time frame.
Here is what I plan to do and how I will syntax it - wanted to see if I'm doing this correctly?
Using TMR1 ...
'Variables
'-------------
tMeasure VAR WORD 'Holder for the time
tResult VAR WORD 'Holder for modified time
tSet VAR WORD 'Holder for timer set value
'Measure event, manipulate Data
'-------------
T1CON.0=0 'Stop timer
TMR1H = %00000000 'Reset the timer
TMR1L = %00000000 '......
PIR1.0=0 'Clear timer overflow bit
T1CON.0=1 'Start timer
''' Wait for event to measure
T1CON.0=0 'Stop Timer
tMeasure = TMR1 'Should put timer stop value into tMeasure
tResult = tMeasure - 100 'Subtract 100 cycles
tSet = 65025 - tResult 'Setpoint for timer
'' If I pre-load the timer with this tSet number, then wait
'' for it to time out, it should run for a time period in cycles
'' equal to tResult - right?
'Perform trial timeout
'--------------------
T1CON.0=0 'Stop timer
TMR1 = tSet
PIR1.0=0 'Clear timer overflow bit
T1CON.0=1 'Start timer
WHILE PIR1.0=0 : WEND
TOGGLE probe 'Should happen about tResult cycles after
'starting the timer, yes?
'
My real questions are with the manipulation of the 16-bit variables. When I write "TMR1 = tSet", the TMR1H and TMR1L registers are filled correctly with the high byte and low byte of tSet - correct?
Normally I would set TMR1 by manually setting the TMR1H and TMR1L with binary code like "TMR1H = %11101100".
Also, do I need to worry about which direction the data is justified? I know it's important, but if I do it as written, is PBP smart enough to get the justification correct for me?
Thank you!
I'm going to measure a timed event, then use that time as a basis for a pass/fail trial of another timed event. I need to measure the time (16-bit), then manipulate it (subtract a few microseconds), then use that manipulated result to continually pre-load the timer and see if the event happens again within the similar allotted time frame.
Here is what I plan to do and how I will syntax it - wanted to see if I'm doing this correctly?
Using TMR1 ...
'Variables
'-------------
tMeasure VAR WORD 'Holder for the time
tResult VAR WORD 'Holder for modified time
tSet VAR WORD 'Holder for timer set value
'Measure event, manipulate Data
'-------------
T1CON.0=0 'Stop timer
TMR1H = %00000000 'Reset the timer
TMR1L = %00000000 '......
PIR1.0=0 'Clear timer overflow bit
T1CON.0=1 'Start timer
''' Wait for event to measure
T1CON.0=0 'Stop Timer
tMeasure = TMR1 'Should put timer stop value into tMeasure
tResult = tMeasure - 100 'Subtract 100 cycles
tSet = 65025 - tResult 'Setpoint for timer
'' If I pre-load the timer with this tSet number, then wait
'' for it to time out, it should run for a time period in cycles
'' equal to tResult - right?
'Perform trial timeout
'--------------------
T1CON.0=0 'Stop timer
TMR1 = tSet
PIR1.0=0 'Clear timer overflow bit
T1CON.0=1 'Start timer
WHILE PIR1.0=0 : WEND
TOGGLE probe 'Should happen about tResult cycles after
'starting the timer, yes?
'
My real questions are with the manipulation of the 16-bit variables. When I write "TMR1 = tSet", the TMR1H and TMR1L registers are filled correctly with the high byte and low byte of tSet - correct?
Normally I would set TMR1 by manually setting the TMR1H and TMR1L with binary code like "TMR1H = %11101100".
Also, do I need to worry about which direction the data is justified? I know it's important, but if I do it as written, is PBP smart enough to get the justification correct for me?
Thank you!