Measuring flow meter pulse outputs - Page 1
Forum section: electronics / beginners

author: InsertUsernameHere
author_rank: Contributor
timestamp: April 12, 2020, 10:11:16 am
content: Hi guys, I've been scratching my head over this one for about a month so I decided i might reach out for a bit of help from the guru's.A bit of background, I've always been interested in electronics but never really dabbled in it to any serious level outside of automotive stuff.With that in mind I've jumped in to the deep end and decided to create a management system for our bitumen tank farms and processing plants to automate and control the process more.Don't worry these are small systems and not a huge processing plant; the need arose due to the aging system having no automation or even tank level indication. Yes i could go down the proprietary route or PLC based system but the cost would be prohibitive and would be no where near as fun or challenging!Essentially to project started out simple as measuring a 4-20mA input to show tank levels from a sensor on a web and iphone app; this bit is complete.Now the project has morphed into a complete User Management / Automation / Valve Controller / Pump Controller system with various business requirements.I have created version 1 of my PCB (the excitement when it got delivered was almost too much) but now version 2 has many more functional requirements due to the project expanding into more of a complete system.The system is currently driven by a Pycom FiPy as the Microcontroller with the software written in Micropython and it seems to be working well so far.The problem I am having is I now have to interface various flow meter's that output differing pulse outputs and I'm not convinced that driving these directly into the ESP32 would provide the most accurate readings.The inputs vary from a single channel 2 wire signal that will be pulsing around 60hz up to a 3 channel (60 degree offset not a quadrature output) signal that could run up to 4khz, subsequently I also have a few standard quadrature (2 outputs plus index and 2 output only) encoders to deal with as well.I'm really at a loss as to how to count these reliably, I'm not concerned with frequency i just need to ensure accurate counting for a totalizator function (measuring volume).I've done a bit of research on counters that might work but I'm not too sure how to handle all signal possibilities listed above. I will also have to use an opto-coupler to isolate the signals as they run up to 24vdc in some circumstances.Short question is, can someone point me in the right direction to reliably count the pulse meters and interface with my esp32?Also will using an opto-coupler to isolate the circuit cause any issues with counting the pulses reliably as well?I hope that wasn't too much of a spielP.S. I'm loving this journey so far and cant wait to see what else I can learn out of this project and see where it ends up!Cheers, Brett.

author: thatguy1988
author_rank: Newbie
timestamp: April 16, 2020, 05:27:53 am
content: I have used Arduino's to count flow meter pulses in the past (though you could use other programmable micro-controllers). I simply programed it to start counting time, count the number of rising edges on each output channel, measure the elapsed time and from that calculate the flow rate. You can read more about how flow meter outputs work herehttps://thesensorshack.com/sensors/turbine-flow-meters/. Note that you normally need to use a pull up or pull down resistor (depending on weather the flow meter is NPN or PNP type). This is because the square wave flow meter output signal either alternates between 0 V and floating or 5 V and floating and you must use the pull down or pull up resistor to pull the floating output to the correct voltage (either 0V or 5V).

author: InsertUsernameHere
author_rank: Contributor
timestamp: April 17, 2020, 10:23:12 am
content: Yeah I've seen a lot of examples with an Arduino but not with an ESP32 (Pycom FiPy) and from what I've read the results are mixed.I was looking at offloading this to a PIC but I found this LSI chip LS7366R, i have ordered one off eBay to test it, the problem is no one stocks them from what i can see so even if it works it might be a no go.

author: Nathanael Law
author_rank: Newbie
timestamp: April 19, 2020, 06:52:28 am
content: I’m also coming from the software side of things and getting into some industrial equipment interfacing that would traditionally be handled by PLCs, so please take my response with a grain of salt.In order to accurately count pulses, you need to be able to sample them at at least 2x the maximum pulse frequency. E.g. if you have a 4 kHz pulse signal, you need to sample (read the signal value) at least once every 125μs (8 kHz). If you can not guarantee that your MCU will be able to do this (e.g., you have some function(s) that may execute in your code that takes near 125μs to return, you can not just read the value of the pulse input directly; you’ll miss pulses.There are a few options that I’ve seen: (1) wire the pulse input to an reasonably high priority interrupt, and (2) use a timer on the MCU. (1) has the potential to be rather disruptive to your program flow, and seems clunky to me, but may be okay in some circumstances. (2) appears to be the preferred option to me for high speed pulses since you can essentially wire the pulse input directly to the timer circuit (in the MCU configuration, not with a physical wire). Then it can count pulses independent of code execution. You can then query the timer for the current count whenever you want in your program flow. Some MCU timers even have built in quadrature decoding, which makes this particularly attractive.SeeSTM32L4 - Timersfor an overview of timer features on STM32L4 MCUs; other vendors have similar support.And thoughts from someone with more experience would be appreciated as I’ve been trying to figure this out too.[edit: URL formatting]