Continue to Site

# how to calculate difference between sine wave signals with ADC, MikroC !!!

Status
Not open for further replies.

#### ennng

##### Junior Member level 2
Hi everyone!

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){
{portc=time;}

}

}

#### emresel

##### Full Member level 5
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.

Good luck

#### ennng

##### Junior Member level 2
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.

Status
Not open for further replies.