Hardware solution to rate limit frequency measurement of a square wave - Page 1
Forum section: electronics / projects

author: A.Huggy
author_rank: Contributor
timestamp: June 09, 2025, 08:52:05 pm
content: Hello,I'm working on a little project that involves measuring the flow of a fluid. I have some flow transducers that measure the amount of oil that is pumped into and out of a tank.The transducers output a square wave (open collector) that changes frequency based on flow. The transducer that is on the input to the tank is working great because the oil is pumped into the tank and therefor under some pressure when it flows through this transducer. The transducer on the output of the tank is the problem, it is not pumped, it's just a gravity feed. Sometimes bubbles flow through the output transducer and cause the square wave to be erratic. For just a few milliseconds the waveform will stop and a few pulses are missed, see the scope trace here:I would like to find a solution to fill in the gaps using hardware but this is the first time I've come across this challenge. Is this a common input filtering requirement and how would you address this with hardware?Thank you!

author: ajb
author_rank: Super Contributor
timestamp: June 09, 2025, 09:52:02 pm
content: Is the output actually frequency versus flow rate, or is it one pulse per unit of volume? What device is reading the transducer's output? Since this is a digital output, presumably a digital system of some sort is reading it?I don't think I would address this with hardware. Assuming something like an MCU or PLC is measuring the time between pulses to determine the flow rate, you could do some simple digital filtering on those interpulse times, or possibly reject any values outside the expected range, before converting to flow rate. If you really need to produce a continuous pulse train, ie because you don't have control over the reading device, I think I would still rather do this in software running an MCU between the transducer and the other device rather than try create some sort of analog circuitry -- or go with an even lower-level hardware approach and install an air trap?

author: Benta
author_rank: Super Contributor
timestamp: June 09, 2025, 09:52:22 pm
content: A PLL would do it.But I'm confused about the premise. I mean, if it's an air bubble and not oil, why count it? At a gas station, that would be fraud.

author: A.Huggy
author_rank: Contributor
timestamp: June 09, 2025, 10:33:18 pm
content: Quote from: ajb on June 09, 2025, 09:52:02 pmIt is one pulse per unit of volume, and the device reading it is an MCU running software that I do not have control over. I like the idea of a secondary MCU between the transducer and primary MCU. I have been considering this strategy for a while but for some reason I felt like there was a simpler solution to this problem that I was just not familiar with.Quote from: Benta on June 09, 2025, 09:52:22 pmI am not familiar with PLLs, but this looks like a promising solution and a fun rabbit hole to dig into. Thank you!Regarding the bubbles, I think the issue is that tiny bubbles get trapped in the transducer at low flow rates and accumulate there until a higher flow rate pushes that air through the system. It also seems like eventually accumulated air reaches a critical volume and gets pushed through even at low flow rates. An air volume of a few cc every 10 minutes is causing gallons worth of error over the course of a day.

author: 2N3055
author_rank: Super Contributor
timestamp: June 09, 2025, 10:47:39 pm
content: If you have bubbles and it is a problem, you need deaerator inserted before sensor, if that is possible.

author: moffy
author_rank: Super Contributor
timestamp: June 10, 2025, 12:37:54 am
content: Quote from: 2N3055 on June 09, 2025, 10:47:39 pm+1 for 2N3055, solve the source of the issue, hacks can have unintended consequences. A PLL might not be the best if the flow rate can vary substantially, for it to remain locked for the missing pulses it would need to be quite narrow band.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: June 10, 2025, 12:47:47 am
content: Quote from: A.Huggy on June 09, 2025, 08:52:05 pmAs others have stated, are you certain that is broken = needs fixing ?Pulse skipping on a transducer with bubbles seems perfectly reasonable, asthere is actually less billable fluid passingYou may be better carefully checking the transducer at low flow rates, and compare the pulse indicated flow, with another known accurate measurement (maybe weight ? )If you find deviations, in true <> indicated, you can either buy a better transducer, or remove the bubbles, or try to calibrate the lowest flow rates better.What does the transducer supplier say about errors at low flows and with bubbles present ?

author: radiolistener
author_rank: Super Contributor
timestamp: June 10, 2025, 01:05:20 am
content: you can convert it to voltage and then use median filtering with window size that can cover your bubble periods.

author: Poroit
author_rank: Frequent Contributor
timestamp: June 10, 2025, 06:50:38 am
content: G'day A. Huggy,Can you mechanically modify the outlet of the tank so the transducer always sees a full pipe?Can we see a pic of your tank?

author: tggzzz
author_rank: Super Contributor
timestamp: June 10, 2025, 10:53:45 am
content: Quote from: A.Huggy on June 09, 2025, 08:52:05 pmSo you think re-inserting "missed" pulses will solve your problem, but:what is theproblemcaused by missing pulses?what will be theconsequencesof re-inserting missing pulses?be aware that you are describing an unusual form of resonant/bandpass filter, and basic theory indicates that all resonant circuits take time to "get going" and "ring" after the stimulus stopsTo emphasise that last point, be aware that re-inserting pulses requires that you can determinewhen the next pulse should be insertedwhen you should stop reinserting pulsesThe first cannot be determined instantly; consider what happens when the fluid is beginning to flow but has not reached full rate.The second requires that you can somehow determine that the fluid has stopped flowing and you should stop re-inserting pulses.In short, it is probably difficult to determine what a circuit should do in all cases. Only after you have done that is it worth considering how to do it.

author: A.Huggy
author_rank: Contributor
timestamp: June 10, 2025, 02:42:53 pm
content: Thank you for all of your responses, you've given me a lot to think about.So far this is what I'm considering:The most correct solution to this problem is to address the root cause: adjust the plumbing so that less bubbles are introduced to the sensor. I will look into this.Hopefully I can design the air out of the system, but if I can't, I will still consider some filtering schemes to make the system tolerant of some bubbles.I'm only a couple hours into researching PLLs but it seems like it will be difficult to create a narrow enough band to do what I need it to do.The most practical filtering option seems to be a secondary MCU dedicated to filtering. I'm leaning towards a rate limiting scheme where the secondary MCU samples the input to assess an average frequency over some period of time, then rate limits the rate of change of this sampled frequency. This rate limited measure of frequency is then output to the primary MCU. I have seen this scheme used in automotive environments where noise is often present. Wheel speed and engine speed measurements are often rate limited like this because these physical measurements can only change so quickly. Similar to an engine going from 3000 RPM to zero in 50ms, it is unlikely that the oil flow rate in my system will change from 20gph to zero in 50ms.

author: tggzzz
author_rank: Super Contributor
timestamp: June 10, 2025, 04:39:41 pm
content: Quote from: A.Huggy on June 10, 2025, 02:42:53 pmSensible approach. Once signal quality has been lost, it can't be recreated.You will need to define what constitutes a "good" result for your complete measurementsystem. For example, if you are determining the total fluid transferred, then re-inserting "missing" pulses would overestimate the fluid transferred; would that be "good" or "bad"?For any filtering scheme you will have to define what "tolerant" includes and excludes. No adjectives are allowed; numbers are required.