Design of lower computer for temperature measurement system based on AVR USB interface

Publisher:快乐家庭Latest update time:2013-12-12 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

0Introduction

In recent years, with the continuous development of integrated circuits and chip manufacturing technology, different USB communication chips have emerged. At present, typical USB communication chips include CH375, PDIUSBD12, etc. These devices are characterized by powerful functions, but high prices, and are difficult to use in the development of medium and low-priced products. The AVR USB technology uses the IO port of the AVR microcontroller with a high-performance 8-bit RISC architecture to simulate the USB communication port, and implements the USB communication protocol by software to simulate the ordinary AVR microcontroller into a USB low-speed device, thereby realizing the communication and control between the AVR microcontroller and the computer. Although this method can only achieve low-speed transmission, it is sufficient for systems with a small amount of commonly used data, and its speed is much higher than the traditional serial port transmission speed, so it has broad application prospects in product development. This article uses AVR USB technology to achieve the measurement and display of temperature.

1 System lower computer software process

The lower computer software design and implementation can be based on the WINAVR programming environment, and the code can be implemented using C language. The AVR microcontroller mainly completes two functions: temperature measurement and data transmission. Temperature measurement mainly samples the voltage signal to determine the discrete value of the temperature. Data transmission is to transmit the measured data to the PC through the USB port simulated by the AVR so that the PC can display and process the data. The main process is shown in Figure 1.

2. Implementation of software functions

2.1 Temperature data collection

ATmega8 contains a 10-bit successive approximation ADC. This ADC can be connected to an 8-channel analog multiplexer to sample 8 single-ended input voltages from port C. The single-ended voltage input is referenced to 0 V (GND). The timing diagram of AD conversion is shown in Figure 2.

For continuous AD data collection, the query method and the interrupt method can be used. The program uses the interrupt method, that is, an interrupt is generated after an AD conversion is completed. When designing, the following function can be used to collect voltage values:

First, define a global variable Value to store the measured temperature value and use the value as the send value of the USB port.

2.2 USB Data Transmission

In order to use ATMEGA8 to simulate "soft USB", the file configuration folder USBDRV of AVRUSB should be placed in the source file directory in WINAVR. In this directory, the files required for programming are listed in Table 1.

This design can reduce the amount of code by only configuring the content of usbconfig.h. Its main parameter configuration is listed in Table 2.

Generally, each USB device has a PID and VID. VID is the manufacturer's code, and PID is the product's code. Each code is a two-byte integer. PID and VID cannot be set arbitrarily. They are assigned by the USB Standard Association (0x16C0, 0x05DC), and in the user configuration file, the principle of low bits first and high bits last must be followed.

2.3 USB data transmission interface function

(1) Initialization function

Before using AVRUSB, you usually need to initialize the USB port by calling the initialization function usbInit(). Before calling this function, considering that the program may jump from other program segments, you usually need to reset the USB port before initialization. Resetting only requires lowering the level of the D- and D+ ports. The following statement can be used to achieve the above function:

DDRD=0x14;PORTD=0x00;

Usually, the function usbInit() can be called after the other parts of the program are initialized, and finally the sei() function is called to enable interrupts. The implementation code in the main.c file is as follows: [page]

(2) Event processing function

The main loop of the user program needs to call the USB event processing function usbPoll() regularly. The USB event processing function usbPoll() will return directly when there is no USB event to be processed, otherwise it will call the internal function to perform the corresponding event processing, and finally pass the data to the user interface function. The usual method is:

The timeout period of a USB communication is 50ms. Therefore, when programming, you should pay attention to other events not taking up too long to prevent the usbPoll() function from being executed in time.

(3) Event interface function

In the user program, you need to write the USB user event interface function to complete USB communication. AVRUSB simplifies the user interface into the following three functions:

The above three functions require user programming and they will complete the data processing of USB communication.

In order to optimize the code, this system only uses the usbFunctionSetup function and shields the usbFunctionWrite and usbFnctionRead functions by setting the corresponding bits in usbconfig.h to 0 or 1 (see Table 2).

The function usbFunctionSetup is responsible for passing USB requests. Its parameters are stored in an 8-byte array (uchar data [8]). The meanings are:

Since the system function only needs to transmit the measured temperature value to the PC, the function only needs to transmit data without identifying different instructions. The following code can be used to implement the above function:

2.4 Configuration of compiled files

In the WINAVR software environment, you also need to configure MakeFile to compile programming files:



After the configuration and programming of the above process, data sampling of the lower computer and data transmission of the USB port can be realized.

3 Conclusion

The temperature measurement and display system based on AVRUSB technology uses integrated soft USB technology, and its hardware circuit design is more compact and stable. It has been proved by use and testing that the system has the characteristics of stable performance and low price. More importantly, this system provides a low-cost USB design solution, and at the same time provides a detailed design process and part of the code of the lower computer, thus providing a better idea for the development of medium- and low-cost USB devices.

Keywords:AVR Reference address:Design of lower computer for temperature measurement system based on AVR USB interface

Previous article:Design of coal mine sensor based on AVR microcontroller
Next article:Multi-channel hydrological parameter acquisition and wireless transmission system based on ATmega16

Latest Microcontroller 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号