I am trying to measure the phase shift between two signals that have the same frequency.
I want use two channels of ADC and then use a counter to count if the first signal reach zero and the counter stop when the second signal hit the zero and then measure this time with give the phase difference. Any help please.
Code:
int i;
int time;
signed flot x;
signed flot y;
void main(){
TRISA=1; TRISB=0;
PORTB=0;
TRISC=0;
PORTC=0;
time=0;
while(1){
x=adc_read(0);
y=adc_read(1);
if(adc_read(0)==0)while(adc_read(1)>0){time++; delay_ms(1)}
{portc=time;}
}
}
Hi,
If i were you, first build simple zero cross cct like in this, then feed the outputs of the detectors to gpios and measure the time between two rising edges. Many micros has port change or edge triggered interrupts. To measure time you can use timers. In your code, "time" variable will be a portion of the actual time.
By the way to use ADCs you need to offset/bias sine waves. If you don't bias probably you will read zero during negative cycle.
Thank you emresel ;
as you said using two channels for different comparators, and using interrupt when the first output goes high and then start the time and when the second output goes high stop the timer.
I would use ADC instead of using comparators is there any idea or code to help. Thanks.