Dim i As Byte
Dim rtim As Word 'number of cycles
Dim mtim As Word 'max time allowed (in cycles)
Dim react(10) As Word 'array to hold reaction times
'new variables from the forum example
Dim ms As Word
Dim seconds As Word
i = 0
main: 'i will have to restart the pic to reset - fine for now
If PORTB.0 = 1 Then
Goto ledon 'simplified version of final app - using 1 led and 1 button
Endif 'just want this timing issue sorted please.
If PORTB.1 = 1 Then
Goto getnewframes
Endif
Goto main
ledon:
PORTA.1 = 1 'led on
getkey:
If PORTB.2 = 1 Then 'reaction button
PORTA.1 = 0 'turn out the light...
rtim = ms
react(i) = ms 'save reaction into array
i = i + 1
'WaitMs(3000) 'wait 3sec before led on
Goto ledon 'start led on again and get another timing
Endif
If PIR1.TMR2IF = 1 Then
PIR1.TMR2IF = 0
ms = ms + 1
If ms = 1000 Then
ms = 0
seconds = seconds + 1
Endif
Endif
If ms > 2 Then 'no key pressed yet so we goto next
PORTA.1 = 0 'turn out the light
'WaitMs(3000)
Goto ledon
i = i + 1
Endif
Goto getkey
getnewframes:
'serial data from pc - code not needed
'when done we start ledon
Here is my understanding of the code fragment using timer / interrupt.
When i try to simulate this it hangs at ms = ms + 1.
I thought timer / interrupt needed the interupt pin to chg state in order to register an "interupt" ??
Hi I think i have a solution - but could you clarify the interupt timing count w.r.t my version of the code ? ie what would ms = 2 be in realtime?
Code:
TRISB = 0x00 'set all PORTB pins as outputs
Config PORTB = Input
INTCON.T0IE = 1 'enable Timer0 interrupts
INTCON.GIE = True 'enable all un-masked interrupts
OPTION_REG.T0CS = False 'set Timer0 clock source to internal instruction cycle clock
Dim i As Byte
Dim rtim As Word 'number of cycles
Dim react(10) As Word 'array to hold reaction times
Dim ms As Word
Dim seconds As Word
i = 0
main: 'i will have to restart the pic to reset - fine for now
If PORTB.0 = 1 Then
Goto ledon 'simplified version of final app - using 1 led and 1 button
Endif 'just want this timing issue sorted please.
If PORTB.1 = 1 Then
Goto getnewframes
Endif
Goto main
ledon:
PORTA.1 = 1 'led on
getkey:
If PORTB.2 = 1 Then 'reaction button
PORTA.1 = 0 'turn out the light...
rtim = ms
react(i) = ms 'save reaction into array
i = i + 1
'WaitMs(3000) 'wait 3sec before led on
Goto ledon 'start led on again and get another timing
Endif
If ms > 2 Then 'no key pressed yet so we goto next
PORTA.1 = 0
ms = 0 'turn out the light
'WaitMs(3000)
i = i + 1
Goto ledon
Endif
Goto getkey
getnewframes: 'serial data from pc - code not needed
End
On Interrupt 'interrupt routine
ms = ms + 1 'decrement the value on PORTB
INTCON.T0IF = 0 'enable new TMR0 interrupts
Resume
Interupt is almost like an independent thread? sort of?
so when it fires i add 1 to ms but what does this represent ?
basically we will be varying the delays from a software pattern sort of test. So i will be sendng the pic the ondelay value and the delay between led on's. then a string representing the "sequence" of led to flash.
So we have 36 leds with 36 switches in a multiplex setup and measuring the response per "led" based on the max reaction time. we using a pic16f874A - It is for a thesis project (not mine, just helping with the dev/building of rig)
thanks for the response. I have just wrapped my mind around the timer thing - but the adc will follow soon coz i want to build a temp sensor (which has been done to death - but i want my own and in basic ! LOL).
thanks - but in general is it ok to use the timer pins?
and
INTCON.T0IE = 1 'enable Timer0 interrupts
Then
INTCON.T0IE = 2 'enable Timer1 interrupts ?? if pic has more than one?
thanks - but in general is it ok to use the timer pins?
and
INTCON.T0IE = 1 'enable Timer0 interrupts
Then
INTCON.T0IE = 2 'enable Timer1 interrupts ?? if pic has more than one?
as i understand it... the timer function will fire "automatically". If i use the timer pin as an input and it is triggered would that not also cause the timer function to fire aswell ?? sorry for the "simple" question, but i would rather ask.
could you pls show a sml piece of code for somthing like: on interrupt 1 , on interrupt 2 ?
as i understand it... the timer function will fire "automatically". If i use the timer pin as an input and it is triggered would that not also cause the timer function to fire aswell ?? sorry for the "simple" question, but i would rather ask.
could you pls show a sml piece of code for somthing like: on interrupt 1 , on interrupt 2 ?
hi
do you perhaps have some documentation on the INTCON ?
INTE = 1 'rb0 pin will trigger interrupt
INTCON.TOIE = 1 'enable the interrupt to fire based on timer
OPTION_REG.T0CS = False 'set Timer0 clock source to internal instruction cycle clock
so
OPTION_REG.T"1"CS = False 'set "Timer1" clock source to internal instruction cycle clock ?
how do you use the TMR0 Prescalers ?
with the lack of literature on Oshonsoft, small code bits are a real help.
repeat after me : "Google is your friend...", heheh
I guess my input to oshonsoft would be to help us "lazy" programmers by providing an intellisense feature so that we can check what other attributes there are to functions and SFR's.
repeat after me : "Google is your friend...", heheh
I guess my input to oshonsoft would be to help us "lazy" programmers by providing an intellisense feature so that we can check what other attributes there are to functions and SFR's.
we have them multiplexed - 6rows on RB with 6cols on RA then a mix of RC & RD for the switch inputs.
the code samples are just for information sake and to increase my "oshonsoft" knowledge base. - I have downloaded all the datasheets and some tutorials on the SFR and Timers. Perhaps I am needing the "syntax" for oshonsoft more than perhaps the code, but sample do help. if i could ref. multiple timers the possiblities...
yes i have read the oshonsoft manual but it makes you want to flip the monitor around to see where the "missing" pages are ! LOL.
I have made headway using the datasheets and OSH. timer 1 and timer 2 .
BUT looking forward to your pearls of code - don't mind the wait just very happy that you were able to assist! thank you.