AN1950
Sensors
4 Freescale Semiconductor
OTHER
This system is designed to run on a 9.0 V battery. It
contains a 5.0 V regulator to provide 5.0 V to the pressure
sensor, microcontroller, and LCD. The battery is mounted on
the back of the board using a space saving spring battery clip.
Smart Washer Software
This application note describes the first software version
available. However, updated software versions may be
available with further functionality and menu selections.
Software User Instructions
When the system is turned on or reset, the microcontroller
will flash the selected LED and display the program title on the
LCD for five seconds, or until the select (SEL) button is
pushed. Then the menu screen is displayed. Using the select
(SEL) pushbutton, it is easy to scroll through the menu options
for a software program. To run the water level program, use
the select button to highlight the Water Level option, then
press the enter (ENT) pushbutton. The Water Level program
will display current water level, the rate of flow, a message if
the container is Filling, Emptying, Full, or Empty, and a
scrolling graphical history displaying data points representing
the past forty level readings.
The Water Level is displayed by retrieving the digital
voltage from the internal A/D Converter. This voltage is
converted to pressure in millimeters of water and then
displayed on the LCD.
Calibration and Calibration Software
To calibrate the system, a two-point calibration is
performed. The sensor will take a calibration point at 0 mm
and at 40 mm of water. Depressing both the SEL and ENT
buttons on system power-up enters the calibration mode. At
this point, the calibration menu is displayed with the previously
sampled offset voltage. To recalibrate the system, expose the
sensor to atmospheric pressure and press the SEL button
(PB1). At this point, the zero offset voltage will be sampled and
saved to a location in the microcontroller memory. To obtain
the second calibration point, place the end of the plastic tube
from the pressure sensor to the bottom of a container holding
40 mm of water. Then press the ENT button (PB2). The
voltage output will be sampled, averaged and saved to a
location in memory. To exit the calibration mode, press the
SEL (PB1) button.
Figure 5. Water Level System Set-Up
for Demonstration
Table 2. Parts List
Ref. Qty Description Value Vendor Part No.
U2 1 Pressure Sensor 1 Freescale MPXM2010GS
C1 1 Vcc Cap 0.1µf Generic
C2 1 Op-Amp Cap 0.1µf Generic
C3 1 Shift Register Cap 0.1µf Generic
D1 1 Red LED Generic
D2 1 Green LED Generic
S2, S3 2 Pushbuttons Generic
U1 1 Quad Op-Amp ADI AD8544
U3 1 Voltage Regulator 5.0 V Fairchild LM78L05ACH
U4 1 Microcontroller 8-pin Freescale MC68HC908QT4
R1 1 ¼ W Resistor 22 K Generic
R2 1 ¼ W Resistor 2.4 K Generic
R3, R6 2 ¼ W Resistor 1.2 M Generic
R4, R5 2 ¼ W Resistor 1.5 K Generic
R7, R8 2 ¼ W Resistor 10 K Generic
R9, R10 2 ¼ W Resistor 1.0 K Generic
U6 1 LCD (Optional) 16 x 2 Seiko L168200J000
U5 1 Shift Registor
Texas Instruments 74HC164
AN1950
Sensors
Freescale Semiconductor 5
Converting Pressure to Water Level
Hydrostatic pressure being measured is the pressure at the
bottom of a column of fluid caused by the weight of the fluid
and the pressure of the air above the fluid. Therefore, the
hydrostatic pressure depends on the air pressure, the fluid
density and the height of the column of fluid.
P= Pa + ρ g h
where P = pressure
Pa = pressure
ρ = mass density of fluid
g = 9.8066 m/s^2
h = height of fluid column
To calculate the water height, we can use the measured
pressure with the following equation, assuming the
atmospheric pressure is already compensated for by the
selection of the pressure sensor being gauge:
h = P \ ρ g
Software Function Descriptions
Main Function
The main function calls an initialization function Allinit calls
a warm-up function, Warmup, to allow extra time for the LCD
to initialize, then checks if buttons PB1 and PB2 are
depressed. If they are depressed concurrently, it calls a
calibration function Calib. If they are not both pressed, it
enters the main function loop. The main loop displays the
menu, moves the cursor when the PB1 is pressed and
enters the function corresponding to the highlighted menu
option when PB2 is depressed.
Calibration Function
The calibration function is used to obtain two calibration
points. The first calibration point is taken when the head tube
is not placed in water to obtain the pressure for 0 mm of water.
The second calibration point is obtained when the head tube
is placed at the bottom of a container with a height of 160 mm.
When the calibration function starts, a message appears
displaying the A/D values for the corresponding calibration
points currently stored in the flash. To program new calibration
points, press PB1 to take 256 A/D readings at 0 mm of water.
The average is calculated and stored in a page of flash. Then
the user has the option to press PB1 to exit the calibration
function or obtain the second calibration point. To obtain the
second calibration point, the head tube should be placed in
160 mm of water, before depressing PB2 to take 256 A/D
readings. The average is taken and stored in a page of flash.
Once the two readings are taken, averaged, and stored in the
flash, a message displays the two A/D values stored.
Level Function
The Level function initializes the graphics characters. Once
this is complete, it continues looping to obtain an average A/D
reading, displaying the Water Level, the Water Flow, and a
Graphical History until simultaneously depressing both PB1
and PB2 to return to the main function.
The function first clears the 40 pressure readings it updates
for the Graphical History. The history then enters the loop first
displaying eight special characters, each containing five data
points of water level history. The function adcbyta is called to
obtain the current averaged A/D value. The function LfNx is
called to convert the A/D value to a water level. It is then
compared to the calibration points, the maximum and
minimum points, to determine if the container is full or empty.
If true, then it displays the corresponding message. The
current water level is compared to the previous read and
displays the message filling if it has increased, emptying if it
has decreased, and steady if it has not changed.
The water level calculation has to be converted to decimal
in order to display it in the LCD. To convert the water level
calculation to decimal, the value is continually divided with the
remainder displayed to the screen for each decimal place. To
display the Rate of Water Flow, the sign of the value is first
determined. If the value is negative, the one's complement is
taken, a negative sign is displayed, and then the value is
continually divided to display each decimal place. If the
number is positive, a plus sign.
Level Function
The Level function initializes the graphics characters. Once
this is complete, it continues looping to obtain an
average A/D reading, displaying the Water Level, the Water
Flow, and a Graphical History until simultaneously depressing
both PB1 and PB2 to return to the main function.
The function first clears the 40 pressure readings it updates
for the Graphical History. The history then enters the loop first
displaying eight special characters, each containing five data
points of water level history. The function adcbyta is called to
obtain the current averaged A/D value. The function LfNx is
called to convert the A/D value to a water level. It is then
compared to the calibration points, the maximum and
minimum points, to determine if the container is full or empty.
If true, then it displays the corresponding message. The
current water level is compared to the previous read and
displays the message filling if it has increased, emptying if it
has decreased, and steady if it has not changed.
The water level calculation has to be converted to decimal
in order to display it in the LCD. To convert the water level
calculation to decimal, the value is continually divided with the
remainder displayed to the screen for each decimal place. To
display the Rate of Water Flow, the sign of the value is first
determined. If the value is negative, the one's complement is
taken, a negative sign is displayed, and then the value is
continually divided to display each decimal place. If the
number is positive, a plus sign is displayed to maintain the
display alignment and the value is continually divided to
display each decimal place.
The most complicated part of this function is updating the
graphics history display. The characters for the 16x2 LCD
chosen for this reference design are 8x5 pixels by default.
Therefore, each special character that is created will be able
to display five water level readings. Since the height of the
special character is eight pixels, each vertical pixel position
will represent a water level in increments of 20 mm.
Resolution = (H1 – H0) / D
AN1950
Sensors
6 Freescale Semiconductor
where H1 and H2 are the maximum and minimum water levels
respectively and D is the possible datapoints available per
character.
Resolution = (160mm– 0mm) / 8.0 = 20 mm / data point.
The graphical history is displayed using the eight special
characters. To update the graphics, all the characters have to
be updated. The characters are updated by first positioning a
pixel for the most recent water level reading in the first column
of the first character. Then the four right columns of the first
character are shifted to the right. The pixel in the last column
of that character is carried to the first column of the next
character. This column shifting is continued until all 40 data
points have been updated in the eight special characters.
LfNx Function
The LfNx function calculates the water level from the
current A/D pressure reading. The A/D Pressure value is
stored in Register A before this function is called. Using the
A/D value and the calibration values stored in the flash, the
water level is calculated from the following function:
RBRA: = (NX –N1) * 160 / (N2 – N1),
where NX is the current A/D Value
N1 is the A/D Value at 0 mm H20
N2 is the A/D Value at 160 mm H20
To simplify the calculation, the multiplication is done first.
Then the function NdivD is called to divide the values.
NdivD Function
The NdivD function performs a division by counting
successive subtractions of the denominator from the
numerator to determine the quotient. The denominator is
subtracted from the numerator until the result is zero. If there
is an overflow, the remainder from the last subtraction is the
remainder of the division.
wrflash and ersflsh Functions
The wrflash and ersflsh functions are used to write to and
erase values from the flash. For more information regarding
flash functionality, refer to Section Four, Flash Memory from
the MC68HC908QY4/D Databook.
ALLINIT Function
The Allinit function disables the COP for this version of
software, sets the data direction bits, and disables the data to
the LCD and turns off the LCD enable line. It also sets up the
microcontroller's internal clock to half the speed of the bus
clock. See Section 15, Computer Operating Properly, of the
MC68908QT4 datasheet for information on utilizing the COP
module to help software recover from runaway code.
WARMUP Function
The Warmup function alternates the blinking of the two
LEDs ten times. This gives the LCD some time to warm up.
Then the function warmup calls the LCD initialization function,
lcdinit.
bintasc Function
The binasc function converts a binary value to its ascii
representation.
A/D Functions
The A/D functions are used to input the amplified voltage
from the pressure sensor from channel 0 of the A/D converter.
The function adcbyti will set the A/D control register, wait for
the A/D reading and load the data from the A/D data register
into the accumulator. The function adcbyta is used to obtain an
averaged A/D reading by calling adcbyti 256 times and
returning the resulting average in the accumulator.
LCD Functions
The LCD hardware is set up for multiplexing three pins from
the microcontroller using an eight-bit shift register. Channels
three, four, and five are used on port A for the LCD enable (E),
the LCD reset (RS), and the shift register clock bit,
respectively. The clock bit is used to manually clock data from
channel four into the eight-bit shift register. This is the same
line as the LCD RS bit because the MSB of the data is low for
a command and high for data. The RS bit prepares the LCD
for instructions or data with the same bit convention. When the
eight bits of data are available on the output pins of the shift
register, the LCD enable (E) is toggled to receive the data.
The LCD functions consist of an initialization function lcdinit
which is used once when the system is started and five output
functions. The functions lcdcmdo and lcdchro both send a
byte of data. The function shiftA is called by both lcdcmdo and
lcdchro to manually shift eight bits of data into the shift register.
The function lcdnibo converts the data to binary before
displaying. The lcdnibo displays a byte of data by calling
lcdnibo for each nibble of data. The function lcdnibo enables
strings to be easily added to the software for display. The
function accepts a comma- delimited string of data consisting
of 1–2 commands for clearing the screen and positioning the
cursor. It then continues to output characters from the string
until the @ symbol is found, signally the end of the string.
CONCLUSION
The water level reference design uses a MPXM2010GS
pressure sensor in the low cost MPAK package, the low cost,
eight-pin microcontroller, and a quad op-amp to amplify the
sensor output voltage. This system uses very few
components, reducing the overall system cost. This allows for
a solution to compete with a mechanical switch for water level
detection but also offer additional applications such as
monitoring water flow for leak detection, and the other
applications for smart washing machines.

KITMPVZ5004EVK

Mfr. #:
Manufacturer:
NXP / Freescale
Description:
Pressure Sensor Development Tools WATER LEVEL BOARD
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet