PLC - reading 640Hz with 1ms time base - Ideas? - Page 1
Forum section: electronics / general

author: brabus
author_rank: Frequent Contributor
timestamp: February 27, 2021, 10:26:25 pm
content: Good morning everyone.I have an interesting question for you:We need to read the speed of a diesel engine, the idea is to use the W signal coming from the alternator. The measurement shows about 640 Hz at 2000 rpm, 50% Duty.The PLC we are using can perform tasks with different, but predictable, time bases: 1 ms, 5 ms, 10 ms or more.At the beginning we wanted to make a gated counter: we leave it running @1ms for e.g. 10 seconds, counting how many pulses we see in the 10 seconds, and then calculating the frequency and thus the engine speed. But 640Hz is really fast, with just 1,56 ms period we are past the Shannon limit.I am trying to make up my mind around a clever way to measure the frequency, maybe multiplying the square waves and numerarically, filtering, or trying a rudimentary FFT...What would you do?I will be glad to hear your ideas. Thanks for your help!

author: fourfathom
author_rank: Super Contributor
timestamp: February 27, 2021, 10:44:19 pm
content: If you sample at the 1ms rate will you lose 640 Hz alternator events, or will you (I hope) get a series of true or false readings? (with a 750 Hz signal you would get "1,1,1,0,1,1,1,0..." with 500 Hz signal "1,0,1,0...", with 250 Hz "1,0,0,0,1,0,0,0..." and so on).In that case, use the readings to increment a counter and read/clear (say) once per second. This will give you a freq resolution of 1 Hz. Or feed these 1/0 events into an IIR filter, scaled to essentially convert a duty-cycle into a frequency. It doesn't have to be IIR, but that's easy.

author: MIS42N
author_rank: Frequent Contributor
timestamp: February 27, 2021, 11:06:25 pm
content: Can you use a Divide by 16 Counter e.g 74LS93 or similar. Then you are dealing with 40Hz. If sampling at 1mS intervals you'll get 12 or 13 high, followed by 12 or 13 low. Count the transitions, multiply by 8, multiply by 1000 (mS in a second) divide by number of mS = original 640Hz. If the measurement period starts at a transition (time = 0, count=0) and ends at the next transition after a long period (say 1 second) you will get quite an accurate read. But the count must start at a transition and end at a transition to get the accuracy.

author: fourfathom
author_rank: Super Contributor
timestamp: February 28, 2021, 02:14:19 am
content: Quote from: fourfathom on February 27, 2021, 10:44:19 pmOr if you are just sampling a 0 - 640 Hz squarewave at a 1 ms rate, then yes, Nyquist is a problem. If you simply divide the input by four, and sample *that* at 1 ms, you can detect the transitions in software and use any of our suggestions. I still like the IIR low-pass filter, but integrate and dump is also a good technique.

author: Siwastaja
author_rank: Super Contributor
timestamp: February 28, 2021, 08:18:07 am
content: If it always runs around 640Hz - more specifically, always significantly over 500Hz and below 1000Hz - you can just let it alias and detect the aliased frequency, for example 640Hz would show as 140Hz. Then add 500Hz to the number.This gives false indication whenever the actual speed is below 500Hz or over 1000Hz, though.A sidenote; I have hard time understanding why some people talk about the conductivity in milli-Siemens when they mean milliseconds. I mean, it looks very awkward, and it requires extra work to press the shift key. The correct unit for time is easier to produce: s.

author: MIS42N
author_rank: Frequent Contributor
timestamp: February 28, 2021, 11:56:32 am
content: Quote from: Siwastaja on February 28, 2021, 08:18:07 amEvery time I type ms I think about the abbreviation for women ms Nancy, ms Smith. So I write mS then go "oh, that's wrong" but the internet is full of wrongness and people understand anyhow so I don't change it. It isn't a good excuse, but maybe it makes it easier for you to understand. I know the rules - lower case except for people and liter, lower case for less than a million - but not good at following all of them. my bad.

author: AlfBaz
author_rank: Super Contributor
timestamp: February 28, 2021, 12:35:12 pm
content: Quote from: brabus on February 27, 2021, 10:26:25 pmQuoteI'd double check my frequency measurement, unless of course there's some exotic info missing about the alternator.\$P=\frac{120f}{N_{s}} \$With the figures given above you alternator has 38.4 poles

author: Siwastaja
author_rank: Super Contributor
timestamp: February 28, 2021, 01:20:21 pm
content: Quote from: AlfBaz on February 28, 2021, 12:35:12 pmMy guess: there's a belt; not very exotic. Most alternators on most engines run on belts. Any non-integral ratio is possible.

author: NiHaoMike
author_rank: Super Contributor
timestamp: February 28, 2021, 01:52:12 pm
content: What inputs does the PLC have? I'd imagine something designed to measure speed would be a very common feature. (My first thought: use a quadrature encoder input with a RC circuit to provide the phase shift to make a single frequency into a unidirectional quadrature signal.)

author: snarkysparky
author_rank: Frequent Contributor
timestamp: February 28, 2021, 05:15:58 pm
content: You will need hardware assistance to do it.I think a common feature of many PLC is a counter input. This will increment a counter in hardware without any software intervention which you can read periodically.Failing that a simple binary divider circuit taking as input the W signal and output say W/64 in frequency which you can easily read with 1 ms .Its a very simple circuit. If no one gives you a better idea post the details of the W signal and the PLC input and I will design you a circuit.

author: AlfBaz
author_rank: Super Contributor
timestamp: March 02, 2021, 06:07:20 am
content: Quote from: Siwastaja on February 28, 2021, 01:20:21 pmMy industrial background saw diesel engine and alternator and thought diesel powered alternator. Reading back it may well be what you say, an alternator hanging off the side such as in automobiles.Having said that 640Hz still seems unrealistic. Even if it was some ridiculous number of poles like 24 for example you are still looking at 3200RPM which would require the rotating parts to be very well balanced. Mechanically this would almost certainly rule out belt driven.Quote from: snarkysparky on February 28, 2021, 05:15:58 pmYes, they're call frequency to voltage/current converters. They are relatively cheap and far easier to fault find than some overly convoluted PLC code

author: bdunham7
author_rank: Super Contributor
timestamp: March 02, 2021, 06:37:43 am
content: Quote from: AlfBaz on March 02, 2021, 06:07:20 amAutomotive alternators routinely go 20,000+ RPM. In this case, try a typical pulley ratio of 3.2 so that the alternator is doing 6400 RPM and you get 12 poles, which might be right for a big alternator on a diesel.

author: fourfathom
author_rank: Super Contributor
timestamp: March 02, 2021, 06:46:45 am
content: Quote from: AlfBaz on March 02, 2021, 06:07:20 amFor what it's worth, the alternator on my sailboat (with a 45HP diesel) needs to spin between 3000 and 6000 RPM in order to deliver close to the rated output. It's rated to120012,000 RPM, and I think has 12 poles. I don't know my pully ratios, but since my diesel tops out at around 3500 RPM, I would guess the ratio is about 1.5 : 1.12 poles at 6000 RPM gives a 1200Hz waveform, doesn't it? If so, the OP's 640 Hz seems quite reasonable.[edit: Alternator is rated to 12,000 RPM, not 1200 (typo on my part). Here's a link to a spec sheet:https://mk0balmaromwtjt14hae.kinstacdn.com/wp-content/uploads/2017/11/PDS-621-120-DV.pdf]

author: AlfBaz
author_rank: Super Contributor
timestamp: March 02, 2021, 09:57:30 am
content: Interesting.I'll have to look into this as I'm finding it hard to believe some of these figures, especially the "routinely 20,000+" bit.Maybe I'm conflating precision balancing at speeds greater than 2500RPM on smaller machines with larger kW rated machines

author: MIS42N
author_rank: Frequent Contributor
timestamp: March 02, 2021, 10:54:46 am
content: I found this "Typically, alternators have their full output rated at 6000 RPM but can continue to spin up to 12,000 RPM or more without any additional increase in output." from a research paper. It also says a typical rpm ratio for a passenger car is 3:1, so if the engine reaches 5000 rpm the alternator is doing 15000. This is not a lot, a turbocharger can spin over 100,000 rpm. Where my father worked in the 1950s there was a compressor with a 3/4 ton rotor that ran at 12,000 rpm. And belt driven superchargers are well over 20,000 rpm. So the figures look reasonable - 6000 rpm = 100 revs /sec and with multiple poles 640Hz looks OK.

author: bdunham7
author_rank: Super Contributor
timestamp: March 02, 2021, 03:34:51 pm
content: Quote from: AlfBaz on March 02, 2021, 09:57:30 amOpen the hood of a car and measure the crankshaft and alternator pulley diameters. Divide the former by the latter to get the drive ratio. Determine the maximum speed of the engine and multiply that by the drive ratio and you have the maximum speed of the alternator. I think you'd be hard pressed to find a modern automobile where that maximum doesn't hit at least 15000 RPM.I know of one case of an alternator failing due to overspeed. A guy I knew was coming off the interstate with his old Mercedes SL and downshifted into the wrong gear, ended up way past redline and the old Motorola alternator just exploded. Other than that, the high speeds don't seem to be an issue. And yes, they are carefully balanced at manufacture, just like turbochargers.

author: AlfBaz
author_rank: Super Contributor
timestamp: March 04, 2021, 10:29:42 pm
content: I finally got around to looking up some of this stuff and everything I doubted is typical when it comes to automobile alternators.I'm a little embarrassed by my lack of knowledge in this field considering I spent years maintaining, installing and repairing 3 phase industrial alternators and load sharing systems, not to mention doubting the generally wise contributions made in this forum.My apologies to the OP for derailing your thread

author: Doctorandus_P
author_rank: Super Contributor
timestamp: March 05, 2021, 12:37:44 pm
content: It seems your PLC is too slow to do it by itself.And once you start adding hardware, a small microcontroller is usually the first to go to these days.Any simply microcontroller can easily measure events with 100ns accuracy or better, which means you can get an accurate RPM reading between any 2 (rising) flanks of your alternator signal.It does of course need some signal conditioning, overvoltage protection etc, but you need that with any added electronics.And when you start thinking microcontrollers, you may also think of ditching the PLC and do everything in the microcontroller.

author: brabus
author_rank: Frequent Contributor
timestamp: March 05, 2021, 03:04:07 pm
content: Quote from: AlfBaz on March 04, 2021, 10:29:42 pmAbsolutely no problem, it was a good occasion to read some interesting insights on the topic.Thanks everyone for your interesting comments and for your knowledge; I tried to play a bit with the numbers on the PLC but the measurement is erratic. We can reliably read frequencies up to ~200Hz with a 1 ms time base and a windows of 1 s. No improvement with longer windows, such as 5 s or 10 s.At the end of the day, there is very little we can do against Mr. Shannon.I would gladly use some glue logic or a microcontroller, the problem is that the system needs to satisfy very stringent regulations and I am forced to buy off-the-shelf certified modules. We ended up identifying a counter module for the PLC, but the budget wasn't very happy with that.Together with the customer we found a solution which meets the engineering target and the management cost projection: an off-the-shelf module which converts the frequency from the alternator into a proportional voltage signal. This signal will be then fed to the PLC and properly scaled to obtain an RPM value. Not the most fascinating solution, but it does what we need and everyone is happy.Thank you again!

author: TomS_
author_rank: Frequent Contributor
timestamp: March 16, 2021, 07:28:54 am
content: Quote from: MIS42N on February 28, 2021, 11:56:32 amIf it's of any help, I believe that "Miss" as in the woman's title is written as Ms.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: April 01, 2021, 08:41:45 pm
content: milli-Siemens does not have much to do with time.https://en.wikipedia.org/wiki/Siemens_(unit)It is amazing how often people think that inventing their own unit names is a clarification instead of an obfuscation of normal & decent SI units.

author: MIS42N
author_rank: Frequent Contributor
timestamp: April 01, 2021, 09:45:35 pm
content: Quote from: Doctorandus_P on April 01, 2021, 08:41:45 pmSiwastaja pointed this out on February 28. There has been no transgressions since then. You are preaching to the converted.