PDA

View Full Version : Capture



SlotH
- 17th May 2005, 22:34
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 :)

Dwayne
- 18th May 2005, 17:09
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

SlotH
- 18th May 2005, 18:09
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

Acetronics2
- 18th May 2005, 18:36
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

G8RPI
- 18th May 2005, 18:42
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

SlotH
- 18th May 2005, 19:17
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.