MSP432 Chapter5 Timers
MSP432 Chapter5 Timers
MSP432 Chapter5 Timers
Programming
1
An 8-bit up-counter stages
2
An 8-bit down-counter stages
3
Counter Mode of Operation of Timer
4
Compare Mode of Operation of Timer
5
Capture Mode of Operation of Timer
6
System Tick Timer
7
System Tick Timer Internal Structure
MCLK
8
System Tick Counting
9
STRVR (STReload Value Register)
STCVR (STCurrent Value Register)
10
STCTRL (System Tick Control)
SysTick->CTRL = 5 = 0101 11
if (SysTick->CTRL & 0x10000) // If COUNTFLAG is Set
Delay Calculation using SysTick Timer
12
Timer32 Timer
• Features of Timer32:
• Two independent counters (T1 & T2) each configurable as 32-bit or 16-bit Down
Counter
• Three different timer modes supported for each counter
• Prescale unit to divide the input clock by 1, 16 or 256
• Independent Interrupts from each of the counter, as well as, a combined interrupt
from both the counters
13
Mode of Operation
• For each of the timers, the following modes of operation are available:
• Free-running mode: The counter wraps after reaching its zero value, and
continues to count down from the maximum value. This is the default mode.
• Periodic/Wrapping timer mode: The counter generates an interrupt at a
constant interval, reloading the value from T32LOADx register.
• One-shot timer mode: The counter generates an interrupt once. When the
counter reaches zero, it halts until reprogrammed by the user.
14
Counting in Free-Running Mode vs. Periodic/Wrapping Mode
15
Timer32 Timer Internal Structure
MCLK
16
Timer32 Registers
Offset Acronym Register Name Type Reset Value
00H T32LOAD1 Timer 1 Load Register RW 0
04H T32VALUE1 Timer 1 Current Value Register R FFFFFFFFH
08H T32CONTROL1 Timer 1 Timer Control Register RW 20H
0CH T32INTCLR1 Timer 1 Interrupt Clear Register W -
10H T32RIS1 Timer 1 Raw Interrupt Status Register R 0
14H T32MIS1 Timer 1 Interrupt Status Register R 0
18H T32BGLOAD1 Timer 1 Background Load Register RW 0
20H T32LOAD2 Timer 2 Load Register RW 0
24H T32VALUE2 Timer 2 Current Value Register R FFFFFFFFH
28H T32CONTROL2 Timer 2 Timer Control Register RW 20H
2CH T32INTCLR2 Timer 2 Interrupt Clear Register W -
30H T32RIS2 Timer 2 Raw Interrupt Status Register R 0
34H T32MIS2 Timer 2 Interrupt Status Register R 0
38H T32BGLOAD2 Timer 2 Background Load Register RW 0H
17
T32CONTROLx Register
18
TIMER32_1->CONTROL = 0xC2 = 0x1100 0010;
T32RISx (T32 Raw Interrupt Status) Register
19
T32LOADx & T32VALUEx Register
20
T32INTCLRx Register
21
Delay Calculation using Timer32
22
Timer A Timer
• Timer A features :
• Asynchronous 16-bit timer/counter with four operating modes
• Selectable and configurable clock source
• Up to seven configurable capture/compare registers
• Configurable outputs with pulse width modulation (PWM) capability
• Asynchronous input and output latching
23
TimerA Modes of Operation
24
Counting in Up Mode
25
Counting in Continuous Mode
26
Counting in Up/Down Mode
28
A more detailed diagram of Timer_A
29
TAxR register
30
TAxCTL register
31
bit Name Description
TAxCTL register
Timer_A Interrupt Flag
0 TAIFG 0: Timer did not overflow
1: Timer overflowed (TAIFG will be cleared on writing one to this bit)
1 TAIE Timer_A Interrupt Enable (0: Disabled, 1: Enabled)
2 TACLR 0: Timer_A Not Clear, 1: Timer_A Clear
Mode Control:
00: Stop mode: timer is halted
4-5 MC 01: Up mode: Timer counts up to TAxCCR0
10: Continuous mode: Timer counts up to 0xFFFF
11: Up/down mode: Timer counts up to TAxCCR0 then down to 0.
Input divider: These bits select the divider for the input clock:
00: divide by 1
6-7 ID 01: divide by 2
10: divide by 4
11: divide by 8
Timer_A clock Source Select: These bits select the Timer_A clock source:
00: TAxCLK (external clock): The timer uses external clock which is fed to the
PM_TAxCLK pin. (Counter Mode)
8-9 TASSEL
01: ACLK (internal clock)
10: SMCLK (internal clock)
11: INCLK (Counter Mode)
32
TIMER_A1->CTL = 0x02D1 = 0000 0010 1101 0001
TAxEXn Register
34
TAxCCRn Register
35
Delay Calculation using Timer A
37
TAxCCTLn Register
bit Name Description
Capture mode
00: No capture
15-14 CM 01: Capture on rising edge
10: Capture on falling edge
11: Capture on both rising and falling edges
Capture/compare input select. These its select the TAxCCR0 input signal:
00: CCIxA
13-12 CCIS 01: CCIxB
10: GND
11: VCC
Synchronize capture source. This bit is used to synchronize the capture input signal with the
timer clock.
11 SCS
0: Asynchronous capture
1: Synchronous capture
38
TAxCCTLn Register
bit Name Description
Synchronized capture/compare input. The selected CCI input signal is latched
10 SCCI
with the EQUx signal and can be read via this bit.
Capture mode
8 CAP 0: Compare mode
1: Capture mode
Output mode. Modes 2, 3, 6, and 7 are not useful for TAxCCR0 because
EQUx = EQU0
000: OUT bit value
001: Set
OUTM 010: Toggle/reset
7-5
OD 011: Set/reset
100: Toggle
101: Reset
110: Toggle/set
111: Reset/set
39
TAxCCTLn Register
bit Name Description
Capture/compare interrupt enable. This bit enables the interrupt request of the corresponding
CCIFG flag.
4 CCIE
0: Interrupt disabled
1: Interrupt enabled
3 CCI Capture/compare input. The selected input signal can be read by this bit.
Output. For output mode 0, this bit directly controls the state of the output.
2 OUT 0: Output low
1: Output high
Capture overflow. This bit indicates a capture overflow occurred. COV must be reset with
software.
1 COV
0: No capture overflow occurred
1: Capture overflow occurred
Capture/compare interrupt flag
CCIF
0 0: No interrupt pending
G
1: interrupt pending