CCP Module to measure frequency change.

Discussion in 'Embedded Systems and Microcontrollers' started by Neyolight, Mar 25, 2012.

  1. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Hi All

    I want to use CCP Module to measure the frequency of the signal coming at RC2(CCP1 pin). This frequency will change and I want to measure the change as it happens.

    I have my code attached for you all to give me some suggestion as to where I am going wrong.

    Right now,the output I get is in 16000, which is way more than expected 65.

    Please HELP ! Im terribly lost !

    Here is my code.

    I am using PIC18F4620 on PICDEM2 plus board.
     
    Last edited: Apr 23, 2012
  2. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Can anyone PLEASE look at my code and point out mistakes? I still cannot get it to work. My CCP data register increments with Timer 1 and I'm not sure why.

    Also, the CCP interrupt flag cannot be cleared once its set.

    PLEASE HELP !
     
  3. Motardo

    New Member

    Sep 21, 2011
    20
    2
    It sounds like the CCP is getting triggered every clock cycle. What is connected to the RC2/CCP1 pin? Make sure you have a bypass capacitor at the PICs VDD and VSS, and maybe try another bypass cap on the CCP1 pin. BTW you're code is reporting the period, not the frequency of the signal.
     
  4. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Thanks for the reply. I have the PIC on a PICDEM 2 Plus board , so cant really add or remove component.

    Yup, I am trying to get T first.

    Why is CCP1 incrementing with clock ? :confused:
     
  5. Motardo

    New Member

    Sep 21, 2011
    20
    2
    I'd guess noise. Either it's unconnected (floating inputs will oscillate), or its connecting wire is too long or too close to other circuitry? What are you using to drive the CCP1 pin?
     
  6. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    I have a square wave of frequency 122 Khz and amplitude 3.8 V at CCP1.
     
  7. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Whats a floating input? I have the signal coming from a circuit on breadboard at CCP1. The wire that connects CCP1 to breadboard is about 30cm in length.


    How do I make it work ?
     
  8. Motardo

    New Member

    Sep 21, 2011
    20
    2
    The CCP input is a schmitt trigger with low/high thresholds 0.2 and 0.8 of VDD, so if your dev board is running at 5 V, the 3.8 V signal isn't high enough. What happens if you just ground the CCP pin? If it stops triggering and setting the interrupt flag every cycle, then the software is probably ok (meaning it's a hardware problem). You have a ground connection from the breadboard to the dev board? Try other frequency inputs and see if the behavior changes.
     
    Neyolight likes this.
  9. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Thanks for that.:)

    I now have a 4.37 V p-p digital wave going to CCP1 and the results are the same. I have a common ground between the dev board and breadboard.

    I tried grounding CCP1 pin and it does not go into the interrupt routine which suggest there is some hardware issue.

    Now, I have no clue how to figure out what that issue is. It is so easy for others to implement CCP but it has been a torture for me so far :mad:
     
Loading...