wynnie1
Newbie level 1
- Joined
- Oct 25, 2012
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,294
Hi everyone i want to create a capture program that uses the capture function of the pic 16f88 the program must capture two incoming signals one at a time the first signal is 20khz
T=50us the second signal is 40khz T=25us ,if the first signal is detected the pin rb2 must be
set if the 40khz signal is detected the rb4 pin must be set, my program does not work
can some one help me ,with the code
thanks in advanced.
Here is my code in mikroc:
unsigned int var,var1;
unsigned int RES1;
void main() {
cmcon=7;
TRISA=0X00;
TRISB=0X08; //MAKE RB3 INPUT for ccp
porta=0;
portb=0;
CCP1CON=0X05;
CCP1IE_bit=1;
CCP1IF_bit=0;
INTCON=0XC0; //global interrupt activated
T1CON=0X01;
do
{
//RES1=var1-var; //the pulse widht will be period2- period
if((RES1 >=20) &&(RES1 <=30)) //this is for a 40 khz signal T=25 us
{
PORTB.RB2=1; //LED FOR 40KHZ SIGNAL
PORTB.RB4=0;
}
if((RES1 >=45) &&(RES1 <=60)) // this is for a 20khz signal T=50 us
{
PORTB.RB2= 0;
PORTB.RB4= 1; //LED FOR THE 20KHZ SIGNAL
}
}
while(1);
}
void interrupt()
{
while(!PIR1.CCP1IF ); // wait for 1st rising edge
var=CCPR1H;
var=(var<<8)+CCPR1L; //read value form ccpr1
PIR1.CCP1IF=0; // reset flag for next interrupt
while( !PIR1.CCP1IF); //wait for second rising edge
var1=CCPR1H;
var1=(var1<<8)+CCPR1L; //read values from ccpr1
PIR1.CCP1IF=0;
CCP1CON=0X00; //RESETS THE CCP MODULE AFTER TWO CAPTURES
RES1=var1-var;
}
T=50us the second signal is 40khz T=25us ,if the first signal is detected the pin rb2 must be
set if the 40khz signal is detected the rb4 pin must be set, my program does not work
can some one help me ,with the code
thanks in advanced.
Here is my code in mikroc:
unsigned int var,var1;
unsigned int RES1;
void main() {
cmcon=7;
TRISA=0X00;
TRISB=0X08; //MAKE RB3 INPUT for ccp
porta=0;
portb=0;
CCP1CON=0X05;
CCP1IE_bit=1;
CCP1IF_bit=0;
INTCON=0XC0; //global interrupt activated
T1CON=0X01;
do
{
//RES1=var1-var; //the pulse widht will be period2- period
if((RES1 >=20) &&(RES1 <=30)) //this is for a 40 khz signal T=25 us
{
PORTB.RB2=1; //LED FOR 40KHZ SIGNAL
PORTB.RB4=0;
}
if((RES1 >=45) &&(RES1 <=60)) // this is for a 20khz signal T=50 us
{
PORTB.RB2= 0;
PORTB.RB4= 1; //LED FOR THE 20KHZ SIGNAL
}
}
while(1);
}
void interrupt()
{
while(!PIR1.CCP1IF ); // wait for 1st rising edge
var=CCPR1H;
var=(var<<8)+CCPR1L; //read value form ccpr1
PIR1.CCP1IF=0; // reset flag for next interrupt
while( !PIR1.CCP1IF); //wait for second rising edge
var1=CCPR1H;
var1=(var1<<8)+CCPR1L; //read values from ccpr1
PIR1.CCP1IF=0;
CCP1CON=0X00; //RESETS THE CCP MODULE AFTER TWO CAPTURES
RES1=var1-var;
}