Capture woes...


Closed Thread
Results 1 to 10 of 10

Thread: Capture woes...

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Capture woes...

    Lets look at this and see what its doing:
    Code:
    INTCON = 0 ' Interrupts off
     
     
    CCP1CON = %00000101 ' Capture mode, capture on rising edge
    T1CON = 0 ' TMR1 prescale=4, clock=Fosc/4, TMR1=off
    T1CON.4 = 0 
    T1CON.5 = 1
     
    CLEAR
     
    Reload: 
    TMR1H = 0 ' Clear high byte of TMR1 counter
    TMR1L = 0 ' Clear low byte
    T1CON.0 = 1 ' Turn TMR1 on here 'here you turn on the timer, but at what state is your signal?
     
    Next you wait for capture flag, but again, if the flag sets on rising edge (or falling) but 
    you started in the middle of a "high", you will stop when 75% of the cycle is done.
     
     
    Capture = 0 ' Clear capture int flag bit
    While !Capture ' Wait here until capture on rising edge 
    Wend
     
    T1CON.0 = 0 ' Turn TMR1 off here
     
    ' Rising edge detected / stuff 'captured' Timer1 value in T1
    T1.HighByte = CCPR1H ' I don't understand why you replace T1 count with CCPR1
    T1.LowByte = CCPR1L  'T1 has the counts you are comparing in your spreadsheet
     
    DEBUG #T1,13,10
     
    GOTO ReLoad
    You need to wait for a rasing edge before you start the counter, then on next rising edge, stop and get the counts. Or even better, set a word = to count, after you turn the timer off. then reset it and turn it back on. Right now you don't turn it back on until after you have sent data out. You are missing a portion of your signal this way.

    HTH
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Capture woes...

    Bert, thanks for the insight.

    I'm still trying to wrap my brain around what you suggested. Are you saying the Debug might be affecting the captured value?

    Sorry I'm being so dense here.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Capture woes...

    Last edited by mister_e; - 21st May 2011 at 10:21. Reason: Microchip's CCP Tips& Trick pdf
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Capture woes...

    Steve, thanks for that pointer. Things are very well explained indeed. Clarified some things, but am still not out of the woods yet.

    Is my understanding correct here?

    Slowest speed to be measured is 300 rpm. That is 5 Hz.
    Maximum time to be measured between consecutive high going edges is therefore 200,000 us.
    Therefore, T1, set to a prescaler of 1:4 should read 50,000 for a frequency of 5 Hz?

    This is at clock frequency of 4 MHz, Capture configured to increment every rising edge.

  5. #5
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Capture woes...

    Okay, finally got it working. Used the Melabs example at http://melabs.com/samples/LABX2-16F877A/ccpx2.htm and things are working precisely as expected.

    Thanks, guys!

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts