Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

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

Status
Not open for further replies.

ennng

Junior Member level 2
Joined
Nov 1, 2012
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,420
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){ 
     x=adc_read(0); 
     y=adc_read(1); 
     if(adc_read(0)==0)while(adc_read(1)>0){time++; delay_ms(1)}
        {portc=time;}

      }


  }
 

emresel

Full Member level 5
Joined
Feb 12, 2008
Messages
262
Helped
61
Reputation
122
Reaction score
60
Trophy points
1,308
Location
Turkiye
Activity points
2,828
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
Joined
Nov 1, 2012
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,420
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top