Monday, January 3, 2011

With full speed USB interface PICl8F4550 application design

Summary with full speed USB interface of the MCU PICl8F4550 characteristics, and to use its USB interface design a grating displacement detection device.

This design improves the grating displacement detection system anti-interference ability and reliability, reduces the system volume, lower system costs.

Key words full speed USB interface PIC18F455O grating sensor firmware

Introduction

With the USB (Universal Scrial Bus) technological developments, in particular high speed (480 Mbps) USB2.0 agreements, almost all PC peripherals can be ported to USB, USB PC peripherals development space is huge, even in the near future, USB will completely replace the asynchronous serial and parallel ports for printer, PC manufacturers will not be reproduction chassis with asynchronous serial port and the printer and port of the PC, the chassis is not going to have so many wires.

USB is a fast, bi-directional Synchronous transfers, cheap and can be hot-swap serial interface.

Use of USB technology, develop suitable for scientific research and industrial production of a variety of instruments and equipment, which will replace the traditional computer control system using a serial RS232 or parallel some of the instruments received equipment, making your computer real-time measurement and control system more efficient, convenient and flexible.

Use of USB data acquisition programme there are two types using ordinary SCM plus dedicated USB communication chip.

The programme can take full advantage of the developer of the original hardware and software knowledge, development costs are lower, but the system's design and debugging were more cumbersome, and electromagnetic compatibility, easily host does not recognize USB devices. Another way is to use a USB interface functionality of SCM. Use these specific chip components of data gathering system circuit design simple, debugging is convenient, good electromagnetic compatibility. However, most have USB functionality of SCM are tailored to the personal computer peripherals and consumer market needs, neglecting the needs of embedded engineers. Microchip company new PIC18F4550 series monolithic integrated circuits, for a wide range of embedded applications with full-speed USB advantage, even if you encounter severe operating environment or only time to connect a personal computer, you can work properly.

This article to grating sensor detection system design as a background, details with full speed USB interface of the application of single-chip PICl8F4550 design methods.

1 PICl8F4550 introduction

PICl8F4550 is Microchip's latest production with full speed USB interface with 8-bit single-chip, chip-to-high grade 40/44 pin package.

The MCU in addition to the PIC Microcontroller specific reduced instruction set (RISC), data bus and instruction bus independent of Harvard (Harvard) structure, and other characteristics, is also equipped with a self programming flash memory, and canava energy-saving technologies, operating frequencies up to 48 MHz, data transfer rate of up to 12 Mbps. In addition, you have a Microchip advanced PMOS electrical erasable unit (PEEC) Flash technology, high write endurance of up to 100 million times, and the data retention period to more than 40 years. The chip has a strong control and flexible way of working.

New devices at full USB 2.O interface has 1 KB RAM dual access, support for up to 32 endpoint (bi-directional 16 pairs) and 2 types of data transfer rates (i.e. full speed mode 12 Mbps and low-speed mode 1.5 Mbps) with USB protocol may require 4 data transmission mode (control of transmission mode, the interrupt transmission mode, batch mode of transport and realtime transmission mode).

The interface includes a single-chip transceiver and a parallel flow port, the data delivered directly to external devices, not only reduces CPU overhead, and greatly enhance system anti-interference ability and reliability.

PICl8F4550 hardware resource rich, Philippines often contains 33 I/O, I/O port is the port A, B, C, D, E; has multiple interrupt sources and 1 interrupt priority selection, 4 timer, 32 KB Flash, 256 byte EEP-ROM data memory, 2 048 bytes data RAM and 88 hardware multiplier; integrates 13 channel 10-bit A/D converter, 2 CCP (compare/capture/PWM) module .1 an enhanced CCP module and 1 watchdog; has a power saving sleep mode function; 1 USART not only supports asynchronous and synchronous serial communication, but also supports LIN bus; 2 analog comparator, supports I2C and SPI communication master synchronous serial port, programmable undervoltage reset and low-voltage detection circuit, etc.

PIC18F4550 SCM a key characteristic is that it is equipped with 32 KB Flash-enhanced since the programming.

Allows designers to via the USB port on the end application site upgrade. Combined with the new device is equipped with a series on peripherals, and canava technology (nanoWatt) power management features that make it very suitable for a wide variety of embedded applications, including industrial, medical, automobile, battery-powered, and consumer products, etc.

2 design and application of PICl8F4550

2.1 grating displacement sensor basic working principle, features

Grating displacement sensor basic working principle is to use a pair of grating, one is fixed, while the piece is movement.

When they occur in relative motion and light when through both to obtain the equivalent of Interferometer in fringe signals, that is, the so-called "moire signals". For a pair of metering grating, move a notch (often using modern metering raster 4 ~ 250 L/mm) to move a moire. Stripe-width effect by wavelength。 And stripe wide for interpolation effect because the average error., so that you can get very high precision. Compared with ordinary displacement sensor, it has the following characteristics:

① high accuracy.

Grating displacement sensor in large measure the length or linear displacement, just below the laser interference sensor at indexing and angular displacement measuring, grating sensor belongs to the highest precision.

② large quantum measurement and high resolution.

Inductosyn and magnetic gate sensor also has a large range of features, but the resolution and accuracy are not as good as grating displacement sensor.

③ to dynamic measurement, easy-to-implement measurement and data processing automation.

④ with strong anti-interference ability, the requirements of the environmental conditions as laser interference sensor so strict, but not as good as inductosyn and magnetic gate sensor of adaptability.

Greasy dirt and dust will affect its reliability, mainly for the laboratory and the environment good workshop use.

2.2 PICl8F4550 hardware design

PIC18F4550 USB interface hardware design is simple, and microcontroller peripherals are generally single-chip design, you can reference general PIC Microcontroller design methods.

For USB interface, Micrachip Corporation offers a suite of Development Kit (Demo Board) to help users develop their own products. It provides application, driver and firmware, help users become familiar with the process of working USB; at the same time, you can directly use development suite to expansion peripherals.

Figure l is a grating sensor detection system hardware circuit diagrams, the main implementation of data acquisition, processing, transmission and PWM pulse generation, and so on.

From grating sensor input signal 5 Road: sin, cos and zero zero window signals. Synthesis by differential amplification circuit, three-way into the PIC analog input for A/D conversion; at the same time, the differential amplification circuit synthesis after sin, cos signal after zero comparator is converted to a digital pulse signal, then the D flip-flop and "and" gate complete debate to raster displacement. PIC Microcontroller T0 and T1 port receives from "and" gate circuits for Digital pulse, complete raster displacement of count (count grating ruler move complete raster); PIC RCl port output 4 MHz PWM pulse signal as a signal of CP D triggers. Your computer's USB interface both data lines respectively PICl8F4550 of D + and D a port that is used to complete the computer and the data communication between a single chip. Your computer's USB power connection for PIC microprocessor provides energy, on the other hand, through the power supply module converts the 12V power supply for the positive and negative power amplifier circuit provides.

  

2.3 MCU software design

SCM software part mainly complete optical Shan displacement sensor data acquisition, A/D conversion, calculation of grating displacement sensor forward, reverse number of moire fringes, for digital circuit with CP pulse and complete USB communications, etc.

Figure 2 is a single-chip Software section of the flowchart.

  

2.4 PICl8F4550 firmware design

Chipscreen company offers a wide range of USB registers, use these registers can complete USB communication.

Most USB communication is accomplished through interrupts, interrupt service routines in USB, to be achieved within the input/output interface that allows most USB program completed in the background. From the application point of view, the enumeration process and data communication links don't seem to have occurred.

For single-chip control, there are no manufacturers provide automatic generation of firmware (firmware) of the tool, so all programs are compiled by his hand.

Due to the complexity of the USB protocol, taking into account the needs of our customers, therefore, the company launched the PIC18F4550 Mictochip series chip provides for different customer groups in the DEMO program, which greatly reduces the burden on the developers of the system, while reducing the development cycle. This system is provided by the company in Microehip DEMO program, make the necessary modifications. The design of specific firmware mainly consists of the following 8 files.

① m a c I n.: System of the main program, including InitializeSystem () and USBTasks (void) two subprograms, complete system, and other various subroutine calls.

② u s b 9. c: implementation of the USB protocol 9 features, including enumeration bus interface and core functionality, as well as USB interrupt service program.

It handles the USB user generated all interrupts. In this program, the main achievement of the descriptor and Hibernate, reset the enumeration, mainly including USBCheckStdRequest (void), USBStdGetDscHandler (void) and USBStdFeatureReqHandler (void) five subroutines.

③ u b s c r l t r t f c: main realization. USB control transfer the desired features, mainly by USBCtrlTrfSetupHandler (void), USBCtr — IEPServieeCompiete (void) and USBPrepareForNextSetupTrf (void) 8 subroutines.

④ u s b e d r v.: main realization and USB driver-related features, including check bus status, USB module enabling, hang USB module, remote wake up capabilities; mainly by the USBS

Uspend (void), USBModuleEnable (void), USBSoftDetach (void) and USBDriverService (void) 12 subroutine.

⑤ d s u b s c £ ® c: mainly on the description of the system, including manufacturers, product codes, and description.

⑥ u s b g c e n.: on the configuration of the USB device class (here it is configured as a generic USB class), including USB universal class to initialize the endpoint and read and write from USBGenlnitEP (void), USBGenRead (byte * buffer, byte len) and USBGenWrite (byte * buffer, bytelen) three subroutine.

⑦ u m b a s m p £ ® c: mainly for checking the USB in the communication process, endpoint, and BDT (buffer descriptor table) match.

⑧ u s e c r.: direct user-oriented applications that can help users complete their initial configuration, handling data read/write, I/O port address, at the request of the device.

The design of most of the lower computer functionality is accomplished by the program, such as A/D conversion and data read, 1MHz PWM waveform generation, and so on. It mainly includes the UserInit (void), BlinkUSBStatus (void), ServiceRequests (void), ProcessI () (void), ResetTempLog (void) and ReadPOT (void) six subroutine.

2.5 PC software programming

You want to write software on the PC, you can make use of Microchip company provides development kit.

The Toolkit is a Setup, after installation, the installation was found under the USB universal driver, with Borland applications written in C, some firmware code, and the preparation of the application API functions and so on. For general application, the driver can be used directly without renumbering. It is mainly used in programming to the following seven API function: MPUSBGetDLL Version () returns the version number of the DLL; MPUSB — GetDeviceCount () returns the number of connected devices; MPUSBOpen () returns a specified pVID_PID and pEP USB device endpoint handles, returns the handle to an endpoint; MPUSBRead () to read data from the endpoint IN and fill the buffer; MPUSBWrite (), for an OUT endpoint write data and use pData buffer; MPusBReadInt (), from the Interrupt IN endpoint reads data and fill the buffer; MPUSBClose (), close the handle to an endpoint. Because Mierochip company provides MPUSBAPLDLL source program is written using Borland C, this program will not compile in the VC environment, so it cannot generate an implicit call to the .LIB file, so the design to use the DLL using explicit linking.

PC software is mainly used for the realization of the PC with the slave USB communication between, grating sensor offset signal segmentation and display functions.

To achieve this feature there are many kinds of methods, such as using a simple VB, data processing capabilities of Delphi, or at home and abroad, widely used Borland C and VC, and so on. To the next stage of software development as well as manufacturers of other software interface, the system PC software parts using VC ++ 6.0. Figure 3 is a PC Software section of the flowchart.

  

Conclusion

The choice of chips to design embedded systems, depending on the system requirements, design, degree of difficulty and price/performance and other aspects to consider.

Micro-chip company PICl8F4550 series single-chip provides a general purpose driver, API functions, DEMO Board and a series of example programs, etc. Of these, some firmware endpoint and PC communication subroutines can be called directly without the need to rewrite, thereby greatly improving the development efficiency, shorten the product development cycle, this will inevitably lead to the series single-chip will soon occupy part of the USB interface on the market. It is precisely because the benefits of USB and grating sensor has many other displacement sensor incomparable advantages, therefore, the design of the applications will be more and more widely.

No comments:

Post a Comment