Abstract: This paper presents the development environment, typical embedded microcontroller hardware and software structures, and design methods for intelligent sensor embedded controllers. It also briefly introduces signal processing methods for intelligent sensors and finally provides some widely used embedded microcontroller chips. Keywords: Embedded microcontroller, intelligent sensor, signal processing. In intelligent instrument applications, on-chip microprocessor controllers have been widely used. These microcontrollers are mainly developing towards single-chip miniaturization, high cost-effectiveness, and large size. In particular, the emergence of single-chip microprocessors with on-chip program memory, data memory, and various I/O interfaces has changed the traditional design methods of intelligent instruments. The inherent intelligence of sensors provides greater flexibility for modern instrument design. Some microcontrollers integrate A/D and D/A converters, communication interfaces (SPI, CAN, etc.), and non-volatile memory for storing calibration parameters. Applying such microcontrollers to sensors not only provides numerous additional functions and convenience for users but also reduces the effective space of the system. Compared to the amplifiers, resistors, and A/D converters used in general system designs, these microcontrollers offer a more competitive performance/price ratio (their A/D and D/A functions, communication interfaces, and program memory can save more hardware costs). For example, proximity sensors have crucial applications in robotic manipulators. Their linearity is a major limiting factor in their application. Generally, infrared proximity sensors exhibit significant nonlinearity in input and output, and are temperature-dependent. While converting these signals to standard input signals for A/D converters using conventional analog circuit design methods is functionally possible, consistent performance is difficult to maintain. More importantly, this approach increases hardware costs in some situations, as the larger size may not meet practical requirements. For instance, proximity sensors used in aerospace robots have strict requirements regarding size and signal stability. Using an embedded microcontroller, however, allows for the storage of calibration data in a data memory. It also allows for correction of temperature effects using mathematical models, and the measurement results (distance) can be directly transmitted to a host computer via an interface. Comparing the two methods, the latter undoubtedly saves space and offers superior performance, while the cost is comparable, effectively reducing host computer processing time. The following discussion addresses some issues encountered in practical applications. 1. Embedded Microcontroller Hardware Structure Figure 1 shows a typical block diagram of a microcontroller. Unlike general microprocessors, it integrates program memory, data memory, and various input/output interfaces onto a single chip, while general microprocessors require external memory and expanded I/O interfaces. Its basic structure is as follows: CPU—The central processing unit of the microcontroller is relatively simple, generally using a reduced instruction set and lacking advanced operation functions such as floating-point arithmetic. The general-purpose arithmetic unit (ALU) can perform arithmetic and logical operations between working registers and file registers, operating with 8-bit integer data. In general sensor applications, complex data processing is not required, and this simple and inexpensive microcontroller provides a good solution. Data Memory—Composed of general-purpose registers and special-function registers. Compared to the kilobyte-sized storage space of general microcontrollers, the storage units of microcontrollers are smaller, only 256 bytes or even less. Due to its small size and simple addressing, it is often used as the file register of the microcontroller. Some microcontrollers use these registers as EEPROM or flash memory to store calibration data and general constants. Program memory – used to store the running program. Microcontrollers typically employ a special structure to separate program memory and data memory. Compared to the traditional von Neumann architecture where program and data memory are in the same space, this structure is much faster, allowing the processor to acquire data while fetching commands. This structure also allows for different widths for the data memory and program memory; the latter can use a wider structure for higher encoding efficiency. Its space is generally measured in kilobytes (K). I/O ports – used to provide numerical input/output channels for exchanging data with the outside world. Besides sampling status flags, these ports can be programmed to exchange data with A/D or D/A converters, or to communicate with other microcontrollers. Timer/counter – its function depends primarily on the corresponding register settings. As a counter, it can count changes in external states or frequencies; as a timer, it can be used to time external events or control the microprocessor's periodic operation. For example, if no events occur within a certain period, a watchdog timer can periodically reset, a function clearly useful for intelligent sensors. A/D Converter – Most microcontrollers have an internal 4-8 channel A/D converter, allowing a single microcontroller to simultaneously connect to multiple sensors and perform signal processing. Early microprocessors primarily used 8-bit A/D converters, but now 10-bit or 12-bit precision microcontrollers are more common, providing users with greater choice. Communication Interface – For different applications, current microcontrollers can provide different communication protocols, such as SPI, I2C, or network interfaces like CAN and USB. 2. Software Design Modern microcontrollers can integrate a large amount of hardware, greatly facilitating users. In the design of intelligent sensor applications, it can be used simply as a component, inputting analog signals and outputting numerical signals. However, in the intelligence of sensors, the hardware actually accounts for a negligible proportion; software is the main factor in increasing sensor functionality and adding value. When using embedded microcontrollers to process data in real time in sensors, the software structure differs from that used in general PCs; the former is much simpler. The main function of a microcontroller in a sensor is to read the input signal, perform simple data processing, and then output the result. These functions are implemented using three main structural methods: • Sequential method • Interrupt method • Multiple selection method. Sequential method—its working principle is shown in Figure 2. This method is relatively simple and suitable for repetitive tasks. The microcontroller first reads the sensor's output, processes the data, outputs the result, updates internal variables, and then returns to restart the process (Figure 2(a)). Clearly, this method repeatedly runs in a certain cycle, wasting machine time. When the input remains unchanged, this processing method reduces the sensor's reaction speed. It can be changed to the structure shown in Figure 2(b), where if the input remains unchanged, the output remains unchanged; only when the input changes is the corresponding processing performed. This effectively improves the efficiency of the output-input response. Interrupt method—this is a common method used by various CPUs to handle events. When applying embedded microprocessors to sensors, interrupt mode can also be used to implement process control and processing. This processing method is commonly used in multi-sensor systems. Here, the microcontroller uses the above method to process data sampled from some sensors in a loop, executes the main program, and executes the corresponding task when the state of a sensor changes (e.g., exceeding a certain threshold). For example, in a smart multi-sensor system using real-time temperature compensation, when the temperature changes, the functional relationship between input and output changes, requiring the corresponding compensation coefficient to be obtained through a lookup table, which can be achieved through an interrupt. In a multi-processor system with upper and lower level computers, communication between them can also be achieved through interrupts to achieve timely data exchange. When an interrupt occurs, the processor saves the data in the registers to the stack, prioritizes the execution of the interrupt function, and returns to the breakpoint to restore the context and continue the original program after the interrupt routine is completed. Of course, the implementation of this interrupt method depends on the processor's hardware architecture. The interrupt method is generally used in situations where smart sensors need to communicate and execute special functions at regular intervals, making the software structure simple and easy to implement. See Figure 3 for the specific program flowchart. Multiple selection mode—In a smart multi-sensor system, when the input changes, the corresponding function needs to be executed. The more input states, the more output options there are. For example, currently used fuzzy logic washing machines widely employ microcontrollers to determine various input conditions (the amount of clothes, the degree of dirt, etc.) and provide corresponding control strategies. In reality, this function can be directly implemented using intelligent sensors. The flowchart for the multi-selection method is shown in Figure 4. The output result is determined by the input changes and the current state. Mathematically, this can be represented as: State_next = F(State_present, Input); Output = G(State_present, Input); where functions F(X,Y) and G(X,Y) represent the state change logic and the correspondence between output and input. In embedded microprocessor microcontroller systems, a lookup table method is generally used to obtain the corresponding data. As can be seen from the flowchart, this method conforms to structured programming design and is relatively easy to implement in software. In fact, in some more complex processes, the above three methods are often combined. The use of these three methods in embedded intelligent multi-sensor systems is mainly determined by the characteristics of the embedded microprocessor itself. Factors such as the inability to implement floating-point operations, the use of a reduced instruction set, and limited data memory space require a simple program structure that is easy to implement. 3. Development and Implementation Currently, there are many development tools supporting microcontrollers, and manufacturers generally provide corresponding technical support. Below is a brief introduction to the Picstart Plus development toolkit provided by Microchip, including the corresponding hardware, interfaces, datasheets, and the MPLAB IDE development software. It enables programming, debugging, writing, and simulation of PIC series microcontrollers. Its software development environment supports operation under Windows, making debugging simple. Since embedded microcontrollers generally use a reduced instruction set (RISC), programming is greatly facilitated. The system simulation function allows developers to step through the program and monitor intermediate results in registers, observing the program's execution process. The only drawback of this development system is that it cannot directly simulate the system like a typical microcontroller system. When a microcontroller is embedded in a sensor system, simulating its operation is relatively difficult. However, this can be addressed by improving the simulation system. An interface can be designed between the PC and the designed embedded system, connecting the microcontroller's installation location to the simulator to achieve system simulation. 4. Sensor Data Processing Generally, microcontroller systems handle sensor data processing relatively simply, using an A/D converter to sample the sensor data. Due to their powerful computational capabilities, functions such as linearization, filtering, and thresholding are relatively straightforward. However, when using a microcontroller, these functions require more specialized processing methods. 4.1 Linearization Linearization is a common problem in sensors. By processing the sampled data from the microcontroller, nonlinearity can be eliminated. This can generally be achieved through two methods: 1. Lookup Table Method—Pre-calibrated experimentally, the sensor's A/D sampled input is compared to the actual value, and the result is stored in memory. For each input, a corresponding output is obtained by looking up a table. For example, the PIC74** includes an 8-bit A/D converter, which can directly obtain the actual result through a linked list of 256 input/output groups. The A/D converter's input is equivalent to the pointer entry address of the linked list. This method is based on extensive experimentation and is relatively simple. For example, infrared proximity sensors and temperature sensors can achieve linearization using this method. When the A/D converter has high precision, such as the PIC16C773 and PIC16C774 A/D converters with 12-bit precision, 4096 address spaces are needed to store the corresponding table. Internal interpolation method - When memory space is limited, the interpolation method can be used to realize the linearization of the sensor. The sampled curve is regarded as a series of nodes connected by straight lines. Therefore, only the beginning and end data of each node need to be stored, which greatly saves storage space. The specific implementation method is as follows: (1) Sample and obtain the sensor input value x; (2) Determine the node position n where u is located; (3) Read the node input and output values Xn, Xn+1, Yn, Yn+1 of the corresponding node; (4) Calculate the output result Y Y=Yn+(X-Xn)Kn Kn=(Yn+1-Yn)/(Xn+1-Xn) The slope ratio of each node can be pre-stored in the microcontroller and obtained by looking up the table to improve the calculation speed. 4.2 Selection of Filtering Method Data acquired from an A/D converter undoubtedly contains external interference, which needs to be removed through filtering. A relatively easy method to implement in a microcontroller is the moving window filtering method. Specifically, a certain window value is set, for example, 3 to 8 data points are grouped together, and the average value is taken. When the data acquired by the sensor changes rapidly, such as 1/3 to 1/5 of the sampling frequency, a smaller window value (3 to 5) is more ideal. When the data acquired by the sensor changes slowly, a larger window value is more likely to achieve a better filtering effect. Currently, the on-chip microcontrollers commonly used in embedded intelligent sensors mainly include the following types. The MORTOROLA 68HC908GP20 includes 33 bidirectional I/O ports, interrupts, SCI/SPI serial communication ports, a timed watchdog, and in-system programming capabilities. Microchip's PIC series microcontrollers, in addition to some of the similar functions mentioned above, also offer a 12-bit precision A/D port (PIC16C773 and PIC116C774), making them very convenient to use. PIC series on-chip microcontrollers are currently widely used in China. CYPRESS SEMICONDUCTOR's COP684BC/COP8844BC have CAN interface functionality. Other companies providing these types of microcontrollers include Zilog, Digi-Key, and Atmel. In conclusion, embedding on-chip microcontrollers into sensors greatly enhances the intelligence and practicality of sensors, providing new ideas for intelligent sensor design. The standardized interfaces they offer greatly facilitate sensor usage.