Digital Scale

Nikola Kuzmanovski

Overview

This project is rather experimental. The device is intended for measuring weight of objects put on it. The weight range is 0 - 1.5 Kg.

Hardware

This device uses the C8051 8-bit micro-controller from Silicon Labs. The C8051 has a built in ADC on it which is used to read input from the weight sensor. The weight sensor acts as a resistor and is also connected to the programmable current reference. The resulting voltage drop is then read from the ADC on the micro-controller.

Schematic Device view

The ADC value is then converted and displayed on the 4-digit (4x8) segment LCD.The weight sensor is glued to one acrylic plate. On top of that another acrylic plate is placed to make the sensor act as a scale. They make a sandwich with the sensor between the two plates. There is also a button for starting the device. The entire device is powered by a coin battery which supplies 3 volts and is placed in a plastic box.

Board top Board with LCD Board bottom

Software

Written in assembly. The micro-controller is put to sleep and stays in sleep mode until the button is pressed. When the button is pressed a port match interrupt occurs. When this happens micro-controller wakes up from sleep, services the flag, turns on the LCD and starts measuring the voltage output from the weight sensor.

The ADC is configured to 12-bit mode and accumulation of 4 conversions. One measurement of the ADC is done by starting the current reference and waiting until it powers up. After this is done the conversation is started and the micro-controller polls the BUSY flag which is set when a conversion is done. When the flag is set the value measured from the ADC is stored into internal registers. However the program measures an average value of collected values measured by the ADC. This is done by using a circular buffer data structure. Informally, the circular buffer in this program stores the conversions of the ADC and has a pointer that points to the first conversion done out of all of the conversions stored in the buffer. This way when a new conversion is done this "first" conversion is replaced by the new one and the pointer is incremented. Hence we have multiple conversions of the weight that keep updating. This way if the sum of all the conversions is calculated every time a new conversion is done and an average can be calculated by just dividing the sum by the number of elements the buffer stores.

The above process is done in a loop as long as the micro-controller is not sleeping. There is one more thing done in the loop after a measurement is done and that is displaying the number to the LCD. For this to be done first the average presented in binary is converted to 4 separate digits in binary. After this is done the way the numbers should be displayed is retrieved from a table made specifically for the LCD. This algorithm also checks if the number to be displayed is 1-digit, 2-digit or 3-digit to display blanks in the unused spaces.

After about 2 minutes the loop stops and the micro-controller goes back to sleep until the button is pressed again.

Downloads


Last modified:Mon, Jan 23, 2023.

00006