thunderace7
New Member
Hi,
I am trying to use the timer in a 28x2 to make a repeating interrupt every 10 seconds. The manual is not very clear on this (at least, not to me) but I think it works something like this:
The timer operates with "minor tick" which are related to the clock frequency and, at 8Mhz, occur every 32 microseconds. These minor ticks are counted in a word variable that is not user accessible. When this variable overflows from 65535 to 0, a "major tick" is produced which is counted on a variable called "timer" that is user accessible. When this "timer" variable overflows from 65535 to 0, an interrupt flag is set, causing the program to jump to the "interrupt" subroutine. It seems that this flag remains set and must be reset within the interrupt subroutine. The interrupt must also be re-enabled with the "setintflags" command within the interrupt subroutine.
The manual also states that the timer can be preloaded with a value to reduce the time until overflow. This is achieved by the command "settimer". I believe that this preloads the minor ticks counter, NOT the "timer" variable as seems logical (to me, at least). Using the constant "t1s_8" a value of 34286 is preloaded to give 1 second timing at 8Mhz. I believe that this actually gives minor tick overflow as 1 second intervals, not 1 second interrupts. To get 10 second interrupts, the major tick variable "timer" also has to be preloaded with the value 65526.
Does all this sound right or am I mistaken?
I have played around in the Editor and have come up with the following program:
code:
initialise:
#picaxe 28x2 ; define picaxe chip for compiler
setfreq m8 ; select internal resonator 8MHz
let dirsa=%11111111 ; set port a as outputs
let dirsb=%11111111 ; set port b as outputs
let dirsc=%11111111 ; set port c as outputs
settimer t1s_8 ; settimer to 1 second ticks at 8MHz
setintflags %10000000,%10000000 ; set timer 0 to interrupt
let timer=65526 ; preload timer variable for 10 second interrupt
main:
Let pinC.4=1 ; insert main program here
Pause 100 ; insert main program here
Let pinC.4=0 ; insert main program here
Pause 100 ; insert main program here
let pinsb=timer ; insert main program here
Goto main ; loop back to repeat
interrupt:
pause 2000 ; insert interrupt program here
setintflags %10000000,%10000000 ; set timer 0 to interrupt
let timer=65526 ; preload timer variable for 10 second interrupt
let toflag=0 ; clear timer overflow flag
return
code:
This seems to work but it might not be correct. I think maybe the "let toflag=0" line could be replaced by another "settimer t1s_8" line. Would this be more correct?
Thanks,
Chris.
I am trying to use the timer in a 28x2 to make a repeating interrupt every 10 seconds. The manual is not very clear on this (at least, not to me) but I think it works something like this:
The timer operates with "minor tick" which are related to the clock frequency and, at 8Mhz, occur every 32 microseconds. These minor ticks are counted in a word variable that is not user accessible. When this variable overflows from 65535 to 0, a "major tick" is produced which is counted on a variable called "timer" that is user accessible. When this "timer" variable overflows from 65535 to 0, an interrupt flag is set, causing the program to jump to the "interrupt" subroutine. It seems that this flag remains set and must be reset within the interrupt subroutine. The interrupt must also be re-enabled with the "setintflags" command within the interrupt subroutine.
The manual also states that the timer can be preloaded with a value to reduce the time until overflow. This is achieved by the command "settimer". I believe that this preloads the minor ticks counter, NOT the "timer" variable as seems logical (to me, at least). Using the constant "t1s_8" a value of 34286 is preloaded to give 1 second timing at 8Mhz. I believe that this actually gives minor tick overflow as 1 second intervals, not 1 second interrupts. To get 10 second interrupts, the major tick variable "timer" also has to be preloaded with the value 65526.
Does all this sound right or am I mistaken?
I have played around in the Editor and have come up with the following program:
code:
initialise:
#picaxe 28x2 ; define picaxe chip for compiler
setfreq m8 ; select internal resonator 8MHz
let dirsa=%11111111 ; set port a as outputs
let dirsb=%11111111 ; set port b as outputs
let dirsc=%11111111 ; set port c as outputs
settimer t1s_8 ; settimer to 1 second ticks at 8MHz
setintflags %10000000,%10000000 ; set timer 0 to interrupt
let timer=65526 ; preload timer variable for 10 second interrupt
main:
Let pinC.4=1 ; insert main program here
Pause 100 ; insert main program here
Let pinC.4=0 ; insert main program here
Pause 100 ; insert main program here
let pinsb=timer ; insert main program here
Goto main ; loop back to repeat
interrupt:
pause 2000 ; insert interrupt program here
setintflags %10000000,%10000000 ; set timer 0 to interrupt
let timer=65526 ; preload timer variable for 10 second interrupt
let toflag=0 ; clear timer overflow flag
return
code:
This seems to work but it might not be correct. I think maybe the "let toflag=0" line could be replaced by another "settimer t1s_8" line. Would this be more correct?
Thanks,
Chris.