BeanAnimal's Bar and Grill - Automated RO/DI Water Filtration System - part 3

Automated RO/DI Water Filtration System

part - 3 flow transducer hardware

There are several different types of flow transducers that can be used to measure the volume and/or rate of flow through a piping system. One of the most common (and inexpensive) types is the paddle wheel sensor (transducer). The fluid to be measured (water in this case) flows through the sensor and is directed past a paddle wheel. The paddle wheel rotates past a tiny hall effect sensor embedded in the sensor case. The hall effect sensor creates a small electrical pulse as each paddle edge passes. The volume of flow can be easily calculated by simply totaling the number of pulses. Because each vane (edge) of the paddle creates an electrical  pulse, even at low flows there are multiple pulses per second. In most cases the hall effect style flow sensors are very linear within their designated range of flows. 

Hall Effect Flow Sensor Animation

 The hall effect models generate a pulse each time one of the vanes passes the hall effect sensor. Multiple pulses are generated per single rotation of the paddle wheel.

Because there are multiple pulses per rotation, and the sensor is linear with regard to the number of pulses per volume, regardless of the flow rate, the sensor is very easy to interface to the microcontroller. Total volume of flow can be calculated by simply counting the total number of pulses over a short period of time.

A typical low cost hall effect flow sensor used in high end coffee and soda machines costs $40 - $100 dollars and my project calls for (2); Ouch!

 

HM Digital FMS-2 Flow Sensor

HM Digital FMS-2 Flow SensorWhile searching for TDS sensors I happened upon the super low cost FMS-2 flow transducer made by HM Digital. At $15 each, the FMS-2 appeared to be exactly what I was looking for so I ordered a handful to play with. The design of this paddle wheel flow sensor is slightly different than most of the other paddle wheel flow sensors. One vane of the paddle is equipped with a tiny magnet and the case has a tiny reed switch embedded in the plastic. With each full rotation of the paddle, the reed switch is actuated (closed) momentarily and then allowed to open back up. This results in 1 pulse per rotation. The inexpensive FMS-2 flow sensor is also not linear with respect to the number of pulses per volume and in fact the pulse rate varies greatly over the range of flows that the sensor can measure.

Reed Switch Flow Sensor Animation

The FMS-2 generates a single pulse per revolution of the paddle wheel. The pulse is the result of a magnet attached to one of the vanes passing a reed switch embedded in the sensor's case. 

Because there is only a single pulses per rotation, and the sensor is not linear with regard to the number of pulses per volume, depending on flow rate, the sensor is somewhat complicated to interface to the microcontroller. Total volume of flow is calculated by measuring the frequency of the pulses, not the number of pulses. A mathematical equation is used to convert the frequency into a flow rate. With only a single pulse per revolution, low flow rates would take extremely long sampling times (many seconds) to be accurate to enough decimal places. The problem is that the actual flow rate can easily change during the sampling period! The only viable choice for this type of sensor is to measure the elapsed time between the rising (or falling) edge of EACH pulse and extrapolate that to a frequency.

The FMS-2 datasheet provided very little detail and was of little help so I had to set out on my own to fill in the gaps. The datasheet provided a simple frequency to flowrate conversion table as follows:

Frequency
(Hz)

   Flow Rate
(l/min)

       1.80             0.3
       2.85             0.4
       3.90             0.5
       4.95             0.6
       6.00             0.7
       7.05             0.8
       8.10             0.9
       9.15             1.0
      11.25             1.2
      13.35             1.4
      14.40             1.6
      17.55             1.8
      19.65             2.0

I was able use the table to work backwards and derive the equation used to create it. It sure would have been nice if the HM Digital folks had just provided the equation to begin with.

The flow equation:

FMS-2 Frequency to Flow Equation 

Can be simplified to:
FMS-2 Frequency to Flow Equation Simplified

While there is a slight loss of precision in the simplified equation, it will be more accurate than needed for the intended purpose. Furthermore, a single divide (as opposed to the two divides) will help save clock cycles in the microcontroller code. Actually, the simplified version is only two mathematical operations compared to 4 in the unsimplified version. BASCOM-AVR only allows for 1 instruction per line of code, so the net savings are rather substantial when working with limited clock time and program memory.

 

Frequency From Elapsed Time

There are many ways to measure frequency using an AVR microcontroller and I toyed with several options, one of them being interrupt driven timers and counters that would be set each time a pulse from the FMS-2 sensor was detected. In practice this worked, but would have required the use of several of the scarce AVR interrupt timers and I/O pins. Instead of an interrupt based frequency counter, I decided to use polling. Quite simply the software checks the state of the I/O pins once every 500μs (500 microseconds). Polling at that relatively slow (500μs) rate still allows plenty of processing time for the other functions of the RO/DI automation controller while still allowing for very little error at the expected flow rates.

The elapsed time to frequency conversion is straight forward. The elapsed time is recorded in 500μs ticks ( 0.0005 seconds per tick). That means there are 2000 ticks per second. 1 Hz = 2000 ticks, or 1 revolution per second. The simplified equation looks like this:
Ticks To Frequency Equation    

 

BASCOM-AVR Code

The BASCOM-AVR code for reading the HM Digital FMS-2 flow sensor is straight forward. One leg of the sensor is hooked to 0V (ground) and the other to an INPUT pin on the microcontroller. The input pin is pulled HIGH via PULLUP RESISTORS. Each time the reed switch is pulled closed by the magnet, the INPUT pin is pulled to LOW (0V, GROUND) LOGIC. 

The code simply looks for changes in the state of the INPUT pin that the sensor is connected to, it does this once every 0.0005 seconds. If the state is LOW then a pulse has occurred, if not a counter variable is incremented. Each time a pulse (LOW LOGIC in the pun) is detected, the elapsed time (recorded in the counter variable) since the previous pulse is stored and the counter variable is reset. Once per second, the stored value is used to calculate the instantaneous flow rate through the sensor. The flow rate is calculated by converting the elapsed time into a frequency.  

I need to clarify something very important regarding the theory as explained above, and the actual CODE presented below. In the animation above, the reed switch is CLOSED momentarily once per rotation, pulling the LOGIC HIGH to 5V. A perfectly square wave form is depicted in the picture. In the real world, when the reed switch closes, it will bounce several times, creating a jagged rising edge. This is known as "switch bounce" and can cause false readings. There is usually much less bounce when a switch is OPENED. Also, many microcontroller INPUT pins work better when they are pulled to a HIGH LOGIC (5V) and wait to sense LOW LOGIC (0V). For this reason the INPUT PIN for the FMS-2 is pulled HIGH on the ATMEGA128 microcontroller and tied to one leg of the FMS-2 flow sensor. The other leg of the flow sensor is tied to GROUND. Each time the reed switch closes, the INPUT pin of the ATMEGA128 is pulled to LOW LOGIC (0V, ground). In other words, the momentary pulses are 0V and the rest of the time the microcontroller reads 5V on the input pin. Keep this in mind when reading the BASCOM-AVR code.  

BASCOM-AVR FMS-2 Sensor Code

Click on the image above to see the BASCOM-AVR code for reading the HM Digital FMS-2 flow sensor. For the sake of brevity and space, variable declarations and compiler directives are not included in the code snippet.

That concludes the HM Digital FMS-2 flow sensor overview. In Automated RO/DI Water Filtration System - part 4 we will look at the code and electronics for the HM Digital TDS sensor.




Umbraco Development: MB Technology, Inc.

Website: Naked Ape Software

Privacy Policy

COPYRIGHT © 1989 - 2017, WILLIAM BURNETT. ALL RIGHTS RESERVED.