Microcontroller selects minimum/maximum value
By Abel Raynus, Armatron International, Melrose, MA -- 9/20/2001
Microcontroller-based systems for measurement, sensor-data processing, or control, sometimes require you to determine a maximum or minimum data value. For example, in an object-detection system, such as a radar or sonar system, the microcontroller receives echo signals from multiple targets and then must select the closest one; in other words, it must determine the minimum distance. Another example is an automatic-tuning system in which the microcontroller acquires data and must determine the maximum or minimum values of the data. A simple way to determine maximum and minimum value involves a microcontroller, IC1, that receives a set of data from N sources (Figure 1). The data should be in 8-bit format. To simplify the process, consider that the data are 1-byte-long integers. In other words, the data cover the range 0 to 255. In most cases, this range produces satisfactory results. The same limitation applies to the number of data sources. If you need more data precision or more data sources, then you can use two or more bytes at the expense of added program complication. Two approaches exist for the maximum/minimum values. In the first, the microcontroller memory collects the received data and processes the data to determine maximum or minimum values (Figure 1a). In the second approach, the microcontroller processes the data immediately after receiving it (Figure 1b). Listing 1 shows the program for the first approach. Assume that a data array with N=8 exists in the microcontroller's memory. For demonstration purposes, Listing 1 illustrates this part of the routine in lines six to eight and 17 to 21, in which the controller loads the data registers from a predetermined table. In a real situation, you would load the data registers from data sources before calling the program. The process of minimum-value detection is based on a method called "the bubble." The search algorithm starts testing the memory data array from its end. It clears the index register (X) after completion of the program. If you need to detect the maximum instead of the minimum value, you need change only one instruction in line 28.
Is this the best Design Idea in this issue? Vote at www.ednmag.com.
© 2009, Reed Business Information, a division of Reed Elsevier Inc. All Rights Reserved.

