High Resolution Digital Weigh-Scale Design Using Z8 Encore!

High Resolution Digital Weigh-Scale Design Using Z8 Encore!
Application Note
High Resolution Digital Weigh-Scale Design
Using Z8 Encore!® Microcontrollers
AN025404-0608
Abstract
This application note describes the development
and use of a Digital Weigh-Scale (DWS) using
Zilog’s Z8 Encore!® microcontroller. This
reference design offers a ready-to-use DWS
solution easily scalable to measure high-capacity
loads. A high-resolution Analog-to-Digital Converter (ADC) external to the microcontroller is
used to accurately measure the load cell output.
The measured weight is displayed on the LCD.
are the most commonly employed measuring components. The low voltage output of a load cell
which is in the order of few millivolts needs to be
amplified and digitized. This requires an ADC with
a resolution greater than 16-bit.
A high-resolution ADC with a built-in amplifier is
used for these type of applications. The ADC output is
read by a microcontroller and appropriate algorithms
are used to calculate the weight and display them.
Note: The source code associated with this
reference design is available under
Z8 Encore! Applications Code
Library in Application Sample
Libraries on www.zilog.com.
Features
The main features of DWS are:
•
Measures 10 g to 40 kg (with 10 g resolution)
•
TARE feature to measure net weight
•
Count items with identical weights
•
Calibration of weigh-scale
•
Selectable clock source and reference
voltage for ADC
•
Displays weight on single-line 8 character (8 x 1)
LCD (see Figure 1)
Discussion
Digital Weigh-Scale measures weight or change in
weight depending on the object for measurement.
It displays weight in digital format with appropriate units of weight. Load cells whose output voltage changes proportionally to the weight applied
Figure 1. Digital Weigh-Scale Reference
Design Board
Hardware Architecture
This reference design is based on the Z8 Encore!
MCU which communicates with the 24-bit ADC
CS5550 through Serial Peripheral Interface (SPI).
The output voltage of the load cell is passed
through a Low-Pass Filter (LPF) to suppress any
high frequency noise and applied to ADC. The
measured weight is displayed on a 8 x 1 LCD.
Copyright ©2008 by Zilog®, Inc. All rights reserved.
www.zilog.com
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
This design supports the user interface to handle
TARE, COUNT, and CALIBRATION modes of
weigh-scale operation. The power supply for DWS
is derived from a 9 V DC adapter. It is essential
that the excitation voltage for the load cell and the
ADC reference voltage is derived from the same
source to provide ratiometric connection. Hence,
any variation in excitation voltage of the load cell
does not result in loss of measurement accuracy,
since the ADC’s voltage resolution changes
proportionally.
TARE
The block diagram in Figure 2 provides an overview of the DWS hardware architecture. For more
details on hardware connections, see Appendix
A—Schematics on page 4.
COUNT
Note: The analog input pin, AIN2, is used
as the default analog channel for
measurements. The AIN1 pin is used
to measure much lower load cell
voltages as it supports higher gain.
Switch Functionalities
TARE is a term used in weights and measurements
which refers to the weight to be subtracted from the
gross-weight in order to obtain the net weight. For
example, to measure the weight of contents in a
container, the weight of container (TARE) is subtracted from the gross weight (weight of container
+ weight of contents). For more details on usage,
see Using TARE Function on page 4 and for
software implementation, see Figure 4 on page 5.
The COUNT switch is used to determine counts of
a known weight item. For more details on usage,
see Using COUNT Function on page 4 and for
software implementation, see Figure 8 on page 11.
CALIBRATION (External ADC)
The CALIBRATION switch allows you to perform
gain and offset calibration on external ADC
CS5550.
The functionalities of different switches used in the
design are described in following sections.
5V
9V
Power
Supply
3.3V
2.5V
2.5V
5V
3.3V
3.3V
5V
Vref
VA+
VD+
VDD
8x1 LCD
5V
Load Cell
L
P
F
SDO
MISO
PA4-PA7
AIN2-
SDI
MOSI
PA0
TARE
AIN2+
SCLK
SCLK
PA1
COUNT
~CS
~SS
PA2
CALIBRATION
XIN
T1OUT
PA3
TEST
Switch
CS5550
Z8 Encore!
Figure 2. Digital Weigh-Scale Hardware Block Diagram
AN025404-0608
Page 2 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
TEST
The TEST switch allows you to exit the TARE and
COUNT modes and display the absolute weight
placed on the load cell.
Figure 3 displays the characteristic of the load cell
used in this reference design.
1500000
1400000
Software Implementation
1300000
ADC Count
This reference design makes use of the Z8
Encore!’s on-chip SPI, Timer, and GPIO peripheral. The software presented with this application
initializes these peripherals and configures the
CS5550 ADC. The output of Timer1 is used as system clock source for CS5550. The output of
CS5550 is read every 50 ms. Timer0 is configured
to generate interrupt every 1 ms.
1200000
1100000
1000000
900000
800000
c
700000
600000
A flag indicating the 50 ms timeout is monitored
and initially 10 samples of ADC output are collected and stored into a buffer. The average of these
10 samples is used to calculate the weight. Each
new sample collected thereon replaces the oldest
sample in the buffer. If the current ADC value differs from its previous value by a predefined threshold, then, it implies that there is a substantial
change in weight and 10 new samples are collected. This way, sudden weight changes are taken
into account. The threshold ADC value is selectable through THRESHOLD_
WEIGHT_DIFFERENCE macro.
All weight, COUNT value, and operating modes of
weigh-scale are displayed on LCD. Weight less
than 1 kg is displayed in grams. Weight greater
than 999 g is displayed in kilograms with 3 decimal
places. The software also continuously polls switch
press and corresponding functionalities of the
switches are performed. See Appendix B—Flowcharts on page 5for the software flow.
As the ADC count value read from the controller
corresponds to the Load cell output, the Load cell
characteristic is derived by plotting ADC count
values against standard weights. An appropriate
equation is obtained from this plot which is used to
calculate the weight at run-time.
AN025404-0608
0
5
10
15
20
25
30
35
40
45
Weight (Kg)
Figure 3. Load Cell Characteristics
Figure 3 plot results in a linear equation of type
y = mx + c
(1)
where,
•
•
•
•
x is the weight in kilograms
y is the ADC Count corresponding to the
applied weight
c is the ADC Count when no load is present on
load cell
m is the slope of the curve
Rearranging Equation (1),
x = (y – c) ⁄ m
(2)
Equation (2) is used to calculate weight at runtime.
As the load cell characteristic varies from one to
another, you have to derive an appropriate equation
as discussed above and calculate the weight.
Page 3 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Performing Weight Measurements
Using COUNT Function
Setup
Follow the steps below to use the COUNT
function:
The setup for measuring weight is provided below:
1. Connect the bridge excitation terminals of the
load cell to connector J16 on the reference
design board.
2. Connect the differential output of the load cell
to connector J4.
3. Plug in a 9 V, 10 W DC adapter to J15.
4. Put the SPDT switch SW6 in ON position to
power up the board.
5. Build digital_weigh_scale.zdsproj
available in the source folder of the Application Library using ZDS II—Z8 Encore!.
6. Download the code onto the reference board.
Basic Weight Measurement
Follow the steps below to measure the basic
weight:
1. Execute the code and observe the measured
weight on LCD. This value will vary from one
load cell to other. You will have to calibrate the
weigh-scale against standard weights to get
accurate readings.
2. Place some weight on the load cell and the
measured weight will be displayed on the
LCD screen.
Using TARE Function
Follow the steps below to use the TARE function:
1. Place the object on the scale whose weight is to
be offset for further measurements.
2. Press TARE switch. Character ‘T’ is displayed
on the LCD indicating that the scale is in
TARE mode.
3. Place the object whose weight is to be
measured on the load cell.
4. To exit the TARE mode and start absolute measurement, press the TEST switch.
AN025404-0608
1. Place the reference weight on load cell
against which the counting is to be done
and press COUNT switch.
2. The LCD displays count value ‘1’ and the
mode ‘C’ indicating that the scale is in
COUNT mode.
3. Place additional identical weights to view
the number of objects kept on the load cell.
4. To exit the COUNT mode and start weight
measurement, press the TEST switch.
Using CALIBRATION Function
Follow the steps below to use the CALIBRATION
function:
1. Press the CALIBRATION switch. LCD will
display ‘OFFSET’. At this point connect the
‘+’ and ‘-’ pins of J4 (for AIN2) to ground and
press the CALIBRATION switch again.
2. The LCD will display ‘GAIN’. Connect the
load cell output to J4 (for AIN2) channels and
put maximum weight to be measured on the
load cell. This maximum weight applies the
absolute maximum instantaneous voltage to be
measured across the analog inputs.
3. Press the CALIBRATION switch again to
complete gain calibration.
Optional Design Changes
The optional design changes which can be
implemented are as follows:
1. To change the system clock source to an
external crystal for CS5550, populate crystal
Y1 and do not use resistor R5.
2. To use internal reference voltage for CS5550,
populate the resistor R6 and do not populate
resistor R31.
Page 4 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Note: By default, the reference design uses
external reference voltage for
CS5550 on-chip modulator and
Timer1 output as the system clock
source.
Summary
The reference design based on Z8 Encore!®
Z8F0812 MCU provides a scalable and ready-touse solution for DWS. The software is modular and
easy to customize for any weight measurement
application.
References
The documents associated with Z8 Encore!
Z8F0812 MCU available on www.zilog.com are
provided below:
•
Z8 Encore! XP® F0822 Series Product
Specification (PS0225)
•
eZ8TM CPU User Manual (UM0128)
•
Product Specification—CS5550
(CS5550_F1) available on www.cirrus.com
For lower resolution, the design can be based on
Z8F0822, which has 10 bit on-chip ADC. This
will necessitate the use of external amplifier to
boost the load cell output. The reference design can
be easily ported to Z8F1680 for low-cost and
low-power solution.
AN025404-0608
Page 5 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Appendix A—Schematics
Appendix A displays the schematics of Digital Weigh-Scale reference board.
AN025404-0608
Page 6 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Appendix B—Flowcharts
This Appendix displays the following flowcharts for the Digital Weigh-Scale application using
Z8 Encore!® Microcontroller:
•
Main Function (Figure 4)
•
ADC Sample Collection and Change in Weight Detection Routine (Figure 5)
•
Weight Calculation Routine (Figure 6)
•
TARE Switch Handling Function (Figure 7)
•
COUNT Switch Handling Function (Figure 8)
•
CALIBRATION Switch Handling Function (Figure 9)
•
Processing Switch Inputs (Figure 10)
AN025404-0608
Page 7 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
.
Start
Initialize GPIO, SPI, Timer
of Z8 Encore!. Initialize LCD
& Configure ADC CS5550
Start Continuous
ADC Conversion
Collect 10 ADC samples
and put it into an array
Monitor switch inputs
and call appropriate
functions.
50 ms Timeout
of the timer?
No
Yes
Collect single ADC sample
to replace the oldest
sample in the array
Calculate weight and
display it on LCD in
appropriate format
End
Figure 4. Main Function
AN025404-0608
Page 8 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Start
Replace the oldest sample in the
array with a new sample
Latest two samples differ by a
predefined threshold corresponding
to a certain weight?
Yes
Collect 10 new samples
and refresh the array
No
End
Figure 5. ADC Sample Collection and Change in Weight Detection Routine
Start
Average the 10 samples of
ADC collected in an array
Calculate the weight using
appropriate curve fitting equation
which relates ADC count to weight
End
Figure 6. Weight Calculation Routine
AN025404-0608
Page 9 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Start
Display ‘T’ on LCD
indicating TARE mode
Collect 10 ADC samples, average
and calculate weight. This weight
will be deducted from all future
weight measurements, until
TEST switch is pressed
Change the system mode to
NORMAL, to perform actual
weight measurements
End
Figure 7. TARE Switch Handling Function
AN025404-0608
Page 10 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Start
Display ‘C’ on
LCD indicating
COUNT mode
Collect 10 ADC samples,
average and calculate
weight. Measured weight is
assigned as the unit weight
Any switch other
than COUNT
Yes
No
Collect 10 ADC samples, average
and calculate weight. Divide the
measured weight by the unit weight
to get the count
Display the count
End
Figure 8. COUNT Switch Handling Function
AN025404-0608
Page 11 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Start
Display “OFFSET” on LCD indicating
offset calibration follows
Connect the appropriate analog
input pins of the ADC to ground
CALIBRATION
switch pressed?
No
Yes
Send offset calibration
command to ADC
Display “GAIN” on LCD indicating
offset calibration follows
Connect load cell output to appropriate analog
input pins of the ADC and place maximum
load to be measured on the load cell
CALIBRATION
switch pressed?
No
Yes
Send gain calibration
command to ADC
Set system mode to NORMAL to
perform actual weight measurements
End
Figure 9. CALIBRATION Switch Handling Function
AN025404-0608
Page 12 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Start
TARE
switch pressed?
Yes
Call TARE
handling function
Yes
Call COUNT
handling function
Yes
Call CALIBRATION
handling function
No
COUNT
switch pressed?
No
CALIBRATION
switch pressed?
No
TEST
switch pressed?
Yes
Make the weight
offset (as set in TARE
function) zero and
change system mode
to NORMAL
No
End
Figure 10. Processing Switch Inputs
AN025404-0608
Page 13 of 14
High Resolution Digital Weigh-Scale Design Using Z8 Encore!® Microcontrollers
Warning: DO NOT USE IN LIFE SUPPORT
LIFE SUPPORT POLICY
ZILOG'S PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE
SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS PRIOR WRITTEN APPROVAL OF
THE PRESIDENT AND GENERAL COUNSEL OF ZILOG CORPORATION.
As used herein
Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b)
support or sustain life and whose failure to perform when properly used in accordance with instructions for
use provided in the labeling can be reasonably expected to result in a significant injury to the user. A
critical component is any component in a life support device or system whose failure to perform can be
reasonably expected to cause the failure of the life support device or system or to affect its safety or
effectiveness.
Document Disclaimer
©2008 by Zilog, Inc. All rights reserved. Information in this publication concerning the devices,
applications, or technology described is intended to suggest possible uses and may be superseded. ZILOG,
INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY
OF THE INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT.
Z I L O G A L S O D O E S N O T A S S U M E L I A B I L I T Y F O R I N T E L L E C T U A L P R O P E RT Y
INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR
TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. The information contained within this
document has been verified according to the general principles of electrical and mechanical engineering.
Z8, Z8 Encore!, and Z8 Encore! XP are registered trademarks of Zilog, Inc. eZ8 is a trademark of Zilog,
Inc. All other product or service names are the property of their respective owners.
AN025404-0608
14
Page 14 of 14
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising