LarsLeppek78
Hello everybody,
Is it possible to measure revolutions per minute with openplc?
The revolutions amount to a maximum of 250.
Maybe someone has a solution for me in LD
Use OpenPLC on the PC in connection with an Arduino Uno.
MfG Lars Leppek
Lars Leppek
Reply 0 0
tim292stro
Short answer "yes".

Longer Answer:

You need a stable time reference and and something to count over a fixed time interval.

For an encoder wheel this can be pulses, for an angle sensor this can be degrees traversed.  How you do this depends on a few things:
  1. Most importantly is the range of what speeds you want to measure. 
  2. Second most important is the resolution of the sensor you are using.
These details will drive how you sample this sensor and speed(s).  If it a slow maximum revs, you may wish to use a higher resolution sensor to gain more precise position data - or not... it depends on what you want to do with the data.  You'd take a counter that can't overflow in your sample interval, start the interval timer and open the counter for counts, wait your sample interval, then when the interval expires you block the counter from ingesting additional counts and read out the value.  From there you can multiply that value by "1/IntervalInSeconds" to derive a Hz value.  The trick is that if your interval is too short you will bottom out on a minimum RPM to capture.

For example an interval of 1 millisecond, with a 10 pulse/revolution encoder (1-pulse/36° shaft rotation) will result in a bouncing RPM values (quantization) below 100revs/second or 6,000RPM.  These bouncing errors would be sample intervals with no pulse reading as 0RPM followed by sample periods with one pulse reading as ~6000RPM.  So the advice is to take your maximum worst-case RPM, multiply it by 120% and find an encoder that uses between 90-95% of the maximum counter input frequency.

If you are looking at 250RPM maximum, that's only 4.167 revs/second.  A pulse generator with one square wave per revolution would give a 4.167Hz output - very easy to count with an Arduino Uno (https://create.arduino.cc/projecthub/moty/frequency-counter-92ec57) - this sketch could even easily handle a 10,000pps encoder (41,666.667Hz).  Be aware that this example sketch has a bug with timing - so you'll want to work that out of build on what they have for your own use.

With a 6MHz input frequency you can find a Commercial-Off-The-Shelf encoder that'll do 10,000pulses/revolution - giving a maximum shaft speed of ((6,000,000[MaxinputFreq]/10,000[EncoderResolution]) * 60) =) 36K-rpm.  Then you'd tune your sample interval to find a minimum revs limit based on your RPM resolution desired - if you want three decimal places of RPM, you'd need (((0.001/60) * 10,000) * 2[nyquist]) 0.333Hz sample interval.  This is a refresh rate of about once every 3-seconds, and will provide a frequency output that OpenPLC can easily convert.

If you have more than one PWM input available from an Arduino - you can stagger them so that one begins counting pulses halfway through the other's count interval, an interleaved pulse count.  And a comment about the linked sketch - you could add a tick counter to have it start the PWM pulse counter and grab the current system tick value to a register - then stop the PWM pulse counter after the interval and grab the current system tick counter to find out how many system tick actually elapsed then reconcile the interval tick value against the it by the system clock ticks for the actual frequency derivation.

Once you have the frequency counter value from the Arduino pushed into OpenPLC, divide it by the encoder's resolution, then multiply it by 60 to derive RPM - that's easy enough to do in OpenPLC.  Take a sensor value in Hz and (RegisterHz/EncoderResoution) * 60 = Revs/Minute.  For example a RegisterHz value of 21,562.833Hz on a 10k-pulse/rev encoder works out to: (21,562.833Hz/10000) * 60 = 129.377RPM

The math is similar for an angle/rate sensor (very useful for very low speed position to speed conversion) only instead of pulses per second as Hz, you do DegreesPerSecond/6 = RPM.  This principal is the same for a variety of sensor types.  Optical shaft encoders put out pulses (can be a glass disc, or reflective target).  Gear tooth inductive proximity sensors put out pulses.  Magnetic encoders (hall effect) put out pulses (but I really like these: https://www.rls.si/eng/lm10-linear-and-rotary-magnetic-encoder-system as you can get >16-bit/rev encoders - no affiliation).  Understanding the fundamentals of how to sample the pulses and use the controlled sample characteristics is most of what motion control is about.

One other thing I'll comment about encoder signals... if you get over about 30kHz on the pulse signal, you probably want to think about your wiring as you're transitioning into RF space and your signal integrity is going to become an issue.  Most >5k-rpm encoders with 10KPulse/rev will have a differential signal - use it!! (and with a front-end that features some hysteresis).
Reply 2 0
tim292stro
Some examples of how encoder resolution and sample interval, minimum RPM measured and maximum frequency interplay:

Two example encoders: one is 1024pulse/rev, the other is 20-bit (1,048,576pulse/rev)
Assume maximum input frequency of 6MHz

For the 20-bit encoder the maximum frequency limited RPM is 286.0625RPM at about 5.999MHz, with a sample interval of 3.495253Hz (updates the register every 286.102 milliseconds) - and you get a resolution of 0.0001RPM.

For the 1024pulse encoder at the same revs, the sample interval is almost 300 seconds to get 0.0001 resolution RPM - but your encoder frequency drops to only 5.859kHz, which can accomodate less-than ideal wiring circumstances.
OR if you drop the RPM resolution to 0.1RPM the sample interval is about the same as the 20-bit encoder at about 1/3 of a second.

As you can see, low speed resolution requires higher pulse counts per revolution to keep the count interval reasonable - but higher pulse counts per revolution requires that you handle much higher frequencies at your counter for high shaft speeds.  Optimizing this is a balancing act.
Reply 1 0
LarsLeppek78
Hello,
thank you in advance for these detailed instructions.
Unfortunately I have a late shift this week, so unfortunately I can only test it on weekends.
I will definitely get in touch with you and report if everything went well.
Many thanks
Greetings Lars
Lars Leppek
Reply 1 0
Reply