afnan.bashir
Member
I am trying to measure the time difference between the rising or the falling edge of two square waves, that i get from the Zero Crossing Detectors.
I am trying to measure phase difference between Current and Voltages of an A.C. Circuit. Getting two inputs from Voltage and Potential transformers.
Someone told me to use CCP to measure the time but that can measure time difference between the events from input on single pin.
But I have two inputs from C.T. and P.T.
I have to measure the power factor of A.C. Circuit, but not finding a proper way to do that.
I tried this but not getting the correct output
void main() {
//Let the Module start up
Wait(500);
LCDInit(LS_CURSOR_OFF);
LCDClear();
LCDClear();
///******************** PORT Initilization **********************************
PORTD = 0X00;
TRISD = 0X00;
while (1) {
time=0;
LCDWriteStringXY(0,2,"Frequency:=");
if(PORTCbits.RC6 == 1)
{
while(PORTCbits.RC7 != 1){
time = time+1;
Delay_us(1);
RD0 = ~RD0; // Toggle RA0 pin
}
LCDWriteIntXY(6,0,cos(time*0.9),3);
}
Delay_ms(50);
/*OPTION_REG = 0b00101000; // TOCS=1 for Counter mode, PSA=1 for 1:1 prescaler
// Display Frequency
TMR0=0;
Delay_ms(1000);
LCDWriteStringXY(0,0,"Frequency:=");
LCDWriteIntXY(12,0,TMR0,2);
LCDWriteStringXY(14,0,"Hz");
////////////////////////////////////*/
}
}
I am trying to measure phase difference between Current and Voltages of an A.C. Circuit. Getting two inputs from Voltage and Potential transformers.
Someone told me to use CCP to measure the time but that can measure time difference between the events from input on single pin.
But I have two inputs from C.T. and P.T.
I have to measure the power factor of A.C. Circuit, but not finding a proper way to do that.
I tried this but not getting the correct output
void main() {
//Let the Module start up
Wait(500);
LCDInit(LS_CURSOR_OFF);
LCDClear();
LCDClear();
///******************** PORT Initilization **********************************
PORTD = 0X00;
TRISD = 0X00;
while (1) {
time=0;
LCDWriteStringXY(0,2,"Frequency:=");
if(PORTCbits.RC6 == 1)
{
while(PORTCbits.RC7 != 1){
time = time+1;
Delay_us(1);
RD0 = ~RD0; // Toggle RA0 pin
}
LCDWriteIntXY(6,0,cos(time*0.9),3);
}
Delay_ms(50);
/*OPTION_REG = 0b00101000; // TOCS=1 for Counter mode, PSA=1 for 1:1 prescaler
// Display Frequency
TMR0=0;
Delay_ms(1000);
LCDWriteStringXY(0,0,"Frequency:=");
LCDWriteIntXY(12,0,TMR0,2);
LCDWriteStringXY(14,0,"Hz");
////////////////////////////////////*/
}
}
Last edited: