circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

June 2006, Issue 191

Measurement System for Weight and Dimensions
Renesas M16C Platform Design Contest 2005


FIRMWARE

I developed the firmware with Renesas’s high-performance embedded workshop (HEW), which came with the SKP16C62P board. Several code samples from the kit proved to be extremely useful, especially the code for the serial I/O and LCD.

The Weasure firmware first initializes the MPU, the I/O ports used, the UART, and the timers. It then enters the main loop that updates the display based on input from the size and weight measurements.

The size measurement process works with three arrays of port bit IDs, one for each measurement axis. Each array slot represents a photocell with the port number in the top four bits and the bit of that port in the lower three bits. These slots correspond to the photocells on the measurement axis.

To measure a length, the firmware starts at the end of the array and works its way down, examining the value on the port’s bit for each consecutive slot. When it finds a zero value (indicating a lit photocell), the array position indicates the length for that axis.

An ISR for timer B4 is used to measure the pulse width of the scale’s PWM output. The timer is configured to invoke the ISR every time the input changes state. By recording the timer’s count on positive transitions, the weight-dependent pulse width is measured. This ISR averages every four measurements to filter the values and give a stable result. When an averaged result is complete, a flag is set, indicating that the weight reading should be updated in the LCD. If no signal transitions are found (i.e., the timer overflows), the scale is presumed to be off and an “off” message is displayed.

Finally, another ISR listens for data on the serial port. This feeds back the Weasure data according to a simple protocol. An s command byte returns the height, weight, and depth in inches as integers (e.g., “05,12,17”). A w command byte returns the weight in pounds and ounces (e.g., “08,12”). A c command byte returns the same information as the w command along with the raw PWM count. This protocol makes it easy for a PC to query the Weasure for automated shipping applications.

The excellent Renesas HEW tools made software development a straightforward process. It was easy to modify the supplied examples to fit this application. The interactive debugger worked great too. I had no difficulties implementing the firmware.