Deseamos crear una base de tiempo de 1ms y para ello utilizaremos un el TIMER3 de PIC18F. (Ver diagrama de bloques en la figura 14-1) ![]() Tiempo de Ciclo paso a paso: En el módulo TMR3 se produce la interrupción TMR3IF cada vez que TMR3 llega su máximo (FFFFx0). Cada 0.5us se suma uno al contador TMR3 por lo tanto necesitamos que se produzca la interrupción cada 2000 ciclos. Para ello antes deberemos de precargar un valor a TMR3 para que la suma sea de 2000. Siendo un contador de 16bits habrán 65536 códigos por lo que el código a cargar a TMR3 será 63536 igual a F830x0. Valores seleccionados: Prescaler: 2:1 TMR3L: 46 // count up from F830 but there is a small overhead and TMR3L must be 0x46 TMR3H: F8 C code: /* TMR3IE = 1; T3CON = 0; T3CONbits.RD16 = 1; // 0 = R/W as 8 bits, 1 = R/W as 16 bits T3CONbits.T3CCP2 = 0; // used with both CCP modules T3CONbits.T3CKPS1 = 0; // 2 bit Prescale value: 00: PS = 1, T3CONbits.T3CKPS0 = 1; // 01: PS = 2, 10: PS = 4, 11: PS = 8 T3CONbits.T3CCP1 = 0; // used with CCP2 module T3CONbits.T3SYNC = 0; // Timer 1 Osc Sync: 0 = on, 1 = off T3CONbits.TMR3CS = 0; // Clock Source: 0 = Fcy, 1 = Ext Clk T3CONbits.TMR3ON = 1; // 0 = turn timer off, 1 = turn timer on TMR3H = 0xFA; // TMR3H must be written first TMR3L = 0x46; // count up from F830 but there ara a small overhead and TMR3L must be 0x46 TMR3IF = 0; // reset the interrupt flag */ |