Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 7th March 2008, 06:54 PM   #1
Default Can CCP do this on 16F876A? :(

Hello friends,

I am stuck with a problem and will kindly appreciate any help on this.

I have got two TTL signals ranging from 500 Hz to 10kHz. I am trying to measure the delay of one with reference to other. As the signals can be of any frequency I am not sure how to use CCP for this task. I have searched a few topics on here but couldn't find anything appropriate.

I am a newbie and wold really appreciate any help.

Thank you all in advance

bjox
bjox1 is offline  
Old 7th March 2008, 08:07 PM   #2
Default

Presumably the two frequencies are identical?, otherwise it wouldn't be possible.

If you XOR the signals together, this will give you a pulse representing the phase difference between them.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th March 2008, 03:43 AM   #3
Default

Hi Nigel,

Thank you for the reply.

Quote:
Originally Posted by Nigel Goodwin
Presumably the two frequencies are identical?, otherwise it wouldn't be possible.
I am sorry for not providing enough info. YES, the two signals at any given time will have the same frequencies.

Quote:
If you XOR the signals together, this will give you a pulse representing the phase difference between them.
I am very thankful to you for giving this idea but would really appreciate if you could explain it in a bit more detail. Probably if there's a circuit to look at?? For instance, what will be the output from an XOR and what will be the input to my PIC?? And finally what method I will have to use to get the phase difference in the PIC? [I apologise if I ask too much]


Thanks in advance Nigel.

-I am pretty much new to the electronics

Last edited by bjox1; 8th March 2008 at 03:45 AM.
bjox1 is offline  
Old 8th March 2008, 04:24 AM   #4
Default

Have a read of this thread. For some reason the OP has deleted his initial question but he basically wanted to find the phase difference between two signals.

Mike.
Pommie is online now  
Old 8th March 2008, 08:10 AM   #5
Default

Hey Pommie,
Thanks for the thread. I had a look at it and it seems a gr8 technique. The only concern is whether I could measure the phase at different freq??

I mean will it work if the signals are at 9.9kHz or in the second case if the signals are at 990Hz?? Please enlighten me!

Thanks.
bjox1 is offline  
Old 8th March 2008, 09:21 AM   #6
Default

If you use a 20MHz crystal then you will be able to measure 2μS periods. It really depends how accurate you want it.

Mike.

Last edited by Pommie; 8th March 2008 at 09:49 AM.
Pommie is online now  
Old 8th March 2008, 09:28 AM   #7
Default

Quote:
Originally Posted by bjox1
I am very thankful to you for giving this idea but would really appreciate if you could explain it in a bit more detail. Probably if there's a circuit to look at?? For instance, what will be the output from an XOR and what will be the input to my PIC?? And finally what method I will have to use to get the phase difference in the PIC? [I apologise if I ask too much]
Draw yourself some little diagrams and work it out, it will help you understand it.

All you need to know is that an XOR gate sets the output HIGH, when the two inputs are DIFFERENT, if the two inputs are the same, them the output is LOW.

So get a sheet of graph paper, draw your two input waves on it above each other, then follow the rules above to draw the output waveform below them. Do this for various phase differences, this should make it all clear.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th March 2008, 01:14 PM   #8
Default

Hi Pommie and Nigel,

Quote:
If you use a 20MHz crystal then you will be able to measure 2μS periods. It really depends how accurate you want it.
I was looking for something with a very high accuracy. I mean I calculated [ and I saw some of ur replies to the same OP] and :
For 1kHz signals- 10us*100 is 1ms i.e. 100 is the max value therefore 3.6 deg for every counter.
& for example for 10kHz signals- 10us*10 will be 100us i.e. 36 deg for every counter.
So I was wondering if I could eliminate this error or probably a technique which is independent of the signal frequency?

Hi Nigel,

I am sorry for asking this again but I am kind of struggling in analysing the XOR technique [probably because Im in my first year ]. If you see the diagram I have attached, if the second signal is say 50 deg lag, and if I feed these two signals to XOR gate, then one signal will be high and the other will be low and the output from XOR will be high all the time. I don't know how can I find the phase difference from there?

I apologise if I ask a bit too much basics.

Thanks again.
Attached Thumbnails
Can CCP do this on 16F876A? :(-diagram.jpg  

Last edited by bjox1; 8th March 2008 at 01:17 PM.
bjox1 is offline  
Old 8th March 2008, 03:47 PM   #9
Default

Your diagram clearly shows a time when one is HIGH and one is LOW, when both are HIGH, and when both are LOW, bear in mind to have a phase difference you can measure both waves must be exactly the same frequency.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th March 2008, 04:03 PM   #10
Default

Quote:
Originally Posted by Nigel Goodwin
Your diagram clearly shows a time when one is HIGH and one is LOW, when both are HIGH, and when both are LOW, bear in mind to have a phase difference you can measure both waves must be exactly the same frequency.
Mate I am so sorry but I don't understand what to do with the output.

I am so so sorry but please enlighten me. I think my brain hates me!

Thanks Nigel.
bjox1 is offline  
Old 8th March 2008, 04:34 PM   #11
Default

Like I said, draw a diagram - it's easy - heres an example, top two are the two input waveforms, bottom one the output from an XOR. The bottom waveform is a direct representation of the phase difference.
Attached Thumbnails
Can CCP do this on 16F876A? :(-phase.gif  
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th March 2008, 07:25 PM   #12
Default

Quote:
Originally Posted by Nigel Goodwin
Like I said, draw a diagram - it's easy - heres an example, top two are the two input waveforms, bottom one the output from an XOR. The bottom waveform is a direct representation of the phase difference.
Dear Nigel,
I am so so thankful to you for explaining this to me in such a detail.

As u have suggested me to draw a few cases, I have attached a diagram where I have assumed two cases of delayed signal [named as signal2]. As far as I could imagine [I might be wrong] that if we take a reference point on signal [signal1] on the rising edge of the pulse, the delay signal will possibly have the two cases:
1) if signal2 arrives as low = that means 0-180 deg delay &
2) if signal2 arrives as high = that means the delay signal [signal2]has
crossed the 0-180 deg of delay range and now
it's in 180-360 deg range.

In the attached diagram, I have taken two such cases, one for 10 deg delay and second one is for 350 deg delay and I have found out that the output pulse from XOR gate has the same pulse width.
Now that implies that for any delay value [in deg] between 0-180 [say 'x'] will have the same value for the signal with a delay of 360-x deg[ In my case,10 deg will be same as 360-10 =350 deg]. I am all confused about how to calculate the phase on these cases??

I apologise Nigel if I have over thought it but I would really appreciate any further help on this matter.

Thank you soo soo much .

Ps: I apologise if the diagrams are not upto the scale.
Attached Thumbnails
Can CCP do this on 16F876A? :(-diagram1.jpg  

Last edited by bjox1; 8th March 2008 at 07:36 PM.
bjox1 is offline  
Old 8th March 2008, 08:34 PM   #13
Default

You are correct, 10 degrees and 350 degrees will read the same, because they are the same - are you needing to know which leads or lags as well?.

Perhaps you might try telling us exactly what you are trying to do?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th March 2008, 11:32 PM   #14
Default

Quote:
Originally Posted by Nigel Goodwin
You are correct, 10 degrees and 350 degrees will read the same,
Perhaps you might try telling us exactly what you are trying to do?.
Hi Nigel,
Sorry about the late reply.

Well I am at Uni [first year] and this task is a part of our module. There are a few circuits given by technician which introduce delay [0-360 deg].

So we have same signals [same freq at a given time] but one is ref and the other signal goes through these circuits which introduce resp delay. As I mentioned earlier, I have to measure the phase diff but the freq can range from 500Hz to 10kHz.
Quote:
because they are the same - are you needing to know which leads or lags as well?.
Well, I have to measure the delay of signal2 with repect to signal1. Hence my reference point is signal1. I hope this might give you a rough idea! I apologise again for being so stupid.

Is it still possible to achieve 0-360 phase measurement using XOR technique??

Thanks once again Nigel.

Last edited by bjox1; 8th March 2008 at 11:38 PM.
bjox1 is offline  
Old 9th March 2008, 12:17 PM   #15
Default

As the signal always lags, detect the start of the reference pulse, then start counting while you wait for the start of the following pulse.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply

Tags
ccp

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
CCP (compare mode) crys Robotics Chat 3 17th February 2008 12:33 PM
stepper motor with 16f876a jay543_uk Micro Controllers 10 8th February 2008 09:05 PM
Pic 16f876a Prog. Problem JEFFxxx Micro Controllers 9 5th October 2006 10:45 PM
16F876A YAN-1 Micro Controllers 1 14th December 2005 09:56 AM
PWM module in the 16F876A YAN-1 Micro Controllers 3 23rd May 2005 01:08 AM



All times are GMT. The time now is 03:29 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker