Development of a high-performance portable PIC microcontroller humidity detector

Publisher:MysticJourneyLatest update time:2006-05-07 Source: 电子技术应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    Abstract: The development of a high-performance portable PIC microcontroller humidity detector is introduced, and the relevant working principles and key technologies are explained in detail. This tester makes full use of the PIC microcontroller's own software and hardware resources. It has the advantages of intelligence, small portability, and programmability. It is widely used in many fields such as agriculture, hydrological systems, environmental monitoring, and meteorology.

    Keywords: PIC microcontroller humidity tester soil moisture content

    Timely and accurate measurement of the humidity and soil moisture content of the surrounding environment is widely used in many fields of national economic development. For example, in agriculture, in order to manage soil scientifically, soil moisture content needs to be tested frequently; in water conservancy projects, such as Hydrological stations and dams also need to frequently test soil moisture content. In addition, soil moisture measurement is an indispensable measurement item in environmental protection, meteorology, and national defense construction. How to automate this tedious measurement and related data processing has become an important issue that needs to be solved urgently.

    This article introduces a high-performance, portable, programmable humidity tester mainly composed of PIC16C74 microcontroller, and explains in detail the working principle, basic functional block diagram, key technology and corresponding working software process of the instrument.

    1 Basic principle and functional block diagram of the instrument

    The system hardware structure block diagram of this instrument is shown in Figure 1. The chip uses the PIC16C74 microcontroller with low price and excellent performance. It makes full use of the software and hardware resources it provides and completes soil moisture detection with corresponding peripheral circuits. The main components include: humidity sensor, PIC microcontroller, external memory (E2PROM), touch keyboard, liquid crystal display (LCD), battery power on and off control circuit, and communication interface circuit for transmitting data to the computer.

    The sensor uses a patented product. Its function is to directly insert the detection head into the soil to be measured and convert the soil moisture into a corresponding analog voltage. The voltage range is 0~1.2V. The analog voltage is amplified to 0~5V by an operational amplifier. After the voltage is within the range, it is sent to the I/O port of PIC16C74. There are 8 channels of A/D converters in the microcontroller. Select one port as the analog voltage input channel, and then convert it into a digital voltage value according to the voltage-moisture content formula. , after the microcontroller calculation, the actual soil moisture content value is obtained, which is sent to the external extended memory for storage for transmission and processing, and at the same time, it is sent to the LCD screen for real-time display.

    This instrument sets each batch of data to consist of 16 bytes, and the external memory capacity is 64K bytes, so the maximum storage capacity of the external memory can reach 512 batches. In order to further process the measurement data, a large amount of data from each test point needs to be sent to the computer. To complete the data transmission, we choose the RS232 standard interface method, and the device uses MAX202 as the interface device. The data is sent to the computer through the I/O interface, and then It is further processed to draw test curves and charts, which are then analyzed, printed and archived.

    Due to the small size of the instrument, touch switches are used as buttons, which can complete functions such as power control (ON), measurement (MEASURE), page forward (UP), page back (DN), clear (CLEAR), and approval (ACK). Allow users to operate flexibly. The power supply is powered by a 9V standard battery, and a special power control circuit controls the power on and off. The PIC16C7 microcontroller monitors the battery power supply. When the voltage is within the normal working range, the LCD screen displays "H". When it is lower than the set standard voltage, it displays " L", indicating that the battery needs to be replaced.

    Because the tester we developed uses a high-performance microcontroller chip, it has abundant available software and hardware resources, requires fewer peripheral devices, has strong functions, has low power consumption, and has a wide range of applications.

    2 Key components and key technologies

    2.1 PIC16C74 microcontroller

    This instrument chip uses the PIC16C7 microcontroller produced by the American Microchip Company. This chip is a low-power, high-performance, affordable CMOS fully static 8-bit E2PROM single-chip microprocessor. It is 400IP and has an I/O port of 33 pins, suitable for installing more peripheral devices and equipment.

    The PIC16C7 chip contains 192 bytes of data memory (RAM) and 4K bytes of program memory (ROM) capacity, 33 output/input ports, three timers/counters, three capture/compare/PWM modulus and two serial ports , the synchronous serial port can be configured as three-wire SPI or two-wire 120 working mode, the serial port can be set as synchronous or asynchronous, and the eight-channel high-speed A/D converter part. In terms of software structure, it adopts RISC instruction structure, with an 8-level stack, multiple internal and external interrupt bits, and 35 instructions, making it easy to program.

    Compared with other microcontrollers (such as 8031 ​​chips), PIC16C7 has the following characteristics that other chips cannot match:

·It has 8 internal A/D conversion channels. This alone eliminates the need for additional A/D conversion peripheral chips when A/D conversion is required;

·There are only 35 software instructions, implemented through programming;

·Low power consumption, high-speed CMOS EPROM technology, only consumes 2mA at 5V 4MHz, and only 15mA at 3V 32KHz;

·More importantly, the chip has a sleep function, that is, it performs Sleep working mode. In this mode, the chip consumes very little (less than 1mA). When the chip needs to work again, the chip can be woken up through internal or peripheral interrupts. into normal working mode;

·With confidentiality function.

  2.2A/D conversion

    The PIC16C7 microcontroller has 8 analog input ports, sharing a sample/hold. The sample/hold is compared successively, and finally the analog quantity is converted into a digital quantity. For this tester, the input is the analog voltage sent by the sensor, and its value is Changes in the range of 0~1.2V, and the amplified voltage enters the microcontroller for A/D conversion and calculation processing. The A/D conversion circuit is shown in Figure 2.

    In addition, the analog reference voltage of the A/D converter is RA3/ref, and the pin voltage is +5v. When designing this circuit, the following work needs to be done:

·Accuracy calculation and error of A/D conversion

    Convert analog voltage 0~1.25vV into 8-bit binary digital, whose 1LSB=1.25/256=4.9mV≈5mV, when VDD=5V±10%, and Vref=5v, the full range of A/D conversion The accuracy is less than 1LSB, which includes offset error, full-scale error, and integer error, and the A/D conversion is monotonic.

    Since VDD is less than 5V or Vref is less than VDD, the resolution and accuracy will be reduced, so we adopt the following two measures in the design. One is to use VDD=5V, and Vref==SV; the other is to amplify the input through an operational amplifier to make the input analog The voltage changes within the range of 0~5V.

· Requirements for input analog signals

    The analog input needs ESD protection, so a reverse bias diode is added between VDD and VCS to protect the device from damage. At the same time, it is required that the external device connected to the analog input pin should have extremely low leakage current.

·A/D sampling requirements

    For A/D conversion to achieve a specific accuracy, the input channel voltage needs to fully charge the holding capacitor. The formula is: sampling time = amplifier stabilization time + holding capacitor charging time + temperature coefficient, which can be obtained.

·A/D conversion clock selection

The clock is selected as 4MHz.

    2.3 Keyboard control

    PIC16C74 has five I/O ports PORTA ~ PORTE. PORTE is a bidirectional port. The four pins RB (4 ~ 7) of port B. When the pins are set to input mode, the status of these four pins changes. will cause an interruption. Utilizing the characteristics of the B port, it is easy to interface with an external control keyboard. This instrument is designed with a 2×4 keyboard with a total of 8 control keys. The keyboard control circuit is shown in Figure 3. In order to sample the keyboard, first prohibit the digital current sink, and then use software to set port B so that RB4~RB7 are input terminals and RB2~RB3 are output terminals to high level. Allow the pull-up of RB4~RB7, make RB2~RB3 low level in sequence, and detect RB4 to RB7 at the same time to see if there is a keystroke (low level). Each scan will find multiple keystrokes. Once a keystroke is detected key, before restarting keyboard sampling, after a 40ms debounce time, no other keystrokes will be detected until the current key is released.

    2.4 LCD display

    The tester displays the LCD display EDM-1601A, which can display 16 ASCII characters at the same time. Each character consists of a 5×7 dot matrix. The internal control circuit of this device mainly consists of an instruction register, a data register, an address register, and a display It is composed of data register, character generator and timing generator. The display screen of this instrument is shown in Figure 4.

    Position 0 displays the battery voltage status. When the battery voltage is >7.5V, "H" is displayed to indicate that the battery voltage is normal. When the battery voltage is <=7.5V, "L" is displayed, indicating that the voltage is too low and the battery needs to be replaced. Digits 1 to 3 show the number of test batches. This tester can test up to 512 batches of data. Position 4 is a space. Digits 5 to 10 display the voltage value of the measured point, in millivolts (mV). The numbers from 11 to 15 show the moisture content percentage of this test point.

    Each time the measurement key is pressed, the relevant voltage value of the test point and the converted water content value are displayed, and these values ​​are simultaneously sent to the external memory for storage.

    2.5 Serial communication

    In order to conduct in-depth analysis of the collected data, the data needs to be transferred from the external memory of the tester to the computer. PIC16C74 has a serial communication interface (SCI). SCI is a full-double interface that can communicate with peripherals such as CRT terminals and computers. Industrial asynchronous system, this instrument adopts RS-232-C interface mode, and the transmission baud rate is 9600 bits. The data transmission format is shown in Figure 5. In this way, SCI uses the standard non-return to zero (NRZ) format, starting with a start bit, represented by a logic "0", followed by 8 data bits, and finally It is a stop bit, represented by logic "1". This instrument does not have a parity bit, so the length of data transmitted at one time is 10 bits. The interface chip is MAX232, and the receiving end (computer) uses receiving software edited in C language to display the received data and perform further processing, such as summarizing it into a data table, drawing analysis curves, and printing results, etc. for the staff. refer to.

    2.6 Power control

    This instrument is powered by a standard 9V dry battery. In order to ensure normal power supply, the power supply needs to be controlled in the following three aspects.

·To control the power on and off, press the ON key on the keyboard, and the 9V voltage will be output through the MAX667 (MAX company) to provide the 5V voltage required by the instrument;

·Battery voltage test circuit, assuming that the standard 9V dry battery is lower than a specified voltage under loading, the instrument cannot work normally and the battery needs to be replaced. To achieve this purpose, the battery voltage needs to be continuously monitored;

·Automatic shutdown function: After the test is completed, if the instrument is not operated, the power circuit will automatically disconnect after one minute to realize the automatic shutdown function.

    The above three types of control are all completed by the MAX667 device, and the specific circuit is shown in Figure 6.

    3. Control software design of detector

    This detector is programmed in PIC16CXX assembly language. The control software consists of main control program, key function detection, measurement and moisture content calculation, display, clearing, forward and backward page display, communication and other subroutines. Figure 7 is the control software block diagram.

    4 Characteristics and development prospects

    The basic features of this testing instrument are:

·Small size, 150×80×60mm3, can be carried in your pocket to various test points for data sampling;

·Large amount of data collected: due to the addition of external E2PROM memory, 512 batches or 1024 batches of data can be sampled, calculated and stored;

·Through the communication interface, the collected data can be sent to the computer for further processing, such as drawing test curves, analyzing, printing results and storing data;

·It is powered by a 9V dry battery. In order to reduce power consumption and extend the use time, the instrument is controlled by a special control circuit. It will automatically shut down after a certain time. During the measurement interval, it enters the sleep state to save energy. Other devices try to use CMOS low-power and low-current devices;

·The instrument is intelligent and programmable. Due to the use of advanced microcontroller, A/D conversion and various mathematical calculations can be performed inside the microcontroller. Through software programming, data can be viewed (pages forward and backward), data in external memory can be cleared, and data can be transferred to the instrument. The computer sends data, and these functions can be selected through the corresponding buttons on the instrument panel.

    To sum up, this tester makes full use of the software and hardware resources of the PIC16C74 microcontroller, and has the advantages of intelligence, small portability, and programmability. In addition, this tester only needs to replace the sensor and modify the control software to expand to other environmental parameters. Testing applications make this tester widely used in agriculture, hydrological systems, environmental protection, meteorology and many other fields.

 

    references

    1PIC16C6X/7X/8X microcontroller application manual. Wuhan Liyuan Electronics Co., Ltd.1996

    2 "Principle of PICC16CXX series microcontroller". Wuhan Liyuan Electronics Co., Ltd.1997

    3 Compiled by Wang Shiyuan and Wu Zhifang. 1BM PC/XT (Great Wall 0520) interface technology and application. Tianjin: Nankai University Press, 1991

(Date of receipt: 1999-06-23)

 

 

 
Reference address:Development of a high-performance portable PIC microcontroller humidity detector

Previous article:Automobile fault self-diagnosis system and fault diagnosis instrument V. A. G1551 Research
Next article:Measurement of the flatness of piano key arrangement

Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号