Capture


Closed Thread
Results 1 to 6 of 6

Thread: Capture

  1. #1
    SlotH's Avatar
    SlotH Guest

    Default Capture

    Hi, I'm having some trouble reading rotations per minute (RPM) and I was wondering if somone has an example on a capture code. I want it to read the time between 2 pulses in seconds and get the result divided by 60 (seconds per minute).
    Anyway, that was my plan, If someone has a better one please tell me

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Sloth,

    Sloth>>Hi, I'm having some trouble reading rotations per minute (RPM) and I was wondering if somone has an example on a capture code. I want it to read the time between 2 pulses in seconds and get the result divided by 60 (seconds per minute). <<

    There are a couple of problems with your question...

    1. What are you trying to read??? RPM of a Car engine?
    2. What chip are you using?
    3. Do you have example Code?
    4. A more detailed explanaition is MUCH better.


    I am going to assume that you are measuring something like a car motor, or something that gives you "Pulses" for each revolution.

    First, there is a Pulsein command

    Pulsein PinX, 0, Lengthofpulse.
    Pulsein PinX, 1, Lengthofpulse.

    Both of these statements measure the width of a pulse... whether that pulse is high or low...

    With Lengthofpulse, you can calculate your RPM, RPS (per second) or whatever.

    If you have a 4 mhz chrystal, (or use a internal clock) your Lengthofpulse will be in 10us increments. that is 1/100,000 of a second.

    Thus a return of 1500 will mean 15,000us, which is 15/1000 of a second. Which equates to 67 RPS or 4020 RPM.

    Now, if I didn't error on my math (which happens) your project may look something like the above. But please give a more detailed description...We are totally clueless on what you want.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    SlotH's Avatar
    SlotH Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, maybe my question was i little blurry, I'm using a PIC16F877a (20mhz) to build a speedometer, exhaust temperature, clock and a device for reading the RPM. I have a device that sends a pulse of +5V per revolution.

    I've read somewhere that the pulsin isn't as accurate as the CCP module, so I thought it would be best to use it therefor.

    Is this formula correct?

    RPM = 60/(time per rev in seconds)

    0,12s < time per rev < 0.006s
    Assuming that the lowest RPM = 500 and the highest 10000
    Last edited by SlotH; - 18th May 2005 at 21:12.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,617


    Did you find this post helpful? Yes | No

    Default

    Hi, slot

    If your processor runs @ 20 Mhz ... the pulsin step is 2µS ...with 16 bits of count

    you want to measure from 0.006 to 0.12 s ...

    65535 * 2µS = 0.131070s ... ok for lo speed
    3000 * 2µS = 0.006 s .... ok for hi speed

    so, the max error is 1/ 3000 counts ...

    is this enough for you ...and do not forget you will have to read something stable ...a mean value over 100 samples will give you 0.6s between each result.

    seems correct with pulsin !!!

    ... except if you want to count AND run calculations at the same time. The CCP module will there be compulsory ...

    Alain

  5. #5
    G8RPI's Avatar
    G8RPI Guest


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Your fomula is correct. Pulsein works well for slower speed signals (6ms is slow) at 500RPM you would have to count 20 pulses for 5% (25RPM) resolution This would take 2.4 seconds between readings or 1.2 s for 50RPM resolution. Measuring the period takes only 0.12s with the full 16bit (0.15RPM) resolution of pulsein.
    Below is some code I wrote as part as a gas turbine (jet) engine controller.
    Pulsein_max colud de reduced to 15000 (0.15 seconds) for your 500RPM lower limit. This stops the program waiting for a pulse (default is 65 seconds) when the engine is not turning.
    HTH,
    Robert G8RPI.

    'Start sequencer for gas turbine engines
    'PIC16F877, XT, 4MHz
    'Robert Atkinson G8RPI 29/01/03

    'INPUTS------------------------------------------------------------

    'HP Tacho input 70Hz = 100%

    HPTACH VAR PORTB.0 'HP TACHOMETER INPUT
    DEFINE PULSIN_MAX 41000 ' LIMIT MAXIMUM COUNT TIME TO 0.41S



    'VARIABLES-----------------------------------------
    HPRPM VAR WORD 'PERCENT HP RPM

    HPPW VAR WORD 'ACTUAL PULSE WIDTH HP TACHO

    '************************************************* *****************************

    GOTO MAIN 'JUMP PAST SUBROUTINES


    HPRPMCAP: 'RPM CAPTURE MODULE


    PULSIN HPTACH, 1, HPPW

    HPRPM = 35700 / (HPPW / 2) 'CALCULATION OF PERCENT BASED ON 2 POLE 4200 RPM = 100%
    '35700 USED DUE TO 16 BIT MATH LIMIT
    IF HPPW <400 OR HPPW >40000 THEN 'TRAP UNDER AND OVER PULSE WIDTHS
    HPRPM = 0
    ENDIF

  6. #6
    SlotH's Avatar
    SlotH Guest


    Did you find this post helpful? Yes | No

    Default

    I think I will have to stick to my first idea, in other words CCP.
    Found a great example :
    http://picbasic.com/resources/samples/x2/pbp/ccpx2.bas
    But I'm not really sure how it works and how do you divide #period with 60 ? I assume that the period i messured in seconds.
    *edit* Thanks for the great support, I feel a little dumb asking these questions.

Similar Threads

  1. mS Timer
    By whmeade10 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th September 2020, 12:12
  2. Using hardware capture
    By Bruce in forum Code Examples
    Replies: 14
    Last Post: - 25th March 2012, 05:52
  3. Using CCP1 and CCP2 to measure instant fuel consumption
    By srspinho in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 20th September 2008, 15:50
  4. Measuring change of frequency with PIC
    By Aussie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 01:47
  5. continious counting process (capture)
    By asynch in forum General
    Replies: 1
    Last Post: - 17th February 2006, 07:42

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