Design of a Portable Multi-Parameter Environmental Monitoring Instrument
2026-04-06 03:30:47··#1
Abstract: This paper introduces a multi-parameter environmental monitoring instrument based on the MSP430 series ultra-low power microcontroller, and elaborates on the selection of environmental parameter sensors, the design and implementation methods of the monitoring instrument's hardware and software. This instrument fully utilizes the resources of the MSP430 microcontroller, possessing advantages such as small size, portability, high performance, low power consumption, and programmability, and can be widely applied to environmental parameter monitoring and protection in many fields. Keywords: MSP430 microcontroller, environmental parameter monitoring instrument, low power consumption. This paper takes intelligent buildings as its application background and introduces a highly versatile portable multi-parameter environmental monitoring instrument. It uses the MSP430F437 ultra-low power microcontroller as its core and is equipped with a new type of miniature low-power sensor to realize the functions of collecting, processing, storing, and communicating parameters such as temperature, humidity, illuminance, and harmful gas concentration inside buildings. The paper elaborates on the sensor selection, hardware structure, software flow, and other related technologies, and points out the characteristics and advantages of the instrument. 1 Sensor Selection The sensor is a key component that determines the accuracy of the monitoring instrument. The selection of sensors is mainly based on factors such as the working environment, measurement accuracy, linearity, interchangeability, sensitivity, response speed, stability, power consumption, size, and ease of interfacing with an MCU. The sensors selected for this monitor are: the integrated temperature sensor TMP35, the integrated humidity sensor HM1500, the hot-wire semiconductor gas sensor MR511, and the integrated illuminance sensor TSL253. Compared with similar products, they have certain advantages in the above aspects and are well-suited for portable instruments. The voltage output of TMP35 is linearly related to the measured temperature T, as shown in equation (1); the output of HM1500 is voltage, which is proportional to the measured humidity %RH and related to the temperature T, as shown in equation (2); MR511 has internal temperature compensation, and its output voltage is approximately linearly related to the measured gas concentration C (linearity ≤ ±5%), as shown in equation (3), where Nc is the device sensitivity and the ambient humidity Vc value has an impact; the voltage output of TSL253 is proportional to the measured illuminance Ee and related to the temperature T, as shown in equation (4), where Ne is the sensor sensitivity, etc. VT=[10×T](mV) (1) VRH=[600×(%RH+38.5)/(39.1-0.056T)](mV) (2) Vc=[Nc×C](mV) (3) Vec=[(Nc×Ee) ×(1.05-0.002T)](mV) (4) The above formulas show that high-precision monitoring must consider the nonlinearity of the sensor, the influence of temperature and humidity, measurement error and environmental error, etc., and especially focus on solving the nonlinearity and temperature and humidity compensation in the measurement. When arranging the printed circuit board, try to reduce the lead resistance and distributed capacitance to reduce the measurement error. In the circuit design, add linearization processing circuit and temperature and humidity compensation circuit, or use a microcontroller system to process and correct by software lookup table and other methods (using software to realize the sensor calibration and compensation function can reduce the power consumption of the instrument). If possible, use a standard measuring instrument for calibration to improve the measurement accuracy. 2 Hardware Design The monitoring instrument is mainly composed of MSP430 microcontroller, measurement conversion, keyboard display, serial communication, battery power supply and other parts. There are very few components in the circuit, the power consumption is low and the functions are powerful. The specific hardware circuit schematic diagram is shown in Figure 1. 2.1 MSP430 Microcontroller The microcontroller system is the core of the monitoring instrument. It completes the functions of instrument setting, measurement object selection, signal processing and storage, status information display, data communication and other functions. Compared with MCS51, MCS96 and PIC[1] series, TI's MSP430F series ultra-low power microcontroller with flash memory has a great advantage. MSP430F microcontroller has a variety of models, and its functional combinations are different, which can meet the requirements of different application occasions. This design uses the MSP430F437, whose main features[2] are as follows: Low operating voltage (1.8~3.6V), small current (280μA/1MHz/active mode), 5 low power consumption modes; 16-bit RISC architecture, 27 simplified instructions, 125ns instruction cycle; Rich interrupt sources that can be nested arbitrarily, and it only takes 6μs to wake up the system from standby state using an interrupt request; On-chip watchdog and power-on reset circuit, selectable clock source (XTAL1, XTAL2 or internal DCO); Internal comparator A with interrupt function; Bidirectional parallel I/O ports P1 and P2 (with interrupt function) and P3~P6 ports, most of which have multiplexing function; Two 16-bit timers A and B, each with 3 compare/capture modules, each of which can be independently programmed to generate timing pulses and capture external events; On-chip integrated 4×32 segment LCD liquid crystal driver, whose external leads are multiplexed with P3~P5 ports; The MSP430F437 features a general-purpose communication module (UARST0) with selectable synchronous/asynchronous software modes; an 8-channel 12-bit ADC12 with automatic cyclic acquisition, built-in sample-and-hold circuit, and selectable voltage reference; a JTAG interface or on-chip BOOT ROM simplifies program downloading and debugging, and the program code is protected by safety fuses. The MSP430F437 requires no additional memory, as it includes 1KB of on-chip RAM and 32KB of in-circuit erasable programmable main Flash + 256 bytes of information Flash. The on-chip Flash module contains three control registers, a timing generator, an erase/program voltage generator, and the Flash memory itself. The main Flash is divided into segments 0-63, each 512 bytes, and the information Flash is divided into segments A and B, each 128 bytes. The MSP430F437's memory can accommodate large-scale tables and features an efficient lookup table processing method. This monitor is configured with sections 0-23 for program code, section 24 for the LCD display character table, sections 25-31 for storing calibration and compensation tables, sections 32-63 for storing user-acquired data, and sections A+B for storing various parameters. In the circuit, the functions of other main modules are allocated as follows: the 16-bit Timer A's compare/capture module 0 implements hour, minute, and second timing; the compare/capture module 1 controls the A/D sampling period; the 16-bit Timer B can implement PWM output and is reserved as a control port; ADC12 is used for environmental parameter measurement; comparator A is used for battery undervoltage monitoring; P3-P5 ports are used to drive the LCD display; the general communication module UARST0 implements RS485 serial communication; and a JTAG interface is reserved for user upgrades. 2.2 Measurement Conversion The MSP430F437's ADC12 conversion module features high speed and versatility, and its 12-bit conversion accuracy ensures the resolution requirements of general sampling. Its eight external analog sampling channels can be configured arbitrarily. The conversion reference levels VR+ and VR- can come from internal or external sources, or a combination of both. The embedded sample/hold circuit provides users with various options for the sampling timing. The sampling timing can be directly controlled by software bits, three internal or external signals. The ADC12 has four operating modes. It can perform single or multiple conversions on a single channel, single or multiple conversions on a sequence channel, and single or repeated conversions on a sequence channel. For sequence channel conversion, the sampling order is completely defined by the user. The ADC12 conversion results are stored in 16 conversion storage registers ADC12MEM0~ADC12MEM15. Their values are as shown in equation (5): NADC=4096×(Vin-VR-)/(VR+-VR-) (5) Each storage register has its own corresponding control registers ADC12CTL0~ADC12CTL15, and the sampling channel number and the reference level required for conversion can be configured independently by software. In this monitoring instrument, the outputs of each environmental parameter sensor are preamplified by U2 and then sent to the analog input terminals A0-A3. The conversion reference voltages for the four signals are VR+=2.5V and VR-=0V. The ADC12 operating mode is set to single-transformation of the sequence channel, with each conversion initiated by the timing output OUT1 of the timer A compare/capture module 1. After a single-transformation of the sequence is completed, an ADC12 interrupt request is set. The sequence channels are ADC12MEM0-ADC12MEM12, and the corresponding control registers ADC12CTL0-ADC12CTL12 have channels A0-A3 repeatedly configured. In this way, each environmental parameter can be sampled three times continuously within equal time intervals, and then the conversion result is obtained by median filtering in the ADC12 interrupt service routine. It should be noted that the ADC12 conversion core and the reference level generator can enter power-saving mode separately, which facilitates low-power design and further reduces power consumption and extends the service life of the sensing elements. The power supply of the measurement circuit is set to be independently controllable, supplied by the output of OUT2 of U3, and switched through the P2.0 of the microcontroller. 2.3 Keyboard Display The MSP430F437 has six multiplexed I/O ports, P1 to P6, which are both dual and single I/O ports. When P1 and P2 are set as inputs, any change in the state of these pins will trigger an interrupt. In this design, P3 to P5 are multiplexed for LCD driving, and P1.0 to P1.4 are used as a 3×2 fast keyboard. To read the key values, the port functions are first configured: P1.0 to P1.2 are output ports, sequentially outputting low levels; P1.3 and P1.4 are input ports, with interrupts enabled and falling edge trigger selected. When a key is pressed, the interrupt service routine on port P1 performs debouncing delay, key value reading, and other functions, and the obtained key value is then processed by subsequent programs. The on-chip LCD driver can operate in four modes: static and 2 to 4 multiple-select modes, and can connect to a maximum of 4 to 32 = 128 segments of LCD. In Figure 1, pins R33, R23, R13, and R03 set the analog bias voltage, providing drive capability. A typical connection is a resistor divider: VR33 = VCC, VR23 = 2/3Vcc, VR13 = 1/3cc, VR03 = 0V. S0 to S31 are segment outputs (3μA per segment); COM0 to COM3 are common outputs connected to the LCD back electrode. The software control of the LCD is extremely simple. It has a control register LCDCTL that defines the operating mode and current consumption. Twenty display memories, LCDM (16 used), store 128 segments of status information to be displayed. The contents can be obtained by looking up the display character table using an efficient addressing method. Based on the commands from the control keys, the microcontroller can select the instrument's "measurement/communication" mode and "single/cycle" acquisition type, and can also perform functions such as key-based time calibration, parameter setting, starting acquisition, and data storage confirmation. The LCD display can be configured with 1×32 segments for customized, time-division, over-range, and low battery alarms. The remaining 3×32 segments are a multi-purpose display area, which can sequentially display operation prompts, working status, and environmental parameter measurement results, greatly facilitating users. 2.4 Serial Communication To perform in-depth processing of the acquired data (such as statistical analysis, printing and archiving, plotting graphs, etc.), the data needs to be sent from the detector to the computer. Data transmission uses the standard USART communication module of the MSP430F437 (reset SYNC=0 to select asynchronous function), and an external low-power device MAX485E is connected to form a half-duplex RS485 serial communication port. To improve communication reliability and facilitate networking with other intelligent devices to achieve control functions, this monitor uses an asynchronous address-bit multi-machine communication format. The asynchronous frame consists of 1 start bit, 8 data bits, 1 address bit, and 1 stop bit, with a baud rate programmed at 9600bps. The address-bit multi-machine communication protocol of the USART communication module is shown in Figure 2. During communication, the RS485 is first set to receive mode, and the receive wake-up interrupt enable bit URXWIE is set to 1 (at this time, only address characters can trigger receive interrupts). When a character at an address position is received, the receiver of the communication module is activated, the character is sent to URXBUF, and the receive interrupt flag URXIFG is set. Within the serial port receive interrupt service routine, the received address can be checked. If it matches, URXWIE is set to 0, and the microcontroller will read the subsequent data of the data block; if the address does not match, it waits for the next address character. After receiving a command from the host, the RS485 enters transmit mode, first setting the control character address bit TXWake to 1. When the 8 bits of the address character are transmitted from UTXBUF to the transmitter, the TXWake bit is loaded with the address of the character to be transmitted. After each character is transmitted, the TXWake bit is automatically cleared, triggering the transmit interrupt UTXIFG. Within the serial port transmit interrupt service routine, the user can send complete data blocks sequentially and then reset the RS485 receive mode. 2.5 Power Control This instrument uses a single 3.6V/4Ah lithium-ion battery. To ensure the accuracy of multi-channel power supply and analog signal measurement, a power control circuit based on the ADP3302AR1 dual low-dropout linear power regulator chip (U3) was designed to perform the following functions: Power On/Off. When the "ON" key is pressed, pin SD1 of U3 is at a high level, and pin OUT1 outputs the main power supply Vcc required by the instrument. A high-level interlock signal is sent from pin P1.5 of the microcontroller, ensuring that OUT1 maintains its output after the "ON" key is released. When the "OFF" key is pressed, pin P1.5 of the microcontroller outputs a low level, turning off the output of pin OUT1. Pin OUT2 of U3 outputs the 3V required by the analog measurement circuit. The measurement power supply can be switched on and off independently, controlled by the level of pin P2.0 of the microcontroller. Battery Voltage Monitoring. The load voltage of U3 should not be lower than 3V; otherwise, it will not function properly. The microcontroller's on-chip comparator A has multiple references; one is selected: 0.5 × Vcc = 1.5V. The positive terminal of the battery is directly connected to the comparator's input pin CA0 through a voltage divider resistor. When the battery voltage is lower than the set value, comparator A is interrupted. Within the interrupt service routine, the LCD alarm is displayed, prompting the user to charge the battery (using an external charging adapter). Automatic shutdown. After each test, if no further operation is performed, a timer is used to compare/capture 0 interrupts. After 5 minutes, the microcontroller's P1.5 pin sends a low level, and the OUT1 pin outputs 0V, thus cutting off the instrument's power supply and achieving automatic shutdown. 3 Software Design The software of the tester is written in MSP430 assembly language. To facilitate program scheduling and improve reliability, the software adopts a modular structure, mainly composed of an initialization program, a main program, subroutines, parameter tables, etc. 3.1 Software Functions and Features After the microcontroller system is powered on, it enters the initialization program to complete the initialization work such as setting up each on-chip module, clearing the LCD memory, and setting ports. Then it jumps to the main program, enables interrupts, cyclically sets the low-power mode, and performs no-operation. One of the features of this software design is the use of interrupt event-driven technology, which aims to reduce power consumption. After setting the LPM0 low-power mode (55μA) in the main program, the CPU is immediately disabled, the peripheral modules remain active, and wait for various interrupt events. If there is an interrupt, the CPU is woken up and executes various interrupt service subroutines to complete the event processing. After each interrupt service subroutine is executed and returned, the LPM0 low-power mode is reset in the main program and waits for the next interrupt event. This process is repeated so that the system can run at low power for most of the time. Another feature of this design is that the efficient table lookup function of the MSP430F437 is used to compile a nonlinear correction and humidity compensation table for gas concentration measurement, which greatly improves the program running speed and acquisition accuracy. The table is generated based on a limited number of data and obtained by curve fitting through Lagrange interpolation [3]. The specific steps are as follows: (1) Under the condition of 5%RH humidity, the digital result Nc corresponding to the ADC12 conversion storage register is measured at different gas concentration points C of a typical gas sensor. In the test, 10 concentration points were taken at equal intervals in the range of 10 to 300 ppm; (2) Using the curve fitting method and combined with the relationship (3), a continuous curve between the digital quantity Nc and the gas concentration C at 5% RH was fitted. After discretizing the curve at intervals of 1 ppm, it was stored in segment 25; (3) The above measurement and data processing process was repeated at humidity levels of 20% RH, 35% RH, 50% RH, 65% RH, 80% RH and 95% RH respectively, to form 6 nonlinear curves of Nc-C under different humidity levels, which were stored in segments 26 to 31. Note: When sampling the digital quantity Nc and the current humidity value, first look up the two curves corresponding to the humidity range, that is, use linear interpolation to get the upper and lower gas concentration values based on Nc, and then use linear interpolation based on the current humidity to get the final gas concentration value after humidity compensation. 3.2 Example of software process This detector has many programs. Due to space limitations, this section only introduces the distinctive Flash data storage program and the crucial ADC12 subroutine. The MSP430F437 allows for program download, debugging, and modification via the JTAG interface or on-chip BOOT ROM. It even allows user programs to quickly and securely save acquired and processed data to Flash memory during runtime, without any external devices. Data storage utilizes a fast segment write method and a byte sequence write mode, with low write current (3mA), high write speed (≤25ms/512 bytes, far exceeding the page write speed of serial EEPROM 5ms/16 bytes), 100,000 write cycles, and 100 years of data retention. After each acquisition and processing, 16 bytes/batch of data, "batch number-time-environmental parameters," are stored in segments 32-63. Figure 3 shows the flowchart of the 16-byte data storage program, where Lock, Busy, SEG, WRT, WRT, and Wait are the control bits or status bits in the Flash control register involved in programming. The ADC12 subroutine is used for environmental parameter measurement. When the measurement button is pressed or the sampling time expires, OUT1 of Timer A initiates a single conversion of the sequence channel. ADC12 automatically and cyclically acquires various environmental parameters in the sampling order of A0 to A3, and saves the conversion results to the storage registers ADC12MEM0 to ADC12MEM11. After the sequence conversion is complete, the ADC12 interrupt request flag ADCIFG is set.