Microchip Technology dsPIC33F Family Manual de usuario Pagina 8

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 16
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 7
dsPIC33F Family Reference Manual
DS70198C-page 12-8 © 2009 Microchip Technology Inc.
12.5.1 Code Example for Period Measurement
The following code example shows the time period measurement using the Input Capture
module. The capture event is generated on every rising edge and the capture interrupt is
generated after taking two time stamps for period measurement, as illustrated in Figure 12-5.
Example 12-1: Capture Code Example
// Initialize Capture Module
IC1CONbits.ICM=0b00; // Disable Input Capture 1 module
IC1CONbits.ICTMR= 1; // Select Timer2 as the IC1 Time base
IC1CONbits.ICI= 0b01; // Interrupt on every second capture event
IC1CONbits.ICM= 0b011; // Generate capture event on every Rising edge
// Enable Capture Interrupt And Timer2
IPC0bits.IC1IP = 1; // Setup IC1 interrupt priority level
IFS0bits.IC1IF = 0; // Clear IC1 Interrupt Status Flag
IEC0bits.IC1IE = 1; // Enable IC1 interrupt
// Capture Interrupt Service Routine
unsigned int timePeriod= 0;
void __attribute__((__interrupt__)) _IC1Interrupt(void)
{
unsigned int t1,t2;
t1=IC1BUF;
t2=IC1BUF;
IFS0bits.IC1IF=0;
if(t2>t1)
timePeriod = t2-t1;
else
timePeriod = (PR2 - t1) + t2;
}
Vista de pagina 7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Comentarios a estos manuales

Sin comentarios