SN8P2740 Series
ADC, OP-amp, Comparator 8-Bit Micro-Controller
SONiX TECHNOLOGY CO., LTD
Page 81
Version 2.0
8.3.2 TC0 TIMER OPERATION
TC0 timer is controlled by TC0ENB bit. When TC0ENB=0, TC0 timer stops. When TC0ENB=1, TC0 timer starts to
count. Before enabling TC0 timer, setup TC0 timer
‟s configurations to select timer function modes, e.g. basic timer,
interrupt function
…TC0C increases “1” by timer clock source. When TC0 overflow event occurs, TC0IRQ flag is set
as
”1” to indicate overflow and cleared by program. The overflow condition is TC0C count from full scale (0xFF) to zero
scale (0x00). In difference function modes, TC0C value relates to operation. If TC0C value changing effects operation,
the transition of operations would make timer function error. So TC0 builds in double buffer to avoid these situations
happen. The double buffer concept is to flash TC0C during TC0 counting, to set the new value to TC0R (reload buffer),
and the new value will be loaded from TC0R to TC0C after TC0 overflow occurrence automatically. In the next cycle,
the TC0 timer runs under new conditions, and no any transitions occur. The auto-reload function is no any control
interface and always actives as TC0 enables. If TC0 timer interrupt function is enabled (TC0IEN=1), the system will
execute interrupt procedure. The interrupt procedure is system program counter points to interrupt vector (ORG 0008H)
and executes interrupt service routine after TC0 overflow occurrence. Clear TC0IRQ by program is necessary in
interrupt procedure. TC0 timer can works in normal mode, slow mode and green mode. But in green mode, TC0 keep
counting, set TC0IRQ and outputs PWM, but can
‟t wake-up system.
0x00
or TC0R
...
...
Clock
Source
TC0C
TC0IRQ
TC0 timer overflows. TC0IRQ set as “1”.
Reload TC0C from TC0R automatically.
TC0IRQ is cleared by program.
0x01
0x02
0x03
0xFE
0xFF
TC0R
...
...
TC0 provides different clock sources to implement different applications and configurations. TC0 clock source includes
Fcpu (instruction cycle) and Fhosc (high speed oscillator) controlled by TC0CKS bit. TC0CKS bit selects the clock
source is from Fcpu or Fhosc. If TC0CKS=0, TC0 clock source is Fcpu through TC0rate[2:0] pre-scalar to decide
Fcpu/2~Fcpu/256. If TC0CKS=1, TC0 clock source is Fhosc through TC0rate[2:0] pre-scalar to decide
Fhosc/2~Fhosc/256. TC0 length is 8-bit (256 steps), and the one count period is each cycle of input clock.
TC0CKS
TC0rate[2:0] TC0 Clock
TC0 Interval Time
Fhosc=16MHz,
Fcpu=Fhosc/4
Fhosc=4MHz,
Fcpu=Fhosc/4
max. (ms) Unit (us) max. (ms) Unit (us)
0
000b
Fcpu/256
16.384
64
65.536
256
0
001b
Fcpu/128
8.192
32
32.768
128
0
010b
Fcpu/64
4.096
16
16.384
64
0
011b
Fcpu/32
2.048
8
8.192
32
0
100b
Fcpu/16
1.024
4
4.096
16
0
101b
Fcpu/8
0.512
2
2.048
8
0
110b
Fcpu/4
0.256
1
1.024
4
0
111b
Fcpu/2
0.128
0.5
0.512
2
1
000b
Fhosc/256
4.096
16
16.384
64
1
001b
Fhosc/128
2.048
8
8.192
32
1
010b
Fhosc/64
1.024
4
4.096
16
1
011b
Fhosc/32
0.512
2
2.048
8
1
100b
Fhosc/16
0.256
1
1.024
4
1
101b
Fhosc/8
0.128
0.5
0.512
2
1
110b
Fhosc/4
0.064
0.25
0.256
1
1
111b
Fhosc/2
0.032
0.125
0.128
0.5