Syntax:
StartTimer TimerNoCommand Availability:
Available on all microcontrollers with a Timer module.
Explanation:
StartTimer is used to start the specified timer.
Timer 0:
Please refer to the datasheet to determine if Timer 0 on specific Microchip PIC microcontroller
can be started and stopped with starttimer and stoptimer. If the Microchip PIC microcontroller
has a register named "T0CON" then it supports stoptimer and starttimer.
On Microchip PIC 18(L)Fxxx microcontrollers Timer 0 can be started with starttimer.
On Microchip PIC baseline and midrange microcontrollers starttimer (and stoptimer) has no effect upon Timer 0.
Example:
This example will measure that time that a switch is depressed (or on) and will write the results to the EEPROM.
#chip 16F819, 20
#define SWITCH PORTA.0
Dir SWITCH In
DataCount = 0
'Initilise Timer 1
InitTimer1 Osc, PS1_8
Dim TimerValue As Word
Do
ClearTimer 1
Wait Until SWITCH = On
StartTimer 1 ' <<< the StartTimer instruction
Wait Until SWITCH = Off
StopTimer 1
'Read the timer
TimerValue = Timer1
'Log the timer value
EPWrite(DataCount, TimerValue_H)
EPWrite(DataCount + 1, TimerValue)
DataCount += 2
LoopKey line: StartTimer 1 — starts Timer 1 counting from wherever ClearTimer left it, right when the switch is pressed.
See Also:
- InitTimer1 — configuring the timer’s clock source/prescaler before starting it
- StopTimer / ClearTimer — stopping and resetting the timer, as used above
- Settimer — preloading a timer’s count value
- Reading Timers — reading a running timer’s current count
- EPWrite — logging the measured timer value, as used above
Supported in <TIMER.H>

