Microchip Technology dsPIC33F Family Manual de usuario Pagina 11

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 26
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 10
© 2010 Microchip Technology Inc. DS70205C-page 11-11
Section 11. Timers
Timers
11
Example 11-1: Initialization Code for 16-Bit Timer Mode
Figure 11-4: Interrupt Timing for Timer Period Match
Note: The timer counts PRx times for the first TxIF event and (PRx + 1) times for all
subsequent TxIF events. For applications in which the asymmetry in interrupt timing
is not acceptable, it is recommended to ignore the first TxIF event after enabling the
timer.
T1CONbits.TON = 0; // Disable Timer
T1CONbits.TCS = 0; // Select internal instruction cycle clock
T1CONbits.TGATE = 0; // Disable Gated Timer mode
T1CONbits.TCKPS = 0b00; // Select 1:1 Prescaler
TMR1 = 0x00; // Clear timer register
PR1 = 9; // Load the period value
IPC0bits.T1IP = 0x01; // Set Timer1 Interrupt Priority Level
IFS0bits.T1IF = 0; // Clear Timer1 Interrupt Flag
IEC0bits.T1IE = 1; // Enable Timer1 interrupt
T1CONbits.TON = 1; // Start Timer
/* Example code for Timer1 ISR */
void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
{
/* Interrupt Service Routine code goes here */
IFS0bits.T1IF = 0; // Clear Timer1 Interrupt Flag
}
Timer
Clock
Input
TxIF
TMRx
12
34 01 23
4
567 0
1
2
3
0
PRx
9
Cleared by user software Cleared by user software
89
56
7
89
~
~
~
~
Vista de pagina 10
1 2 ... 6 7 8 9 10 11 12 13 14 15 16 ... 25 26

Comentarios a estos manuales

Sin comentarios