TMR0 – Guía Rápida¶
Para más detalles sobre el módulo TMR0, su configuración y funcionamiento, consultar la guía completa.
Cálculos Previos¶
Duración del temporizador¶
\[
\text{Duracion} = \frac{\text{PreScaler} \times \text{Num. Cuentas} \times \text{PostScaler}}{F_{\text{TMR0}}}
\]
Modo 8 bits¶
\[
\mathtt{TMR0H} = \frac {\text{Duracion} \times F_{\text{TMR0}}} {\text{PreScaler} \times \text{PostScaler}} \leq 255
\]
Modo 16 bits¶
\[ \mathtt{TMR0H:L} = 65536 - \frac {\text{Duracion} \times F_{\text{TMR0}}} {\text{PreScaler} \times \text{PostScaler}} \geq 0\]
Orden de lectura / escritura (16 bits)
- Leer: primero
TMR0L, luegoTMR0H. - Escribir: primero
TMR0H, luegoTMR0L.
Registros a usar¶
| Registro | Función | Banco |
|---|---|---|
T0CON0 |
Control: habilitar (T0EN), modo (T016BIT), postscaler (T0OUTPS) |
Access |
T0CON1 |
Fuente de reloj (T0CS), sincronía (T0ASYNC), prescaler (T0CKPS) |
Access |
TMR0H |
Valor de comparación (8 bits) / byte alto del contador (16 bits) | Access |
TMR0L |
Contador (8 bits) / byte bajo del contador (16 bits) | Access |
PIR0 |
Bandera de interrupción TMR0IF (bit 5) |
0x0E |
PIE0 |
Habilitación de interrupción TMR0IE (bit 5) |
0x0E |
IPR0 |
Prioridad de interrupción TMR0IP (bit 5) |
0x0E |
RxyPPS |
Salida PPS de T0_out (0x13). Solo RB y RC. Divide ÷2 la frecuencia |
0x0E |
T0CON0¶
| Bit 7 | Bit 5 | Bit 4 | Bits 3:0 |
|---|---|---|---|
| T0EN | T0OUT (RO) | T016BIT | T0OUTPS[3:0] |
T0EN = 1: habilitar timer.T016BIT = 1: modo 16 bits /T016BIT = 0: modo 8 bits.T0OUT: salidaT0_out, se alterna al ocurrir cada interrupción.T0OUTPS: postscaler — cuenta \((\text{valor}+1)\) eventos antes de levantarTMR0IF.
T0CON1¶
| Bits 7:5 | Bit 4 | Bits 3:0 |
|---|---|---|
| T0CS[2:0] | T0ASYNC | T0CKPS[3:0] |
T0CS[2:0]: Selecciona la fuente de reloj.T0ASYNC = 1: fuente asíncrona con el reloj del sistema.T0CKPS[3:0]: prescaler — divisor de frecuencia de \(2^{(\text{valor})}\).
T0CS[2:0]: Fuentes de reloj
| T0CS[2:0] | Fuente |
|---|---|
| 000 | T0CKIPPS |
| 001 | \(\overline{\text{T0CKIPPS}}\) |
| 010 | Fosc/4 |
| 011 | HFINTOSC |
| 100 | LFINTOSC |
| 101 | MFINTOSC 500 kHz |
| 110 | SOSC |
| 111 | CLC1_OUT |
Configuración básica¶
- Configurar
T0CON1: fuente de reloj (T0CS), prescaler (T0CKPS) y sincronía (T0ASYNC). - Configurar
T0CON0: modo (T016BIT), postscaler (T0OUTPS). - 8 bits: escribir en
TMR0Hel valor \(\text{cuenta máxima} + 1\). - 16 bits: (opcional) precargar
TMR0H:TMR0LconEN = 0. - Habilitar el timer:
T0CON0.T0EN = 1.
Configuraciones opcionales¶
- Interrupción: bajar
PIR0.TMR0IF, habilitarPIE0.TMR0IEy (opscional) configurarIPR0.TMR0IPpara la prioridad. No olvidar tener configurado el INTCON para habilitar las interrupciones. - PPS: escribir
0x13enRxyPPS(solo RB y RC). Divide ÷2 la frecuencia deT0_out.