Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
What´s wrong with it?With 32 bit timer and 1:1 prescaler I can't handle the 16 bit lsb and 16 bit msb values.
WHAT channel?But I have only one channel available on my controller as per the design
void IC_INIT(void)
{
// Register 13-1: ICxCON: Input Capture x Control Register in datasheet
IC2CONbits.ICM= 0b011; // Input Capture Mode Select (Every rising edge)
IC2CONbits.ICBNE=0; // Input Capture Buffer Empty Status (Read Only)
IC2CONbits.ICOV=0; // Input Capture Overflow Status Flag (Read Only)
IC2CONbits.ICI= 00; // Select Number of Captures per Interrupt bits (00 = Interrupt on every capture event)
IC2CONbits.ICTMR=1; // Input Capture Timer Select bits 1=TMR2 contents are captured on captured event)
IC2CONbits.ICSIDL=0; // Input Capture Module Stop in Idle Control(0=Input capture module will continue to operate in CPU Idle mode)
IC3CONbits.ICM= 0b011; // Input Capture Mode Select (Every rising edge)
IC3CONbits.ICBNE=0; // Input Capture Buffer Empty Status (Read Only)
IC3CONbits.ICOV=0; // Input Capture Overflow Status Flag (Read Only)
IC3CONbits.ICI= 00; // Select Number of Captures per Interrupt bits (00 = Interrupt on every capture event)
IC3CONbits.ICTMR=0; // Input Capture Timer Select bits 0=TMR3 contents are captured on captured event)
IC3CONbits.ICSIDL=0; // Input Capture Module Stop in Idle Control(0=Input capture module will continue to operate in CPU Idle mode)
IPC1bits.IC2IP = 5;
// Register 6-6: IFS1: Interrupt Flag Status Register 1
IFS0bits.IC2IF = 0; // Input Capture Channel 2 Interrupt Flag Status )0=Interrupt bit is cleared
// Register 6-9: IEC1: Interrupt Enable Control Register 1
IEC0bits.IC2IE = 1; // Input Capture Channel 2 Interrupt Enable bit (1 = Interrupt request enabled)
printf("Ic ready\n");
}
void __attribute__((__interrupt__,no_auto_psv)) _IC2Interrupt(void)
{
LSB = IC2BUF;
MSB = IC3BUF;
IFS0bits.IC2IF= 0; //Clear bit IC1IF (IFS<2>)
}
void timer_init(void)
{
T2CON =0; //disable Timer2
TMR2 =0x0000; //Timer2 reg
PR2 =0xFFFF; //PR reg of Timer2
T2CONbits.TSIDL = 0; // configuring timer3
T2CONbits.TCKPS = 0b00; // 1:1 prescaler
T2CONbits.T32 = 1; //Timer2 & Timer3 Configured as 32-bit Timer
T3CON = 0; //desabling timer3
TMR3 = 0X0000; // TIMER3 REGISTER
PR3 = 0xFFFF; // time period
IFS0bits.T3IF = 0; // clear interrupt flag
IPC1bits.T3IP = 7; // set interrupt priority
IEC0bits.T3IE = 1; // interrupt enable
T2CONbits.TON = ON; // enable timer2
T3CONbits.TON = ON; // enable timer3
printf("Timer ready\n");
}
void __attribute__((__interrupt__,no_auto_psv)) _T3Interrupt(void)
{
IFS0bits.T3IF = 0;
}