Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

reaction timer - multiplex inputs

Status
Not open for further replies.

cybersky

Member
Hi all

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?

thanks
 
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.
 
hi,
How accurate a time interval and how long is the measuring period going to be.???
example 1uSec over 10 seconds say.??

Post your full program.
 
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.
 
Last edited:
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.

Mike.
 
Last edited:
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.

Assume a 100mSec base start, then test at 1mSec intervals for 32 periods, giving 132mSec max

Please post your full program.
 
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?
 
Last edited by a moderator:
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?
Please post your full Basic program and we can work through what you have already done.
 
Eric! why don't we push him into a timer... Thats really the only way to do this..

ie.. Light LED, start timer.... button press, read timer... calculate response .... if timer timeouts ... then fail..
 
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.

Mike.
 
Eric! why don't we push him into a timer... Thats really the only way to do this..

ie.. Light LED, start timer.... button press, read timer... calculate response .... if timer timeouts ... then fail..

hi,
Feel free to push...:rolleyes:

If you read between the OP's lines, I suspect this is an assignment which has to completed using Oshonsoft Basic.

The problem i have has to be solved in oshonsoft because i can only code in basic.
 
Eric,

Can you not do as I suggest above in Oshonsoft? I.E. set individual registers and test an individual bit?

Mike.
 
Eric,

Can you not do as I suggest above in Oshonsoft? I.E. set individual registers and test an individual bit?

Mike.

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.

Eric
 
Hi Eric,

I assumed you wouldn't need asm and could just do,
Code:
    T2CON = 5
    PR2 = 249

// and then

    if PIR1.TMR2IF = 1 then
        1mS has passed

//or

    if TMR2IF = 1 then
        etc.

Mike.
 
hi,
That would work OK.

I'm trying to avoid doing some ones assignment. [from scratch]

Eric
Hope all is ship shape after the flooding.
 
Yes, probably best to help rather than spoon feed.

All good after floods. In fact, lost a few kilos due to living on the 14th floor and not having lifts for two weeks.

Mike.
 
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!

Yes, run it under interrupts.
Looking forward to seeing the code.
 
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}
 
Status
Not open for further replies.

Latest threads

Back
Top