I am trying to create a reaction timer using the 16f874.
what i am thinking of coding -
Code:
dim rtim byte 'keep track of clock cycle w.r.t instruction timing?
dim rtimes(10) as byte 'an array to store 10 timings
getbutton:
if portb.1 = 1 then
rtim = 2 'using the step simuation it shows if using 2cycles
rtimes(0) = rtim + 2
end if
rtim = rtim + 2
goto getbutton
So i will "count" the clock cycles using the rtim then store that in the array and send it to pc via serial. then my pc prog can multiply that by .05us to get actual reaction time.
I have simplified the code to show my idea - so i understand the code is incomplete.
The question being will this wok?
hi,
Using a 4MHz crystal the internal PIC cycle time would be 1MHz [ 1 uSec], BUT you have a number of cycles in the short increment loop, each one taking 1uSec so you would not be counting clock cycles.
How accurate a time interval and how long is the measuring period going to be.???
hi,
Using a 4MHz crystal the internal PIC cycle time would be 1MHz [ 1 uSec], BUT you have a number of cycles in the short increment loop, each one taking 1uSec so you would not be counting clock cycles.
How accurate a time interval and how long is the measuring period going to be.???
Hi
Basically we will have "different" response lengths. i have a board with 36 leds and 36 push buttons (no).
the user will send a string to the pic representing the led to turn on. with the string we will send the desired "on delay" value.
so i have to chk if the desired time has passed or not - if the time is not up i will save the time into the array at the same index as the led "frame" index.
if the time is expired i will write max value.
then after all frames have played i will send to PC.
normal human reaction at its fastest is arounf 100 - 120ms, so we do not really have to be as precise as uSecs ? But we do want a fair amount of accuracy. Hope i am making sense.
Use a 1mS interrupt and a 16 bit variable and you will get mS accuracy and up to a 1 minute interval. It is very easy to setup timer2 to generate a 1mS interrupt or to just set a bit every mS if interrupts aren't desirable.
normal human reaction at its fastest is arounf 100 - 120ms, so we do not really have to be as precise as uSecs ? But we do want a fair amount of accuracy. Hope i am making sense.
100mS base is ok but atleast 200-300ms to respond?
I have not used the timer functions yet - only been using oshonsoft and 16f84's but would that work if i have 36 buttons (6x6multiplex) ?
The problem i have has to be solved in oshonsoft because i can only code in basic.
Would it be a problem to count the cycles for timing?
100mS base is ok but atleast 200-300ms to respond?
I have not used the timer functions yet - only been using oshonsoft and 16f84's but would that work if i have 36 buttons (6x6multiplex) ?
The problem i have has to be solved in oshonsoft because i can only code in basic.
Would it be a problem to count the cycles for timing?
With a 4MHz crystal you only have to setup two registers to get a 1mS signal. Set T2CON = 5 and PR2 = 249 and then PIR1.TMR2IF will get set every 1mS. It really is that easy to use a hardware timer. In your code you can do something like,
Code:
if PIR1.TMR2IF = 1 then
PIR1.TMR2IF = 0
Ms = Ms+1
if Ms = 1000 then
Ms=0
Seconds = Seconds+1
endif
endif
Counting cycles is so last year and also pretty difficult.
hi Mike,
Yes, you can use ASM lines in the Basic text OK, in OSH Basic.
I keep asking the OP to post the coding he has done.... still no response.
I don't mind helping debug what he is doing but I dont intend to write the full program based on his hazy description.
Hi
Thanks for the replies!. just to clarify this is not homework - and i will post the code as soon as i have done it. as i asked in the 1st post was "if counting cycles would work". and i like using oshonsoft so that is why i am asking for basic code.
If i use the timer function will that run "independently" ie - when i do activate an led i can just reset the second or msecods variables ?
thx - my code is on it way to you!
Hi
Thanks for the replies!. just to clarify this is not homework - and i will post the code as soon as i have done it. as i asked in the 1st post was "if counting cycles would work". and i like using oshonsoft so that is why i am asking for basic code.
If i use the timer function will that run "independently" ie - when i do activate an led i can just reset the second or msecods variables ?
thx - my code is on it way to you!
hi Ian, that is exactly what i am looking for - my question was (from my post) is
Light LED, start timer by adding "cycles" to variable - while waiting for either a keypress or timeout......save cycles to array
{CODE}
getkey:
if portb.0 = 1 then
savecycle
endif
rtim = rtim + 2 'rtim is the cycle variable
if rtim = maxtim then
goto nextLed 'i will clear rtim here before lighting the next led (dont need code for that, only asking about best way for getting the time)
end if
rtim = rtim + 2 'rtim is the cycle variable
goto getkey
{CODE}