CCP question


Closed Thread
Results 1 to 2 of 2

Thread: CCP question

  1. #1
    Join Date
    Aug 2005
    Posts
    44

    Default CCP question

    Hi all.

    Im working on a tachometer project, that uses an input from a trigger wheel on an engine, to measure rpm.

    The pulses from the trigger wheel are fed into an LM1815 IC, which basically is a zero crossing detector and outputs a 50-70uS positive pulse at each zero cross.
    The trigger wheel has 36 teeth, therefore 36 pulses per engine revolution.

    My picbasic code for 16F628A uses the CCP1, with a 1:1 prescale and counting 16 rising edges, pic is running at 4mhz.

    Basically im measuring the time for 16 teeth on the wheel (which is aprox 0.4 revolutions of the engine) and working out the RPM based on this time.

    This works fine up until around 4000 rpm, then it gets unstable - as in the results i get from the pic output fluctuate quite randomly.

    I've basically worked out that at 4000 rpm there is approx 2400 pulses per second on the ccp pin and at 6000 rpm there is approx 3600 pulses per sec (0.27 msec between them?).

    This means at 4000 rpm, the ccp event fires 150 times / sec and at 6000rpm around 225 times / sec (every 4.4msec)

    Would the unstability be caused by a limitation of the CCP part of the pic or would it be due to the code taking too long to execute, causing discrepancies in the timer?

    below is a snippet of my code, minus the rpm calculations and minus the various outputs that are triggered at various rpm. See the last few lines where the %%%%% are.... i think the execution time of these lines may contribute to the cause?

    Code:
    
    TRISA = %00100000			' Port A all output but MCLR
    TRISB = %00001010			' Port B all output but 1,3 (Si and CCP)
    
    T1CON = %00000001			' TMR1 1:1 prescale , and turn it on
    CCP1CON = %00000111			' Enable the CCP1 capture, 16th rising edge
    
    
    
    startloop:
    
    IF (capture = 0) Then loop	' Wait here until captured 
    
    period.lowbyte = CCPR1L		' Store the captured value in
    period.highbyte = CCPR1H	' period variable
    
    IF overflow = 1 then		' Skip the output if the timer overflowed
    capture = 0			' Clear capture flag
    overflow = 0			' Clear overflow flag
    goto reset
    EndIF
    
    
    ***** RPM calcs get done here (i've left them out) *******
    
    
    
    SerOut So, N9600, [#rpm,13,10]	
    EndIF
    
    capture = 0			'Reset capture flag to wait for next period
    period = 0
    rpm = 0
    
    Reset: 
    IF (capture = 0) Then reset	 	' Wait here until next period captured 
    TMR1H = 0				' Clear Timer1 high register   %%%%%	
    TMR1L = 0				' Clear Timer1 low register    %%%%%
    capture = 0				' Clear capture flag           %%%%%
    overflow = 0				' Clear overflow flag          %%%%%
    
    GoTo startloop				' Do it forever

  2. #2
    G8RPI's Avatar
    G8RPI Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Jamie,
    There should be no problem with the CCP hardware, it can run up to a few hundred KHz. Your code looks OK too. Have you put 'scope on the output of the LM1815? I'd suspect this first. You could also try connecting a signal generator to the PIC in place of the engine/sensor/LM1815/ combination.
    It is possible that you are getting interference from the engine at higher speeds that is not connected to your RPM signal.
    You don't say how you have configured the LM1815, this could also be the problem.
    Get your circuit running on the bench with a signal generator (another PIC will do the job) first. It's safer than by the engine, and you can hear yourself think!

    Robert G8RPI.

Similar Threads

  1. Capture without CCP
    By boroko in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th March 2009, 23:09
  2. CCp module question.
    By robert0 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd January 2007, 00:28
  3. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  4. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  5. Timer / CCP Question
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd November 2005, 08:22

Members who have read this thread : 1

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