Shop OBEX P1 Docs P2 Docs Learn Events
RPM reading — Parallax Forums

RPM reading

bennettdanbennettdan Posts: 614
edited 2007-07-05 04:04 in General Discussion
I have looked at the Count instruction and if I wanted to mesure RPM would this work?

Hertz VAR· ·Word
RPM·· VAR·· Word

SCHMITT RB.0
Do
Count RB.0, 250, Hertz
RPM = Hertz * 240
Loop

Or should you sample the input longer say 1000 ms? Would it be accurate at 250 ms sample?


Post Edited (bennettdan) : 6/28/2007 12:05:12 AM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2007-06-28 01:53
    It depends on the minimum and maximum RPM you expect to measure.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • bennettdanbennettdan Posts: 614
    edited 2007-06-28 03:17
    The minimum would be around 500 RPM and the max would be around 7000 RPM
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-06-28 07:11
    Did you decide on using a single SX to keep track of RPM?. If not COUNT consumes to many resources and acuracy at 1000 or 250 ms is poor (to me). You could easily be off at least·60 to 240 RPM per measurement. Thats why I was considering an interrupt that counted only 1 revolution per interrupt (maybe a few more) and then calculate the angular acceleration of that revolution, that should be equal to a specific RPS or RPM. And the resources used would be much less than using COUNT.

    I am not sure if it really is any more accurate, but the resources required would be so small that I thought it was a better alternative. Although a slave SX that uses COUNT RB.0, 60_000, RPM would be the most accurate.

    Another thought was an interrupt that would record every 10 ms (or less), for 10 ms and repeated·100 times to create an RPS figure (or any combo that gives you a total of 1000 ms)·to minimize the resources used.

    Bill
  • bennettdanbennettdan Posts: 614
    edited 2007-06-28 14:05
    Would Pulsin command work faster. Then I could just look for a certain pulse length instead of the counts?
  • JonnyMacJonnyMac Posts: 9,215
    edited 2007-06-28 14:25
    Sure, use two PULSIN functions: one for the low side of the signal, the other for the high; add the results to get the period and the rest is math. (F = 1 / T).
  • BeanBean Posts: 8,129
    edited 2007-06-28 15:09
    Yes, pulsin will give you time for 1 revolution in 10 uSec units.

    So 6,000,000 / (time in 10 uSec units) = RPM

    The math is going to be a little tricky, but will be the most accurate.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • bennettdanbennettdan Posts: 614
    edited 2007-06-28 17:01
    Whould this work for the Pulsin command to read RPM?

    Pwidth1 VAR Word
    Pwidth0 VAR Word
    Temp VAR Word
    RPM VAR Word

    Do
    PULSIN RA.0, 1, Pwidth1
    PULSIN RA.0, 0, Pwidth0
    Temp = Pwidth1 + Pwidth0
    Temp = Temp * 1000
    RPM = 6000 / Temp
    Loop

    Post Edited (bennettdan) : 6/28/2007 6:08:41 PM GMT
  • BeanBean Posts: 8,129
    edited 2007-06-28 21:12
    If you have one sensor on the shaft, then at 500 RPMs your period will be 12000 in PULSIN counts.

    You cannot take 12000 times 1000 because that will overflow the word variable maximum value of 65535.

    Even at 7000 RPMs the period will be 857 in PULSIN counts. And again you cannot take 857 times 1000.

    You will need to do a 32 bit division to get RPMs.

    I have some code to do 32 bit division, I'll have to see if I can find it.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • bennettdanbennettdan Posts: 614
    edited 2007-06-28 21:31
    Thanks Bean for the Help I didnt think about overflowing a Word variable.

    What if I drop some zeros from both the 1000 and 6000 and make them 100 and 600 or 10 and 60 the answers would be the same and·would not overflow the Word right?

    ·Do
    PULSIN RA.0, 1, Pwidth1
    PULSIN RA.0, 0, Pwidth0
    Temp = Pwidth1 + Pwidth0
    Temp = Temp *100
    RPM = 600 / Temp
    Loop

    Post Edited (bennettdan) : 6/28/2007 9:48:30 PM GMT
  • BeanBean Posts: 8,129
    edited 2007-06-28 23:08
    At 500 RPM you are going to get a value of 12,000.
    12000 * 10 = 120,000 which is STILL greater than 65535.

    Without doing anything fancy the best you could do is:

    Do
    · PULSIN RA.0, 1, Pwidth1
    · PULSIN RA.0, 0, Pwidth0
    · Temp = Pwidth1 + Pwidth0
    · Temp = Temp / 100
    · RPM = 60000 / Temp
    Loop

    This will give you 5Hz resolution at 500 RPM, but only 1000 hz resolution at 7000 RPM (pretty much unusable).

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com


    Post Edited (Bean (Hitt Consulting)) : 6/28/2007 11:17:07 PM GMT
  • BeanBean Posts: 8,129
    edited 2007-06-29 00:09
    Here is a program that will give you RPM by doing 32 bit division.
    Accurate to about 1 RPM @ 7000 RPM.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
  • bennettdanbennettdan Posts: 614
    edited 2007-06-29 01:23
    Thanks Bean,
    It will take a month to sort out the code and understand it but I will give it try.
  • BeanBean Posts: 8,129
    edited 2007-06-29 01:49
    LOL, You don't really need to understand the division routine. Just know that the routine will calculate "rpm = 6,000,000 / wPulse0".

    Let us know if it works for you.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • bennettdanbennettdan Posts: 614
    edited 2007-06-29 15:26
    Thanks again Bean.
    How did you come up with 12000 being 500RPM and 847 being 7000 RPM?
  • BeanBean Posts: 8,129
    edited 2007-06-29 15:27
    There are 6,000,000 10uSec increments in a minute.
    So 6,000,000 / 500 = 12,000 and 6,000,000 / 7000 = 857

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • bennettdanbennettdan Posts: 614
    edited 2007-06-30 01:44
    I see now thanks again ..
  • ellizardellizard Posts: 106
    edited 2007-06-30 08:18
    HI all,

    Having done the rpm count on my boat's engine.
    I had to reinvent the sensor due to extremely high cost of the original from Volvo Penta, ( a sturdy magnetic working at 12V rougly 150US$)
    I painted black half of the circumference of the fly wheel, the other half is painted white,
    and an ir sensor detect the black (or the white as by personal preferences),
    I've had help from DR. Tracy Allen for solving the equation necessary, and after several testing,
    I've found that if the two halves of the fly wheel are similar enaugh in length, with the measurement of only one half,
    the error in the readings was pretty the same than having the two readings.
    I acclude the File I've done.
    Hope this could be useful........even with the comments in italian language

    Best Regards
    Stefano

    P.S. The program use an DS1603 RTC/elapsed time for taking count of the time the engine is on (maintenace purpose),
    An MAX7219 for displaying the time/RPM in a five digits 7 segments LED display,
    (with a little trick, the fourth digit is reversed to accomplish the thousand points that in italian notation is on the upper left)
    It was developed for the BS2, but I think it could be easily translated for SX28/48 (may be even eliminating the MAX 7219?)
    I tried to make the porting to sx but lack of time togheter with being the project already done, tested and made, (plus some lazyness from me).
    I never accomplished this task.

    Post Edited (ellizard) : 6/30/2007 8:31:31 AM GMT
  • bennettdanbennettdan Posts: 614
    edited 2007-06-30 18:02
    Bean,
    If I want to use an If Then statement with the rpm word can I use decimal values to compare the rpm variable to. Like this ..
    If rpm = 1500 then
    High RB.2
    Else
    Low RB.2
    EndIF

    If I want to use binary I add a % sign in front of the # and if I use Hex then $ sign infront of the number I want to compare the rpm variable to..Right ?
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-07-01 01:45
    Terry,

    Can I use any Hall Sensor with that code or does it require the Melexis Hall sensor from Parallax? I have a Ignition system test stand that I would like to test the rpm code, combined with code for dual Max6675's EGT's and an 8 bit LCD tonite.

    Thanks

    Bill

    Post Edited (Capt. Quirk) : 7/1/2007 1:54:10 AM GMT
  • ChrisPChrisP Posts: 136
    edited 2007-07-01 15:01
    Just throwing in my 2 cents on this one. The common place to read ignition pulses is from the negative side of the ignition coil as this is where is normaly switched. Optoisolators are a wonderful thing, thanks to Mr Schwab for turning me on to them. Anyway, at this point in the electrical system you'll get a division of the engine rpms, 4 cylinders typically fire twice pre ervolution, 8 cylinders 4 times, and singles are a different animal because they are generally once per due to a crankshaft mounted ignition sensor.

    So on a 4 cylinder engine, reading one high and one low period will give you the time for half of a crank revolution, and most likely will take a full revolution to complete, Bean could chime in on this. Is the SX capable of catching the high and the low imediately following each other or will it need an extra transition to set up for the next capture?

    Engines with individual coils per cylinder could go either way, or you could end up reading the time for 2 revolutions for each ignition signal, some motorcycles may fire 4 times per crank revolution but I believe the typical number to be 2.

    RPM's is always dependant on engine and ignition design, distributor car engines have a 2:1 gearing on the distributor, crank·triggers dont, motorcycles and single cylinders being primarily crank triggered, and cars depend on the vintage.

    None of this is set in stone, it just depends on what your working on, and some of this information may not be perfectly accurate because most of my experience is with motorcycles and older cars. GAF would be the expert in this area. Some day I'll find the spell checker in this thing, till then please excuse the typos.



    <My current project is capturing RPM on 4 cylinders up to 15,000 RPM's, and how accurately and conistantly it can be done>
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-07-01 23:52
    bennettdan,

    If you were interested in building your own ignition system? It·should be fairly easy to take·Terry's code example, to·set the dwell time and ignition timming per·RPM.
  • bennettdanbennettdan Posts: 614
    edited 2007-07-02 05:56
    Capt. Quirk
    Actually I plan to use it in a few of the auto circuits but right now I am using this code and other examples to control a 4L60E electronic shift transmission so a person can put the modern 4 speed transmission into some older hot rods and other autos projects.
    I have the PWM code working and I have the shift solenoids workd out now I plan to use the RPM data to setup shift charts.

    ChrisP
    I thought about the 2:1 gearing on the distribitor and I shoud be able to divide the Pulsin staement to get teh proper amount of pulses comming into the SX and Beans code should still be accurate. I will try to test it the first part of the week.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-07-02 06:49
    Good Application, are you working on your own rod?
  • bennettdanbennettdan Posts: 614
    edited 2007-07-02 15:11
    Yes,
    I have a Chevy truck that I am adding a little extra power to. I have a manual transmission in it at the moment and I perfer a automatic so I can have a remote start and easy of driving in town crusing around.
    The chevy and Ford electronic shift transmissions dont really have that much going on inside they are actually very simple on two shift solenoids and three PWM pressure solenoids and then a set of gear indicator switches.
  • dbjdbj Posts: 75
    edited 2007-07-05 04:04
    The late·4L60E·has a extra·PWM modulated torque converter· solinoid for the (TCC)cluch·. The late style 4L60E uses pulse width modulated lockup that is similar to the EPC control, the idea is to ramp the apply of the TCC based on load calculated from·throtle position sensor and the manifold air preshure sensor.·Keep TCC slip RPM·at a mnimum. Slip = Heat.·This is what kills·most overdrive tranys, overdrive turns output faster than imput so good lockup is·a must, also monitor transmission temp and have a fail safe·mode in case the temp goes High, the sensor is in the presure board. A limp mode is defalt·third gear both shift solinoids off, ·Good luck with your controler.
    ····················································································· David

    Post Edited (dbj) : 7/5/2007 4:19:34 AM GMT
Sign In or Register to comment.