博客首页 | 排行榜 |

设计我最赞的博客

个人档案
博文分类
预防水战争(Water War Prevention)  2008-10-18 14:06
An MCU-Based Monitor For A Communal Well

Jeff‘s Microchip Technology PIC12F510-based system monitors the water filtration system in an underground well. The design indicates when the communal filtration system's brine tank is out of salt.

We are beginning to see some signs of public panic due to water issues. I have read about towns whose water sources (e.g., wells) are being threatened by pollution, both natural and man-made. I have also read about cases where upstream users are diverting increasingly large amounts of flow for their own (gluttonous) needs. Perhaps Mother Nature will choose to frustrate humanity by redistributing her life-giving precipitation. While solutions on a local level might be an initial necessity, regional, national,and even global resolutions might better promote unity. The Earth‘s resources do not respect our concocted territorial boundaries. Do we have the rights to water, coal, or any other resource under our feet? What about when a resource just passes through (e.g., a river)?

We must respect the planet and our neighbors, and we should be willing to compromise in order to avoid major conflicts. Unfortunately, some people don‘t think this way. As a result, it may not be long until a gallon of water costs as much as a gallon of oil. Only time will tell. I do know, however,that during the next few years engineers like us will be tasked with developing new systems to facilitate better water management, delivery, filtration,and monitoring. I recently used my engineering skills to tackle a local water issue. In this article, I‘ll describe how I built an MCU-based monitoring system for a water filtration tank.

WATER SUPPLY
Urban dwellers depend on municipal water works to provide an unending supply of fresh, albeit treated, water. As urban sprawl increases,more rural homesteaders are tied together by local community wells and even private single-home water systems. While a private system might be outside the jurisdiction of town regulations, I think it‘s safe to say that no one wants bad tasting,smelly, or toxic drinking water. As the landscape changes, we want to be assured that our water supply has not been compromised. Periodic water testing relieves these concerns. Once we find that our underground aquifer is not being polluted, our attention shifts from supply to quality. Just because the water isn't toxic doesn‘t mean it is palatable. The rotten egg smell from sulfur, the laundry staining rust from iron,or the numerous other byproducts of natural but nontoxic minerals have a direct impact on the quality of the water we pump out of the ground. Extracting undesired material can be a fairly automatic process. Water filters/ softeners mine minerals from the water by various means. Filtering is used to remove particulate. These can easily be seen and removed by simply straining the water,using a material with restricted openings. Filters are available down to 1 μm (0.01× the size of the human hair)。 The smaller the pores, the slower the flow through the filter, and the quicker it will become clogged (needing to be replaced)。 A filter of 10 or even 50 μm may be adequate unless you require protection against water parasites. Carbon is highly effective in removing chlorine, organic contaminants, chemicals,and undesirable tastes and odors. Like the filter cartridge, you must replace carbon periodically because it has a finite amount of absorption and will cease functioning once full.

As water travels through the Earth,minerals are absorbed and water becomes harder. The extent of hardness is measured in grains per gallon(GPG)。 A grain is a unit of weight(approximately 0.000143 lb, with 1 GPG = 17.1 ppm)。 Water with an excess of 5 to 10 GPG is considered very hard. The dissolved minerals can accumulate on surfaces in the form of a hard scale. The buildup will eventually clog pipes and may damage water-using appliances. These minerals also affect the ability of soap to clean surfaces, dishware,and laundry. While these are not generally harmful to the body, a water softener can remove them and protect your plumbing.

A water softener that will remove these is based on the exchange of ions. An ion is a molecule that has lost or gained one or more valence electrons,giving it a positive or negative electrical charge. My system has two basic parts, the brine tank and the resin tank with a controller (see Figure 1)。The tall tank is filled with resin beads typically made from styrene or divinylbenzene. As well water passes through the tank, mineral ions are attracted to the resin, which in turn gives off salt ions. Like other filtering devices, once the surface area of the beads is covered with mineral ions,the exchange ceases. Unlike other filters,the system has the distinct advantage of being able to clean or regenerate itself via a periodic regeneration cycle. The tank‘s controller measures the amount of water used to determine when a cleaning cycle is necessary. When necessary, the controller initiates a cleaning cycle.


During a cleaning cycle, well water temporarily bypasses the filter while a brine solution-sodium chloride(NaCl) or potassium chloride (KCl)and water-flushes the mineral ions from the host resin. Thus, the resin is regenerated by the exchange of brine ions for mineral ions. The host resin itself does not need replacing. However,because the brine is removed and replaced with water each cleaning cycle, the NaCl or KCl in the brine tank needs replenishment. The brine tank can hold a few hundred pounds of NaCl or KCl pellets. When the brine is replaced with water, the pellets will be dissolved by the water until saturated, at which point the remaining pellets sit in the brine. Eventually, when all of the pellets have been dissolved and you‘ve forgotten to add to the brine tank, the regeneration cycle becomes useless and the removal of minerals ceases.

My house and seven others in the neighborhood receive water through a single community well that just happens to be on my property. A perfectly working pump and water softener are key to keeping the neighborhood one happy family. Guess who gets the call when something acts up?

The pump, storage tank, and water softener are housed in a below-ground well house. Generally, this all worked without much intervention. Nevertheless,I came up with an idea several months ago. I wanted the ability to know-without having to periodically enter the dungeon pit-when the brine tank is empty and when the system fails.

TWOFER
Knowing the depth of the pellets left in the brine tank without having to venture underground is a big improvement. Because the water level in the brine tank isn‘t constant,weighing the tank to determine the potassium level won't work unless I know how much water is in the tank and can subtract its weight. Using electronics inside the brine tank isn‘t safe (due to corrosion), so I keep any electronics on the outside. I can sense the level of the water from the outside with a magnet floating on the water's surface. Sensors measure the water level. I use the same sensors to measure the position of a magnet that rests atop the pellets.

The system in Figure 2 is what measures the pellet and water levels. The brine tank has a float switch associated with the water refill cycle that prevents the water level from rising too high and overflowing the brine tank. This float is mounted inside a 4″diameter pipe inside the tank. To measure the water level, I use a foam float with a magnet in the brine tank. To measure the pellet level, I use a piece of 0.5″ plastic egg crate with a magnet in the brine tank.
点击查看Figure2

HALL MONITOR
In a previous column on electromagnetics,I discussed how a magnetic field is produced around a conductor that has a current passing through it("Electric Motor Technology: Theory,Construction, And Requirements," Circuit Cellar 216, 2008)。 When this conductor is within an external magnetic field, the two magnetic fields create a force that tries to move the conductor. This force also has an effect (discovered by Edwin Hall) on the relative position of the current within the conductor (see Figure 3)。 If current flows through a conductor (xaxis) and you measure across the conductor(y-axis), you would measure no potential. As an external magnetic field increases through the conductor(z-axis), the current through the conductor would be forced off center and a potential would be measured across it. A Hall sensor is designed to measure this effect using a thin current-carrying element in a bridge configuration. With a constant current flowing across the element in one axis (x), the other axis (y) will be balanced while no magnetic field is present. Any imbalance is proportional to the strength of the magnetic field passing through the element perpendicular to its other axis (z).


Additional circuitry within the Hall-effect sensor configures its function(see Figure 4)。 Hall sensors are available to measure the magnetic strength, to sense the presence of a magnetic field, or to flip-flop with a magnetic field‘s polarity reversal. Another import use for the Hall-effect sensor is to indirectly measure the current in a wire by measuring the magnetic field produced by the current in that wire. In this project, I want to sense the presence of a magnetic field from a magnet over a minimum distance of approximately 1″ to 2″.


For this operation, I chose the Allegro MicroSystems A3113, a micropower,ultra-sensitive, omni-polar Halleffect switch. Typical switching characteristics(with hysteresis) are 40 gauss(G) on and 32 G off. Note that gauss is the unit of magnetic flux density (B)。The Earth‘s magnetic field is approximately 0.5 G. The local hardware store had a small display of various magnets and I picked up a pair of ceramic magnets about the size of a domino. I connected one of the Halleffect devices to a 5-V supply and monitored the device's open-collector output (with a 47-kΩ pull-up)。 I found the magnet triggered the device right around 2″ from it. Perfect. This verified that the devices were acceptable for my design criteria.

To prevent any contamination or reaction from the ceramic magnets, I dipped each into Plasti Dip, a liquid plastic coating used on many tool handles. This turned out to be more difficult than I had anticipated because of the magnet‘s strong attraction to the can's metal side. I taped a thread to the magnet so I could immerse it and hang it to drain and dry. The pull of these magnets simply ripped off the thread as it jumped to the can‘s side,creating the mess I was trying to avoid! I should have poured some of the liquid into a plastic cup first.

EGG CRATE AND FOAM
On my last trip to the hardware store, I seized the opportunity to search for the items I needed for this project. In the insulation aisle, I found some 1″ high-density foam. This became my brine float. This foam doesn't crumble like the block foam that comes as most packing material. In the lighting aisle, I found some 2′ × 4′ plastic egg crate grills for fluorescent fixtures. They became my pellet float.

Using the plastic brine tank‘s lid as a pattern,I cut a disk out of the foam and the egg crate. I also cut out a 4.5″ hole along one edge, which keeps the disks from spinning within the tank while floating atop the brine and riding atop the salt. After a couple of trial fittings in the tank, I attached magnets to the foam disk and the egg crate disk (see Photo 1)。 The magnets are vertically aligned to one another on each of the disks so when they are in the tank they pass directly behind the Hall-effect PCB strips mounted on the tank's exterior. The brine can easily pass through the holes in the plastic egg crate; the pellets cannot. Therefore,the egg crate rests atop all of the undisolved pellets(see Photo 2)。 While a cleaning cycle is active, all of the brine may be withdrawn from the tank. But it is quickly replaced by the end of the cycle. To prevent the two disks from attracting each other, I placed spacers on the egg crate to keep the two disks at a minimum of 3″apart. The normal level for the water is quite high.



SENSOR STRIPS
To keep the maximum length of this narrow PCB reasonable, I used a length of 8.1″。 This allows sensors to be evenly spaced at every inch and each PCB to report in a single byte(one sensor/bit/inch)。 Because the circuit allows daisy chaining, you can use a number of 8″ sections, as long as you tell the software how many boards (bytes) are in the chain.

Each PCB has its own parallel-toserial shift register. The serial shift register bus contains five signals: 5 V,SDA, SCK, load, and ground. All eight parallel input bits are sampled using the load control line. The inputs can then be shifted out using a SPI (or in this case, the lines are bit banged)。 All Hall-effect outputs are high (1) unless they are sensing a magnetic field. Then the out is pulled low (0)。 The data is read most significant bit to least significant bit and refers to sensors positioned at 31″ down to 0″(using four sensor boards and requiring 4 bytes).

ATINY APP FOR A TINY MICRO
This tiny application is written for a tiny microcontroller. At less than a buck, these eight-pin (and six-pin)devices can be used for many interesting projects. However, because they are inexpensive, they generally don‘t have many of the peripherals that larger devices have. The eight-pin Microchip Technology PIC12F510 microcontroller I used for this project does not have SPI support, so the serial shift routine must be software-driven(see Figure 5)。 The clock is toggled and data is read by assembly instructions as opposed to using a hardware peripheral that could do this in the background automatically.


Limited memory can be problematic for two reasons. The obvious problem:you have limited space in which to cram your application. Writing in assembler is sometimes the only way your application can fit because a higher-level language might require overhead that can put you over the space available. Another problem arises because they generally have few or no hardware peripherals. This means you can chew up precious memory just supporting that function, which then leaves even less for the application.

This application requires only approximately 30% of the 1-KB program space available to the PIC12F510. That includes the software SPI and integer division routines. The application periodically samples the Hall-effect sensors (by reading in 4 bytes of data) and stores the data to a small table (see Figure 5)。Two variables, salt and water, are used to indicate float levels. They are initialized to 32, one more than the maximum level of any sensor (in this case 32 sensors, 0″ to 31″)。 The table is scanned LSB (0) through MSB (31) to find a low. If a low is found, indicating the sensor is seeing a magnetic field,then the bit counter value is stored in either the salt or water variable. The salt variable is tested to see if it has been set. If any value other than 32 is found, the second variable water gets the counter value; otherwise,salt gets the counter value. This gives salt the first counter value when the first low is found(lower level) and water the last counter value when the second low is found (upper level)。 If a float magnet is seen by two adjacent sensors,the lowest sensor is used for the variable salt and the highest is used for the variable water.

The counts in salt are displayed by the red LED. The LED blinks once per second for each ten‘s digit and then again for each unit's digit. A digit of zero leaves the LED on for a longer period of time. The green LED then repeats the display of level count for the water variable (see Figure 6)。 The LEDs are mounted under the roof overhang outside of the locked well house so they can be viewed by looking out of my living room window. Now I can keep track of the system without having to go below ground.


SIMPLIFYING THE SIMPLISTIC
The basic premise of the project is to indicate when the water filtration‘s brine tank is out of salt. I could have done this with a single sensor properly positioned at the bottom of the tank,but this project gave me the opportunity to demonstrate the use of Hall- effect devices to do measurement and not just indication. While the actual level of water in the brine tank isn‘t important, measuring more than one level using the same strip of sensors is a good application. If the filtration system breaks down, the level of water in the brine tank will be an indicator of potential trouble. Because I know that a cleaning cycle normally takes place every "x" days, if the level of the brine hasn't changed in, say, 2x, then I know there must be a problem.

As it is, I use a regulated 5-V wallwart supply to power this circuit(plugged into a GFI)。 If I control 5-V power to the Hall-effect sensors (leave them unpowered when not being sampled),the circuit current will be low enough to run with batteries. I could have used Allegro‘s A3214 for this project. Its less frequent sampling period(60 ms instead of 240 μs for the A3213) translates to a much lower operating current. But it wasn't available at the time I bought these parts.

I will let this circuit run for a while. I will watch its performance. I already have some thoughts on tying this information to other data I might collect in the well house. "Collect"being the key word here. I can think of a few technologies I want to investigate before taking a second look into the pit.

Jeff Bachiochi (pronounced BAH-key-AHkey)has been writing for Circuit Cellar since 1988. His background includes product design and manufacturing. He may be reached through the magazine(jeff.bachiochi@circuitcellar.com) or his web site (www.imaginethatnow.com).

PROJECT FILES
To download code, go to ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2008/217.

SOURCES
A3113 and A3213 Hall effect switches
Allegro MicroSystems, Inc.
www.allegromicro.com

PIC12F510 Microcontroller
Microchip Technology, Inc.
www.microchip.com
类别:嵌入式开发 |
上一篇:设计者最好的朋友(Designer’s Best Friend) | 下一篇:天空导航(Navigating the Heavens)
以下网友评论只代表其个人观点,不代表本网站的观点或立场