+ Reply to Thread
Page 2 of 5
First 1 2 3 4 5 Last
Results 16 to 30 of 74

Thread: Can CCP do this on 16F876A? :(

  1. #16
    bjox1 Newbie
    Join Date
    Mar 2008
    Location
    UK
    Posts
    38

    Default

    Hi Nigel,
    Thanks for the reply.
    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.
    Will I still need an XOR gate for this?? I mean I can just wait for signal1 to get high, start counting till I get next rising edge on signal2 [exactly what Pommie did in the previous post].

    Thanks again Nigel.

    <EDIT>
    Nigel,
    I have found this diagram from a website [attached]. The only other way to find the phase diff of 180+ is that if you look at the signal2 or RX signal waveform and XOR output waveform together [in the diagram], for the phase diff between 0-180, when the signal2 [delay signal] rises, the XOR output is low. For example, for the case of 45 deg, as the signal2 rises, the XOR output is low and for 315 deg, as the signal2 rises, the XOR is high.

    Am I right in assumin that if I use a bit test for this case, I can fix the problem??
    Lastly,if we feed the XOR output to PIC, will I be using counter to find the width of the signal?? If so then wouldn't the counter value be varied? I mean say for 45 deg of phase diff [for 1000Hz signals] the counter will give 'x' value and for the same phase diff [now for 10 kHz signal] the counter will give less than 'x' value?? So if I read the counter value on the output, I will not b getting the same 45 deg value!

    I am so so sorry I sound a bit annoying but I need your kind help on this matter.

    Thanks again for your time Nigel.
    Attached Images
    Last edited by bjox1; 9th March 2008 at 01:07 PM.


  2. #17
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,778

    Default

    If you're using different frquencies you need to measure both the HIGH period and the LOW period, the phase difference is the ratio between them.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  3. #18
    bjox1 Newbie
    Join Date
    Mar 2008
    Location
    UK
    Posts
    38

    Default

    Quote Originally Posted by Nigel Goodwin
    If you're using different frquencies you need to measure both the HIGH period and the LOW period, the phase difference is the ratio between them.
    Sorry Nigel, I am finding very hard to analyse ur solution . Please enlighten me.

    If you're using different frequencies
    I may have explained it wrongly. That’s the whole task:
    1) User will choose any frequency from 500 Hz to 10kHz.
    2) Then same frequency signal will be tap down to TWO signals. One will be the reference and the other will go through this unknown delay circuit.
    3) My aim will be to find the value of the phase difference hence determining the unknown circuit [phase value].

    I am sorry for not explaining it clearly.

    Awaiting ur reply Nigel.
    Thanks again.

  4. #19
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,798

    Default

    Do you need to calculate time difference or angular difference? I.E. 2mS or 2°.

    Mike.

  5. #20
    bjox1 Newbie
    Join Date
    Mar 2008
    Location
    UK
    Posts
    38

    Default

    Quote Originally Posted by Pommie
    Do you need to calculate time difference or angular difference? I.E. 2mS or 2°.

    Mike.
    Hey Mikey,
    That's a very nice question.

    Well I am expected to show the value at the output pin of my PIC. may be using LED [8 bits]. I think output as the angular difference will help me in this.

    <edit>
    Pommie, Can u suggest me any technique for measuring the pulse width using PIC?? [In my case, the output of XOR gate i.e. the ON time of the pulse]

    Thanks again.
    Last edited by bjox1; 9th March 2008 at 05:28 PM.

  6. #21
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,778

    Default

    Quote Originally Posted by bjox1
    Sorry Nigel, I am finding very hard to analyse ur solution . Please enlighten me.



    I may have explained it wrongly. That’s the whole task:
    1) User will choose any frequency from 500 Hz to 10kHz.
    2) Then same frequency signal will be tap down to TWO signals. One will be the reference and the other will go through this unknown delay circuit.
    3) My aim will be to find the value of the phase difference hence determining the unknown circuit [phase value].
    I understood you before, but as you will be using different frequencies the absolute time of the high pulse doesn't provide you enough information, you need to know the time of the low pulse as well, so you can calculate the lag in degrees. Knowing the frequency would do the same thing, and by measuring both high and low, you are in effect measuring the frequency.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  7. #22
    bjox1 Newbie
    Join Date
    Mar 2008
    Location
    UK
    Posts
    38

    Default

    Guys I need ur valuable guidance in this case. I was wondering if it is at all possible to compare the XOR output to the constant PIC clock??

    What I am trying to do is input the XOR waveform into PIC and run 4MHz clock with it. Thus a 4MHz clock will be constant irrespective of the input waveform. If I compare both waveforms and get the time difference [pulse width], I might achieve the task.

    For instance, if the two signals are of 10kHz freq i.e. 277.7 nsec will represent 1 deg of difference. That is, the XOR pulse width representing 1 deg [ON time of pulse], which in freq is 3.6 MHz. Now if I compare it to the constant running 4MHz clock, I can get the time difference which is the phase.

    For the other case if the signals are now at 1kHz freq, i.e. 2.77 us will represent the smallest 1 deg difference. So the XOR pulse width representing 1 deg in freq will be 360 kHz. Again comparing it to the same constant 4MHz PIC clock can give us the difference.

    I honestly have no idea and I may be wrong in assuming all this. The advantage will be that the comparison will always be with a 4MHz crystal, independent of the signal frequency.

    I will greatly appreciate if you could help me implementing this solution [if you think it's at all possible to achieve].

    I will appreciate any suggestions on this.

  8. #23
    bjox1 Newbie
    Join Date
    Mar 2008
    Location
    UK
    Posts
    38

    Default

    Could anyone please please help me out on this.

    Thanks!

  9. #24
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,778

    Default

    Check the spec on the CCP module, you certainly can't get 277nS resolution with a 4MHz clock.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  10. #25
    Super_voip Newbie
    Join Date
    Jul 2007
    Location
    Brisbane, Australia
    Posts
    340

    Default

    Sounds like a job for a PLL (Phase Locked Loop) using the reference signal the PLL will output a signal proportional to the phase error. PLL are used in things like instrument tuners, indicating whether a played note is higher or lower than the reference.

  11. #26
    bjox1 Newbie
    Join Date
    Mar 2008
    Location
    UK
    Posts
    38

    Default

    Quote Originally Posted by Nigel Goodwin
    Check the spec on the CCP module, you certainly can't get 277nS resolution with a 4MHz clock.
    Nigel,
    Mate if I use a 20MHz XT?? Is it possible to do it in this way?? if so then how can I implement in a code?

    I will really really appreciate that mate.

    Thanks again for ur time.

    PS:
    Quote Originally Posted by Nigel Goodwin
    If you're using different frquencies you need to measure both the HIGH period and the LOW period, the phase difference is the ratio between them.
    Nigel,

    Could you explain this once again ?or probably how I can write it in code.

    Cheers


    Sounds like a job for a PLL (Phase Locked Loop) using the reference signal the PLL will output a signal proportional to the phase error. PLL are used in things like instrument tuners, indicating whether a played note is higher or lower than the reference.
    Hi,
    PLL outputs a current signal. I am not sure how to input it to my PIC for finding a phase.
    Last edited by bjox1; 10th March 2008 at 11:00 PM.

  12. #27
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,778

    Default

    Quote Originally Posted by bjox1
    Nigel,
    Mate if I use a 20MHz XT?? Is it possible to do it in this way?? if so then how can I implement in a code?
    Running the PIC at 20MHz, the CCP module should have 200n resolution, use that to measure the width of the pulse from an XOR gate.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  13. #28
    mike50 Okay
    Join Date
    Jun 2007
    Location
    Rochester, Minnesota
    Posts
    102

    Default

    The 16F876 has two CCP modules. Why not use one module to Capture the leading edge of one of the signals and the other module to Capture the leading edge of the other. Then you don't need any external XOR function; you can compute the frequency and the phase directly with the 200 ns resolution.

    Mike

  14. #29
    bjox1 Newbie
    Join Date
    Mar 2008
    Location
    UK
    Posts
    38

    Default

    Quote Originally Posted by mike50
    The 16F876 has two CCP modules. Why not use one module to Capture the leading edge of one of the signals and the other module to Capture the leading edge of the other. Then you don't need any external XOR function; you can compute the frequency and the phase directly with the 200 ns resolution.

    Mike
    Mike,

    Mate it sounds perfect but I haven't got that much experience in writing this sort of code. I have done a few LED blinking codes and can attempt this CCP if I get a little bit of help.

    you can compute the frequency and the phase directly with the 200 ns resolution.
    Mike, Sorry for being so slow but could you check my following steps:

    1) Configure CCP [capture] for the reference signal.
    2)Configure CCP for the delay signal.

    But what do I have to write in my code to get the phase value which will be independent of the signal frequency??

    I would appreciate any help on this.

    Thanks in advance.
    Last edited by bjox1; 11th March 2008 at 11:18 PM.

  15. #30
    bjox1 Newbie
    Join Date
    Mar 2008
    Location
    UK
    Posts
    38

    Default

    Anyone up for the kind help??


    Ps:

    Heyy guys,

    I found this nice document[attached with this post] for measuring the width of a signal [in my case, XOR output]. I will be grateful if you could help me in writing the steps described in the document.


    Many many thanks guys.

    <edit>
    Please please help me out on this...
    Attached Images
    Last edited by bjox1; 12th March 2008 at 04:30 PM.

+ Reply to Thread
Page 2 of 5
First 1 2 3 4 5 Last

Similar Threads

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

Tags for this Thread