A counter in hardware that keeps time so the CPU does not have to. Un contador en hardware que mide el tiempo para que la CPU no tenga que hacerlo.
Santi Scagliusi, PhD
An LED that blinks while the CPU sleeps.Un LED que parpadea mientras la CPU duerme.
mov.w #49, &TA0CCR0
mov.w #CCIE, &TA0CCTL0
mov.w #TASSEL__ACLK|MC__UP|TACLR, &TA0CTL
dormir bis.w #LPM3|GIE, SR ; zzz
nop
jmp dormir
TA00ISR xor.b #BIT0, &P1OUT ; LED1
reti
TA0R ramps 0→49. Every wrap: one interrupt, one LED toggle. The PC stays still in between.TA0R sube 0→49. Cada vuelta: una interrupción, una conmutación. Entre medias el PC no se mueve.
Who is keeping time if the CPU is asleep?Si la CPU duerme, ¿quién lleva la cuenta?
Same wait. One way burns the CPU through it, the other sleeps.La misma espera. Una forma quema la CPU durante ella, la otra duerme.
Same wait: about 100 µA spinning, under 1 µA asleep. La misma espera: unos 100 µA girando, menos de 1 µA dormida.
Four Timer_A instances plus one Timer_B. All 16-bit counters.Cuatro instancias de Timer_A más un Timer_B. Todos contadores de 16 bits.
All five share the same programming model. Learn TA0 and the rest follow. Los cinco comparten el mismo modelo de programación. Aprende TA0 y el resto se deduce.
A clock feeds a divider, which feeds the 16-bit counter TAxR. The mode decides how it counts.Un reloj alimenta un divisor, que alimenta el contador de 16 bits TAxR. El modo decide cómo cuenta.
Every one of these choices is a field of a single register: TAxCTL. Cada una de estas elecciones es un campo de un solo registro: TAxCTL.
Pick a source, a divider and a mode, OR them together, store once.Elige fuente, divisor y modo, los unes con OR, y escribes una vez.
Field MC selects the shape of TAxR over time.El campo MC selecciona la forma de TAxR en el tiempo.
Halted. The counter holds.Detenido. El contador no avanza.
0 to CCR0, then 0. Sets the period.0 a CCR0, luego 0. Fija el periodo.
0 to 0xFFFF, then 0. Free running.0 a 0xFFFF, luego 0. Cuenta libre.
Up to CCR0, then back down. Symmetric.Sube a CCR0, luego baja. Simétrico.
Up mode is the workhorse: CCR0 is the period, the rest is timing inside it. El modo Up es el caballo de batalla: CCR0 es el periodo, lo demás es temporizar dentro de él.
Each channel watches the counter for one value and acts when it matches.Cada canal vigila el contador buscando un valor y actúa cuando coincide.
Sets the period and owns its own interrupt vector.Fija el periodo y tiene su propio vector de interrupción.
Extra compare points inside the same period: a PWM edge or a second event.Puntos de comparación extra dentro del periodo: un flanco PWM o un segundo evento.
No interrupts yet: main watches CCIFG.Aún sin interrupciones: main vigila CCIFG.
espera bit.w #CCIFG, &TA0CCTL0
jz espera
bic.w #CCIFG, &TA0CCTL0 ; ¡borrar!
xor.b #BIT0, &P1OUT
inc.w R10
jmp espera
One LED toggle every 20 counts of TA0R. Then comment out the bic.Una conmutación cada 20 cuentas de TA0R. Después comenta el bic.
Without the bic, how often does the LED toggle?Sin el bic, ¿cada cuánto conmuta el LED?
CCR0 gets a private vector. Everything else shares one and is decoded by TAxIV.CCR0 tiene un vector privado. Todo lo demás comparte uno y se decodifica con TAxIV.
CCIFG: a compare matched. TAIFG: the counter rolled over. CCIFG: coincidió una comparación. TAIFG: el contador se desbordó.
Continuous mode: CCR0 is just another appointment, with its own vector.Modo continuo: CCR0 es una cita más, con su propio vector.
; CCR0: vector propio, flag se borra solo ritmoB add.w #50, &TA0CCR0 xor.b #BIT7, &P9OUT reti ; CCR1: el flag es cosa tuya ritmoA bic.w #CCIFG, &TA0CCTL1 add.w #30, &TA0CCR1 ; re-armar xor.b #BIT0, &P1OUT reti
TA0CCR1 climbs 30, 60, 90… and TA0CCR0 50, 100, 150… (no reset in continuous mode); R10/R11 ≈ 5/3.TA0CCR1 sube 30, 60, 90… y TA0CCR0 50, 100, 150… (en continuo no reinicia); R10/R11 ≈ 5/3.
Remove the add: when does LED1 toggle again?Quita el add: ¿cuándo vuelve a conmutar LED1?
ACLK = 32768 Hz, Up mode, toggle in the ISR: 600 interrupts/s. fout = fclk / (CCR0+1) / 2.ACLK = 32768 Hz, modo Up, conmutar en la ISR: 600 interrupciones/s. fsal = fclk / (CCR0+1) / 2.
Big divider = long range, coarse steps. For high frequencies, don't divide.Divisor grande = rango largo, pasos gruesos. Para frecuencias altas, no dividas.
Compare drives an event at a known time. Capture records the time of an external event.Comparación provoca un evento en un instante conocido. Captura registra el instante de un evento externo.
CM picks the edge, CCIS picks the input. The captured number is just TAxR frozen. CM elige el flanco, CCIS elige la entrada. El número capturado es simplemente TAxR congelado.
Up mode plus reset/set output: CCR0 is the period, CCR1 is the duty cycle. No CPU involved.Modo Up más salida reset/set: CCR0 es el periodo, CCR1 es el ciclo de trabajo. Sin CPU.
CCR1 sets the pulse width. The brightness of an LED, fixed by one register. CCR1 fija la anchura del pulso. El brillo de un LED, fijado por un registro.
The 300 Hz example, no divider: CCR0 = 53.El ejemplo de 300 Hz, sin divisor: CCR0 = 53.
CCR0 .equ 53 ; 32768/54/2 = 303 Hz bis.b #BIT0, &P1DIR mov.w #CCR0, &TA0CCR0 mov.w #CCIE, &TA0CCTL0 mov.w #TASSEL__ACLK|ID__1|MC__UP|TACLR, &TA0CTL dormir bis.w #LPM3|GIE, SR jmp dormir TA00ISR xor.b #BIT0, &P1OUT inc.w R10 reti
In the Timer_A panel, TA0R ramps 0 to CCR0, CCIFG sets, the ISR toggles LED1; R10 counts 606.8 interrupts/s.En el panel Timer_A, TA0R sube de 0 a CCR0, se activa CCIFG, la ISR conmuta LED1; R10 cuenta 606,8 interrupciones/s.
Shared vector without TA0IV: test each CCIFG, clear it, re-arm.Vector compartido sin TA0IV: prueba cada CCIFG, bórrala y re-arma.
CCR1 fires every 30 ticks, CCR2 every 50, through the same ISR.CCR1 dispara cada 30 ticks, CCR2 cada 50, por la misma ISR.
8-bit PWM on P1.0 / TA0.1. The timer drives the output by itself, the CPU is free.PWM de 8 bits en P1.0 / TA0.1. El timer mueve la salida solo, la CPU queda libre.
Click LaunchPad, Run. TA0R counts to 255; the P1.0 output goes high at CCR0 and low at CCR1, no ISR at all.Pulsa LaunchPad, Run. TA0R cuenta hasta 255; la salida P1.0 sube en CCR0 y baja en CCR1, sin ninguna ISR.
A timer is a counter the CPU configures once and then forgets.Un temporizador es un contador que la CPU configura una vez y luego olvida.
Source, divider and mode are all fields of TAxCTL, written in one instruction.Fuente, divisor y modo son campos de TAxCTL, escritos en una instrucción.
Compare turns time into events and PWM. Capture turns events into timestamps.Comparar convierte el tiempo en eventos y PWM. Capturar convierte eventos en marcas de tiempo.
Everything else shares the second vector, decoded by TAxIV. CCIFG vs TAIFG.Todo lo demás comparte el segundo vector, decodificado por TAxIV. CCIFG vs TAIFG.