Module 11 · ClosingMódulo 11 · Cierre

System Modules: Clock, Power & LCDMódulos del sistema: reloj, alimentación y LCD

The background systems that keep the CPU fed, timed, and visible. Los sistemas de fondo que mantienen la CPU alimentada, sincronizada y visible.

Santi Scagliusi, PhD

Where we are goingA dónde vamos

A seconds clock on the LCD, CPU asleep 99% of the time.Un reloj de segundos en el LCD, con la CPU dormida el 99% del tiempo.

reloj   bis.w #LPM3|GIE, SR  ; 1 s
        clrc
        dadd.b #1, R10       ; BCD
        cmp.b #0x60, R10
        jne   mostrar
        clr.w R10            ; 59→00
mostrar call  #pintar
        jmp   reloj
WatchObserva

00 → 59 → 00 on the two right digits. 32768 Hz crystal, ACLK/8, CCR0 = 4095.00 → 59 → 00 en los dos dígitos de la derecha. Cristal de 32768 Hz, ACLK/8, CCR0 = 4095.

PausePausa

Which clock keeps running while the CPU sleeps?¿Qué reloj sigue vivo mientras la CPU duerme?

▶ BoardPlaca · M11 · Demo: reloj de segundos en el LCD

Four systems behind the CPUCuatro sistemas detrás de la CPU

The CPU runs instructions. These keep it powered, ticking, supervised, and on-screen.La CPU ejecuta instrucciones. Estos la mantienen alimentada, en marcha, supervisada y en pantalla.

schedule
CS

Clock system. Generates MCLK, SMCLK and ACLK.Sistema de reloj. Genera MCLK, SMCLK y ACLK.

battery_charging_full
PMM

Power management. Makes VCORE, supervises the supply.Gestión de energía. Genera VCORE y supervisa la alimentación.

pets
WDT

Watchdog. Resets the chip if software hangs.Watchdog. Reinicia el chip si el software se cuelga.

grid_view
LCD_C

LCD controller. Drives the 6-digit segment display.Controlador LCD. Maneja el display de segmentos de 6 dígitos.

Three system clocks, three customersTres relojes del sistema, tres clientes

One clock system fans out to the CPU and two classes of peripheral.Un sistema de reloj se reparte a la CPU y a dos clases de periférico.

CS 0x0160 MCLK CPU + systemCPU + sistema SMCLK fast peripheralsperiféricos rápidos ACLK slow / low-powerlento / bajo consumo

Where the ticks come fromDe dónde salen los pulsos

Three oscillators, three points on the frequency line.Tres osciladores, tres puntos en la recta de frecuencias.

VLO ~10 kHz internal, ultra-low-powerinterno, consumo mínimo LFXT 32768 Hz watch crystal, precisecristal de reloj, preciso DCO 1–24 MHz on-chip, selectableinterno, seleccionable 10 kHz 32 kHz MHz faster →más rápido → HFXT, MODOSC and LFMODOSC round out the set.HFXT, MODOSC y LFMODOSC completan el conjunto.

The clock tree you get for freeEl árbol de relojes que obtienes gratis

After reset every clock already has a source.Tras el reset cada reloj ya tiene una fuente.

DCO 8 MHz LFXT off LFMODOSC ~37.5 kHz ÷8 ÷8 1 MHz 1 MHz asked for, but offpedido, pero apagado fault fallbackrespaldo por fallo MCLK CPU SMCLK fast periph.perif. rápidos ACLK low-powerbajo consumo

ACLK asks for LFXT. Until you enable it, ACLK falls back to LFMODOSC.ACLK pide LFXT. Hasta que lo habilitas, ACLK cae a LFMODOSC.

CS registers are password protectedLos registros de CS están protegidos por contraseña

CSCTL0 · 0x0160
0xA5
high byte · keybyte alto · clave
0x00
low bytebyte bajo
Right key → CSCTL1–6 unlockedClave correcta → CSCTL1–6 abiertos
Wrong key → reset (PUC)Clave errónea → reset (PUC)

Switching ACLK to the crystalPasar ACLK al cristal

        BIS.B #BIT4, &PJSEL0      ; PJ.4 = LFXIN
        MOV.B #0A5h, &CSCTL0_H    ; unlock
        BIC.W #LFXTOFF, &CSCTL4   ; LFXT on
wait    BIC.W #LFXTOFFG, &CSCTL5  ; clear fault
        BIC.W #OFIFG, &SFRIFG1
        BIT.W #OFIFG, &SFRIFG1
        JNZ   wait                ; until stable
        BIC.W #SELA_7, &CSCTL2    ; ACLK = LFXT
        MOV.B #0, &CSCTL0_H       ; lock

Why 32768 HzPor qué 32768 Hz

It is 215. Fifteen divide-by-2 stages land exactly on 1 Hz.Es 215. Quince etapas de dividir entre 2 caen exactamente en 1 Hz.

32768 Hz ÷2 16384 ÷2 8192 ··· 15 stages15 etapas ··· 2 ÷2 1 Hz
timer

A 15-bit counter overflows once per second. That is the heartbeat of a clock.Un contador de 15 bits desborda una vez por segundo. Ese es el latido de un reloj.

PMM: supply in, core outPMM: entra alimentación, sale el núcleo

An LDO makes VCORE from DVCC. A supervisor watches the rail and resets on a droop.Un LDO genera VCORE desde DVCC. Un supervisor vigila la línea y resetea ante una caída.

DVCC 1.8–3.6 V LDO regulatorregulador VCORE CPU + memoryCPU + memoria SVS + BOR below ~1.8 V → hold / restart cleanpor debajo de ~1.8 V → reset limpio

After power-up or LPMx.5, unlock the pins with bic.b #LOCKLPM5, &PM5CTL0.Tras el encendido o LPMx.5, desbloquea los pines con bic.b #LOCKLPM5, &PM5CTL0.

Sleep is four bits inside SRDormir son cuatro bits dentro del SR

These bits in the status register choose how much of the chip keeps running.Estos bits del registro de estado eligen cuánta parte del chip sigue en marcha.

SR (R2) · bits 8–0bits 8–0
V
8
SCG1
7
SCG0
6
OSC
5
CPU
4
GIE
3
N
2
Z
1
C
0
■ clock / CPU off bits■ bits de apagado de reloj / CPU ■ GIE (lets interrupts wake it)■ GIE (deja que una interrupción la despierte)
BIS.W #GIE|LPM3, SR
LPM3 bits = 0x00D0bits LPM3 = 0x00D0

One instruction sets the bits and the CPU stops. An interrupt wakes it; RETI restores the mode.Una instrucción pone los bits y la CPU se detiene. Una interrupción la despierta; RETI restaura el modo.

Count the wake-upsCuenta los despertares

R11 = loop turns. R10 = interrupts.R11 = vueltas del bucle. R10 = interrupciones.

bucle   inc.w R11
        bis.w #LPM3|GIE, SR  ; dormir
        nop
        jmp   bucle
TA00ISR inc.w R10
        bic.w #LPM3, 0(SP)   ; despertar
        reti
WatchObserva

With LPM3, R11 = R10 + 1. Replace the bis with nop: R11 explodes.Con LPM3, R11 = R10 + 1. Cambia el bis por nop: R11 se dispara.

PausePausa

Without bic #LPM3, 0(SP), how many times does the loop turn?Sin bic #LPM3, 0(SP), ¿cuántas vueltas da el bucle?

▶ SimulatorSimulador · M11 · Demo: ¿cuántas veces se despierta la CPU?

The low-power ladderLa escalera de bajo consumo

Each rung down turns off more clocks and drops the current further.Cada peldaño apaga más relojes y baja más la corriente.

ActiveActivo CPU + MCLK on, ACLK onCPU + MCLK on, ACLK on ~100 µA/MHz
LPM0 CPU + MCLK off, ACLK onCPU + MCLK off, ACLK on ~50 µA
LPM3 only ACLK on, RTC-capablesolo ACLK on, permite RTC ~0.9 µA
LPM4 all clocks off, wake on interrupttodos los relojes off, despierta por interrupción ~0.4 µA
LPM4.5 regulator off, no RAM retentionregulador off, sin retención de RAM ~0.02 µA

More awake · higher current ← → less awake · lower currentMás despierto · más corriente ← → menos despierto · menos corriente

The watchdog counts toward a resetEl watchdog cuenta hacia un reset

Clear it in time, or the chip resets.Bórralo a tiempo, o el chip se reinicia.

Stop itDetenerlo
Pet itAcariciarlo
Let it runDejarlo correr
RESET ⟲
MOV.W #WDTPW|WDTHOLD, &WDTCTL

Stop it. First line of most examples. Key 0x5A, WDTHOLD = BIT7.Detenerlo. Primera línea de casi todo ejemplo. Clave 0x5A, WDTHOLD = BIT7.

MOV.W #WDTPW|WDTCNTCL, &WDTCTL

Pet it. Clear the counter on a healthy loop so it never reaches the cliff.Acariciarlo. Borra el contador en un bucle sano para que nunca llegue al borde.

LCD_C drives the 6-digit displayLCD_C maneja el display de 6 dígitos

A dedicated controller paints segments with no CPU work once it is set up.Un controlador dedicado pinta segmentos sin trabajo de CPU una vez configurado.

123456

Six digits, A1 to A6.Seis dígitos, de A1 a A6.

0x0A00 control registers (LCDCCTL0…)registros de control (LCDCCTL0…)
LCDMx display memory, two bytes per digitmemoria de display, dos bytes por dígito

14-segment digits: A1 lives in LCDM10 + LCDM11.Dígitos de 14 segmentos: A1 vive en LCDM10 + LCDM11.

One byte lights the segmentsUn byte enciende los segmentos

Each bit switches one segment.Cada bit enciende un segmento.

G M
LCDM10 = 0xB7
A1 shows "5"A1 muestra "5"
LCDM10 · bit 7 → bit 0bit 7 → bit 0
A
B
C
D
E
F
G
M
1
0
1
1
0
1
1
1

Middle bar = two halves, G and M. Diagonals and DP live in LCDM11.Barra central = dos mitades, G y M. Diagonales y DP viven en LCDM11.

LaunchPad map. The simulator does not model the LCD: try it on the board.Mapa de la LaunchPad. El simulador no modela el LCD: pruébalo en la placa.

Run it on the board: 123456En la placa: 123456

Six bytes, six digits.Seis bytes, seis dígitos.

        call  #lcdInit
        mov.b #0x60, &LCDM10  ; 1
        mov.b #0xDB, &LCDM6   ; 2
        mov.b #0xF3, &LCDM4   ; 3
        mov.b #0x67, &LCDM19  ; 4
        mov.b #0xB7, &LCDM15  ; 5
        mov.b #0xBF, &LCDM8   ; 6
WatchObserva

Digit order on the LaunchPad does not follow LCDM order.El orden de los dígitos en la LaunchPad no sigue el orden de LCDMx.

PausePausa

Which byte turns the 6 into an 8?¿Qué byte convierte el 6 en un 8?

▶ BoardPlaca · M11 · Demo: el LCD muestra 123456

Where this course took youHasta dónde te llevó este curso

From a single bit to a whole microcontroller, twelve modules.De un solo bit a un microcontrolador completo, doce módulos.

0–4
The coreEl núcleo

Bits, registers, addressing modes, instructions and formats.Bits, registros, modos de direccionamiento, instrucciones y formatos.

5–8
Memory and I/OMemoria y E/S

Memory map, assembly with C, interrupts and power, digital I/O.Mapa de memoria, ensamblador con C, interrupciones y energía, E/S digital.

YOU ARE HEREESTÁS AQUÍ
9–11
PeripheralsPeriféricos

Timers, cooperative multitasking, and the system modules.Temporizadores, multitarea cooperativa y los módulos del sistema.

Three ideas to close onTres ideas para cerrar

The system modules, in three lines.Los módulos del sistema, en tres líneas.

CS

One tree, three clocks.Un árbol, tres relojes.

MCLK for the CPU, SMCLK for fast peripherals, ACLK for low-power ones.MCLK para la CPU, SMCLK para periféricos rápidos, ACLK para los de bajo consumo.

µA

Sleep is the default.Dormir es lo normal.

PMM keeps it powered, LPM turns clocks off, the watchdog catches hangs.El PMM la alimenta, los LPM apagan relojes, el watchdog atrapa cuelgues.

LCD

Peripherals do the work.Los periféricos hacen el trabajo.

Set up LCD_C once and it paints segments on its own. That is the whole point.Configura LCD_C una vez y pinta segmentos solo. Ese es todo el sentido.