| TIMER (SX48/52 only) | Example |
TIMER[1 | 2] Command {Value {, Value}}
Function
Configures the SX48/52 Multi-Function timer T1 (TIMER1) or T2 (TIMER2).
Quick Facts
| I/O Pin | Function |
| RB.4 | Timer T1 Capture Input 1 |
| RB.5 | Timer T1 Capture Input 2 |
| RB.6 | Timer T1 PWM/Compare Output |
| RB.7 | Timer T1 External Event Clock Source |
| RC.0 | Timer T2 Capture Input 1 |
| RC.1 | Timer T2 Capture Input 2 |
| RC.2 | Timer T2 PWM/Compare Output |
| RC.3 | Timer T2 External Event Clock Source |
TIMER Commands
TIMER[1 | 2] CLEAR
Clears the hardware timer/counter.
TIMER[1 | 2] PRESCALE Value
Sets the hardware timer/counter prescaler. Value is a constant as defined in the table below.
| Value | Prescaler |
| 0 | 1:1 |
| 1 | 1:2 |
| 2 | 1:4 |
| 3 | 1:8 |
| 4 | 1:16 |
| 5 | 1:32 |
| 6 | 1:64 |
| 7 | 1:128 |
TIMER[1 | 2] R1 Value
Sets the hardware timer/counter R1 register. Value is a byte or word constant/variable.
TIMER[1 | 2] R2 Value
Sets the hardware timer/counter R2 register. Value is a byte or word constant/variable.
TIMER[1 | 2] TIMER
Sets the hardware timer/counter to "Software Timer" mode.
TIMER[1 | 2] PWM OnCycles, PeriodCycles
Sets the hardware timer/counter to "PWM" mode. OnCycles is loaded into timer register R1, and PeriodCycles - OnCycles is loaded into register R2. Note that you must make the PWM pin an output. OnCycles and PeriodCycles are byte or word constants/variables.
The example below illustrates the use the of PWM option to modulate an IR LED at 38 kHz:
DEVICE SX48, OSCXT1
FREQ 4_000_000
IrLed VAR RB.6
PROGRAM Start
Start:
OUTPUT IrLed ' enable LED output
TIMER1 PWM, 52, 105 ' modulate at 38 kHz, 50%
DO
' additional program statements
LOOP
END
TIMER[1 | 2] CAPTURE
Sets the hardware timer/counter to "Capture/Compare" mode.
TIMER[1 | 2] EXTERNAL
Sets the hardware timer/counter to "External Event" mode.