AMAZON multi-meters discounts AMAZON oscilloscope discounts 1 Introduction 2 USB overall structure
3 The physical layer
4 Datalink layer
5 Application layer (user layer) 6 Conclusion
1 Introduction In September 23, 1998 Microsoft, Intel, Compaq, and NEC developed Revision 1.1 of the universal serial bus. The objective was to standardize the input/output connections on the IBM PC for devices like printers, mice, keyboards and speakers. Data acquisition (DAQ) devices were not envisioned to be connected to the USB system. But that does not mean that the USB cannot be used for DAQ. In many ways, the USB is well suited for DAQ systems in the laboratory or other small-scale systems. Small-scale DAQ systems have traditionally suffered from the need of an easy to use and standardized bus system for connecting smart DAQ devices. The nearest thing was the IEEE 488 GPIB system. The GPIB system is expensive and uses very old technology. AMAZON multi-meters discounts AMAZON oscilloscope discounts There is need for an easy-to-operate, inexpensive, and standardized bus system to connect small-scale DAQ devices. The USB can fill those needs. With its plug and play ability, it is extremely easy to implement and use, and it is now standard on all IBM compatible PCs. Although it is not in any way as cheap as say an RS 232 connection, it is affordable. The USB is limited by its very nature, for its application, to DAQ systems. The biggest problem is the maximum cable distance. The low speed version is limited to 3 meters and the high-speed version is limited to 5 meters in total cable length. This requirement reduces the ability of USB to be used in a large, factory or plant, environment. Typically in these industries, DAQ systems need distances up to 1 kilometer. Due to the timing requirements of the USB, the length of the cable cannot be increased with repeaters. This limits the use of the USB to laboratories and or bench top systems. 2 USB - overall structure The USB is a master/slave, half-duplex, timed communication bus system designed to connect close peripherals and hubs to an IBM compatible PC. It runs at either 1.5 Mbps (low speed) or 12 Mbps (high speed). The PC's software program using device drivers create packets of information that are going to be sent to devices connected on the USB bus. The USB drivers in the computer allocate a certain time within a frame for the information. The packet is then placed in this 1 ms frame that can contain many packets. One frame might contain information for many devices or may contain information for only one device. The frame is then sent to the physical layer via USB drivers and then on to the bus. The device receives its part of the packet and if necessary formulates a response. It then places this response on the bus. The USB drivers in the PC hear the response on the bus and verify that the frame is correctly using CRC. If the CRC indicates that the frame is correct, the software in the PC accepts the response. The devices connected to the USB bus can also be powered off the bus cable. Devices can use no more than 500 mA. This works well for small-scale DAQ devices; larger DAQ devices usually use external power supplies. Both power and communications are on the same cable and connector. There are many parts in the USB system that make the communication possible. These include: • Host hubs • External hubs • Type A connector • Type B connector • Low speed cables • High speed cables • USB devices • Host hub controller hardware and driver • USB software driver • Device drivers _ The USB uses a pyramid shaped topology with everything starting at the host hub. The host hub usually consists of two USB ports on the back of the PC. These ports are basically in parallel with each other. Each port is a four-pin socket with two pins reserved for power and two for communications. The cables from eternal hubs or USB devices are plugged into host hub ports. One or both of the ports can be used. It doesn't matter which one is used if only one connection is being made. If the external device or hub has a removable cable then a type 'A to type B' cable is used to make the connection. The A plug goes into the back of a PC (host hub) and the B plug goes into the device or external hub. If the external hub or device has an in-built cable then the A plug is plugged into the host hub port. The socket on the host hub is keyed so the plug will only go in one way. B plugs will not go into A sockets and vice-versa. Figure 1 USB topology Cable lengths are very important (and short) for the USB system. All cables, even if they come out of repeater hubs, must be counted in the total length of the cables. _ The controller chips for the host hub usually reside on the motherboard inside the PC, (although the hub could be a PCB in a PCI slot). The host controller does the parallel to serial and serial to parallel conversion from the PCI bus to the USB connectors. Sometimes a pre-processor is used to improve efficiency of the USB system. This host controller and connector combination is called the root hub or host hub. The host Hubs' function is to pass the information to and from the PCI bus to the data lines (+D and -D) on the USB socket. The host controller can control the speed at which the USB operates. It also connects power lines (+5 V and ground) to a USB device via the USB cable. The external USB device may be another USB hub or a USB type device like a printer. Figure 2 Host hub block diagram The root hub has complete control over the USB ports. This control would include: • Initialization and configuration • Enabling and disabling the ports • Recognizing the speed of devices • Recognizing that a device has been connected • Getting information from the application software • Creating a packet and then frame • Sending the information on to the bus • Waiting and recognizing a response • Error correction • Recognizing that a device has been disconnected • Using the port as a repeater ___ There are two types of connectors, type A and type B. The reason there are two types is that some devices have built in cables while others have removable cables. If the cables were the same it would be possible to connect a host hub port to another host hub port. Because of the polarity of the connectors, the +5 volts would be connected to ground. To keep this from happening the hub's output ports use type A connectors and the device input ports use type B. This means that it is impossible to connect one hub port to another hub port. On an external hub, the input to the hub is a type B connector unless the cable on the hub is permanently connected (no connector). Figure 3 USB connectors _ The USB standard states that the USB will run at either 1.5 Mbps (slow speed) or 12 Mbps (fast speed). The USB must have low-speed cables and high-speed cables. This is due to the impedance difference caused by the different frequencies of data transfer. Low speed cables use untwisted and unshielded. The data pair is 28 AWG and the power pair is 20-28 AWG. The low-speed cable is used on devices like keyboards and mice. The maximum distance for low-speed cabling is 3 meters. High-speed cables are twisted and shielded. The data pair is 28 AWG and the power pair is 20-28 AWG. The maximum propagation delay must be less than 30 ns. The maximum distance for high speed USB is 5 meters. _ External hubs are used to increase the amount of devices connected to the system. Usually they have four USB output ports and either one type B input connector or a dedicated cable. This cable has a type A plug on it. It is usually connected to a host hub, but could also be connected to the output socket (type A) of another external hub. Even though the external hub is a repeater it cannot extend the overall length of the system. This is because of the timing requirements of the USB standard. The external hub is an intelligent device that can control communication lines and power lines on its USB ports. It is a bi-directional repeater for information coming from the host hub and from USB devices. It talks to and even acts like an external USB device to the host hub. It plays an integral part in the configuration of devices at startup. There is no physical limit to the number of hubs. _ The USB system supports every peripheral that can be currently connected to a PC. It has also been adapted to devices that are not usually considered peripherals. This would include data acquisition devices such as digital I/O modules and analog input and output modules. All USB devices must be intelligent devices. Smart devices obviously cost more than the old dumb RS-232 and RS-485 connected devices. With this cost the user gets more functions, ease of use and the ability to connect more devices to the PC. With the old non-USB system the computer was limited to a few devices. The USB system allows 127 devices to be connected to the PC at the same time. There are two types of USB devices, low-speed and high-speed. _ Low-speed devices are not only limited in their speed but also in features. These devices could be keyboards, mice and digital joysticks. Since these devices put out small amounts of information they are polled less and are slower than other devices. When the USB bus is being accessed by high-speed devices, the low-speed device communication is disabled. Turning off the low-speed device ports at the root or external hubs, disables the low-speed devices. The hubs re-enable the low-speed ports after receiving a special preamble packet. _ High-speed devices like printers, CD-ROMs and speakers need the speed of the 12 Mbps bus, to transfer the large amount of data required for these devices. All high-speed devices see all traffic on the bus. They are never disabled like the low-speed ones. When a device like a microphone is 'connected' to the speakers, most of the traffic, and therefore packets, will be used by the audio system. Other traffic like keyboard and mouse functions will have to wait. The host hub controller driver decides who has to wait and how long. _ The host hub controller hardware and software drivers, control all transactions. The host hub controller hardware does the physical connections from the PCI bus to the USB connectors. It enables and initializes the host ports one at a time and determines the speed and direction of data transfer on both host ports. The host controller in conjunction with the host hub software driver determines the frame contents, prioritization of the devices, and how many frames are needed for a particular transfer. ==== HOST PERIPHERAL Client Software Manages Interface Function A Collection of Interface USB System Software Manages Devices USB Logical Device A Collection of Endpoints USB Bus Interface Host Controller/SIE USB Bus Interface Peripheral Controller/SIE USB Port USB Port Logical Communication Flow Logical Communication Flow Figure 10.4 Host hub controller diagram ==== ___ The USB software driver handles the interface between the USB devices, the device drivers and the host hub driver. When it receives a request from a device driver in the PC to access a certain device, it organizes the request with other device requests from the application software, in the PC. It works with the host hub controller driver to prioritize packets, before they are loaded into a frame. The USB software driver gets information from the USB devices during device configuration. It uses this information to tell the host hub controller how to communicate to the device. _ Each USB device must have a device driver loaded into the PC. This device driver is a software interface between the external USB device and the application software, the USB software driver, and the host hub controller driver. It has information about that particular device's needs for the other drivers. This information is used to determine things like the type, speed (although that information can be determined physically by the hub ports), priority, function of the device, and the size of the packet needed for data transfer. As mentioned before, the USB system is a master/slave, half duplex, timed communication bus system, designed to connect peripherals and external hubs. This means that the peripherals cannot initiate a communication on the USB bus. The master or host hub has complete control over the transaction. It initiates all communications with hubs and devices. The USB is timed because all frames are sent within a 1 ms time slot. More than one device can have a packet of information inside that 1 ms frame. The host hub driver, in conjunction with the USB software driver, determines the size of the packet, and how much time each device gets in one frame. If the application's software wants to send or receive some information from a device, it initiates a transfer via the device driver. This device driver is supplied by either the manufacture of the device, or comes with the operating system. The USB driver software then takes this request and places it in a memory location with other requests from other device drivers. Working together, the USB driver, host hub driver and the host hub controller place the request, data and packets from the device drivers into a 1 ms wide frame. The host controller then transfers the data serially to the host hub ports. Since all the devices are in parallel on the USB bus, all of the devices hear the information, (except low-speed devices, unless it is a low-speed transfer. Low-speed devices are turned off when they are not being polled). The host then waits for a response (if necessary). The remote USB device then responds with an appropriate packet of information. If a device does not see any bus activity for 3 ms then it will go into the suspend mode. Figure 5 Example of a USB packet There are four types of IN packets (reading information from a device) and three types of OUT packets (sending information out to a device). Certain devices like mice and keyboards need to be polled (IN packets), but not too often. The USB software driver knows about these devices and schedules a regular poll for them. Included in the response are three levels of error correction. This type of transfer is very reliable. These peripherals are usually low-speed devices and therefore need a distinct low-speed packet to enable them. This packet is called a preamble packet. The preamble packet is sent out before each poll. The low-speed devices are disabled until they receive this preamble packet. Once they are enabled, they hear the poll and respond. Only one device can be polled at a time and therefore only one device will respond. USB has no provisions for multiple responses from devices. On the other hand there are devices that need constant attention but polling is not possible. These would be devices like microphones (IN packets), speakers (OUT packets) and CD-ROMs (both types of packets IN and OUT). The transfer rate is very important to these devices. Obviously they would use the high-speed transfer rate. They would also use a large portion of the frame (up to 90%). The receiving device does NOT respond to the data transfer. This transfer is a one-way data transfer or 'simplex'. This means that error correction is effectively turned off for these types of transfers. 3 The physical layer The physical layer of the universal serial bus is based on a differential +/- 3 V DC communication system. It is in some ways very similar to the RS-485 voltage standard. Unfortunately it does not have the range of 485. This is not because of the type of wire used or because of the USB voltage standard itself. It is because of the timing requirements of the USB protocol. In order to fit in all of the things the peripherals do on a USB bus, it was necessary to put very strict time requirements on the USB. The USB physical standard has a lot of benefits to the user. It is fast, 12 MHz. It is very resistant to noise and is very reliable, as long as the user follows the cabling rules. With standardized cables and connectors it is very hard for the user to get things wrong when cabling the USB system. Figure 6 USB connector pins There is a story that one day Bill Gates was watching some installers put in his new computer. When he saw all the wires coming out of the back of the computer he called the CEO at Intel and said, 'We have to get rid of this mess of cables and connectors'. And as they say, the rest is history. _ The plugs and sockets on the USB have two wires for data communication and two wires for power. Using bus-powered devices is optional. The pins on the plug are not the same length. The power pins are 7.41 mm long and the communication pins are 6.41mm long. This means that if a cable is plugged in 'hot' the power will be applied to the device before the communications lines. More importantly it also means that when a cable is unplugged the data communications lines will be disconnected before the power. This would reduce the possibility of back EMF voltages damaging the equipment. There are two types of connectors for the USB, type A and type B. Type A connector is a flat semi-rectangular keyed connector that is used on the host ports, external hubs and devices. The type B keyed connector is half-round and smaller than the type A connector. Note that both type A and B plugs have the USB symbol on the top of the connector. This is for orientation purposes. The hubs and devices all have female sockets, while the cables have a type A male plug, on one end, and a type B on the other end. This is because if there were a type A on both ends it would be possible to connect two host hub sockets or external hub sockets together. Cables that are not removable from the device or external hub, have only the type A plug on one end. _ The cables for the USB are specified as either low- or high-speed cables. Both the low- and high-speed cables can use type A connectors, but only a high-speed device can use type B connectors. Detachable cables are therefore always high-speed cables. Due to that fact that the impedance of a cable is determined in part by the frequency of the signal, the two speeds need two different cables. External hubs are always high-speed units, but they will accept low- and high-speed cables. Low-speed devices like keyboards will only connect to other low-speed devices using low-speed cables. The ports on the hub can detect the speed of the device on the other end. If the D+ line is pulled high (+3.0 V DC to +3.6 V DC) then the device is considered high-speed. If the D- line is pulled high then the device is considered low-speed. The low-speed (1.5 Mbps) cable uses unshielded, and untwisted data cables. The communication pair is 28 AWG gauge, but due to the lack of shielding and twisting, the overall diameter of the cable is smaller than that of a high-speed cable. The maximum distance for the low-speed cable is 3 meters. This includes all host hub ports to external hub, as well as the external hub to device cables. Usually on data communication systems slower data speeds mean longer distances. In this case, the cable is unprotected against noise, and because of the FCC restrictions on 1 to 16 Mbps communication, its length is severely limited. The high-speed (12 Mbps) cable uses a shielded and twisted-pair 28 AWG gauge wire. The maximum distance for high-speed cables is 5 meters. Again this includes all hub to hub and hub to device connections. The shield is internally connected to chassis-ground at both ends. Usually on data communication systems, the ground is connected at only one end, but because the distances are short, this is not a problem. NOTE: It might be wise though, to measure the chassis to chassis ground difference between both devices before making the connection. The power pair on both low- and high-speed cables is 20 to 28 AWG gauge. The power pair supplies between 500 and 100 mA to external devices at +5 V DC. Every port on a hub will provide this power to the devices if enabled by the hub. All hubs can decide if a port has power applied to the connector. If an external hub is itself powered by the bus then it will divide the 500 mA up into 100 mA or so per port. _ When a device is plugged in to a hub, the port on the hub immediately determines the speed of the device. The port looks at the voltage on the D+ and D- lines. If the D+ line goes positive, the port knows that the device is a high-speed device. If the D- line goes positive, the port knows that the device is a low-speed device. If both D+ and D- voltages fall below 0.8 V DC for more than 2.5 microseconds, the hub sees this as the device having been disconnected. If the voltage on either line is raised above 2 V DC for more than 2.5 microseconds, the port sees this as the device having been plugged-in. == Full/Low Speed USB Transceiver Full/Low Speed USB Transceiver USB Cable USB Cable Full Speed USB Transceiver Low Speed USB Transceiver Hub or Device; Device only +5Vdc +5Vdc +3.0 - 3.6Vdc +3.0 - 3.6Vdc Figure 7 USB wiring diagram == The idle states for low- and high-speed devices are opposite of each other. For the low speed device the idle state is the D+ line at 0 volts, and the D- a positive voltage. The idle state for a high-speed device is such that the D+ is a positive voltage and the D- is 0 volts. In most data communications, a positive voltage indicates a zero (0) condition, and a one (1), a minus voltage. In the USB system it is not possible to say this because it uses an encoding system called NRZI. The voltages used for differential balanced signaling are: • Maximum voltage transmitted +3.6 V DC • Minimum voltage transmitted +2.8 V DC • Minimum voltage needed to sense a transition +/- 2 V DC • Typical line voltage as seen from the receiver +/- 3 V DC _ Figure 8 NRZI example The USB uses non-return to zero inverted (NRZI) encoding scheme. In NRZI, a '1' is defined as 'no change' or 'transition' of voltage whereas a '0' is a change or transition of voltage. A string of '0s' would cause a clock-like data stream. The USB signaling system uses the transition from one voltage to another to synchronize the receivers. A stream of ones therefore would mean no transitions. This would cause the receiver to lose synchronization. To overcome this problem the USB system uses a 6 of 7 bit stuffing technique. If six or more ones are to be transmitted in a row the transmitter stuffs in a zero (a transition). If the receiver sees six ones in a row, it knows that the next transition (zero) is to be ignored. __ Devices like keyboards and mice need power to operate. This power is supplied by the USB system through the cables and hubs. External hubs can be either self-powered or powered off the bus. The voltage supplied by a USB hub is +5 V DC. The hubs must be able to supply a minimum of 100 mA and a maximum of 500 mA, through each port. If an external hub with four ports is powered off the bus, then it will divide the 500 mA supplied between the ports. Four times 100 mA equals 400 mA. This leaves 100 mA to run the hub. It is not possible to connect two bus-powered hubs together unless the devices connected to the last hub were self-powered. If the external hub is self powered, that is mains powered, it should be able to supply 500 mA to each of the ports. 10.4 Data link layer The data link layer within the USB specification defines the USB as a master/slave, half duplex, timed communication bus system, designed to connect close peripherals and external hubs. The hardware and software devices such as the host hub controller hardware and driver, USB software driver and device drivers all contribute to the data link layer of the USB. All these devices working together accomplish the following: • Collects data off the PCI bus via the device drivers • Processes the information or data • Verifies, determines and processes the different transfer types • Calculates and checks for errors in the packets and frames • Puts the different packets into a 1 ms frame • Checks for start of frame delimiters • Sends the packets to the physical layer • Receives packets from the physical layer _ Table 1 USB data link layer block diagram _ A good place to start when looking at the data link layer of the USB is at the four different transfer types. The wide range of devices that the USB has to deal with require that there be multiple transfer types. These are: • Interrupt transfer • Isochronous transfer • Control transfers • Bulk transfers As stated before, there are two speeds that can be used in the USB system. For the most part the data link layer is the same, but there are some differences. The low speed devices do not support bulk and isochronous transfers. The reason for this will become apparent in the following transfer descriptions. _ The interrupt transfer type is used for devices that traditionally used IRQ lines. Devices like keyboards, mice and DAQ cards use the IRQ lines to tell the computer that they need servicing. The USB does not support devices that initiate requests to the computer. To overcome this problem the USB driver initiates a poll of those devices that it knows need periodical attention. This poll must be frequent enough so that data does not get lost but not too frequent as to use up much needed bandwidth. When installed, the device determines its minimum requirements for polling. Devices that need to be polled are rarely polled on every frame. The keyboard is typically polled only every 100th frame. _ Isochronous transfer is used when the devices need to be written to or read from, at a constant rate. This would include devices like microphones and speakers. The transfer can be done in an asynchronous, synchronous, or device specific manner, depending on the device in use. This constant attention requires that the bulk of the bandwidth of the frame be allocated to one or two devices. If too many of these transfers take place at the same time data could be lost. This type of transfer is not data quality critical. There is no error correction and lost or data that is in error, is ignored. Low-speed devices cannot use isochronous transfer because of the small amounts of data being transferred. It is not possible to move data fast enough using low-speed devices. In an isochronous transfer, the maximum amount of data that can be placed in one packet is 1023 bytes. There is no maximum number of packets that can be sent. _ Control transfers are used to transfer specific requests and information to specific devices. This method is used mostly during the configuration and initialization cycles. These transfers are very data critical and require a response or acknowledgement from the device. Full error correction is in force for this type of transfer. All devices use this type of transfer at one time or another. These transfers use very little bandwidth but because the device must respond back to the host hub the frames are dedicated to this one transfer. _ Bulk transfers are used to transfer large blocks of data to devices that are not time dependent but where data quality is important. A typical device that would use the bulk transfer method would be a writeable CD and a printer. These devices need large amounts of data but there is no time constraint like that in a speaker. If data gets there in the first 10 ms or in the next, is not a problem. But they do need correct data, so this type of transfer includes handshaking and full error correction. _ The USB protocol can and often does use a multi-packet-frame format. The USB frame is made up of up to three parts. One frame equals one transaction. The packets are of the following type: • The token packet • The data packet • The handshaking Every frame starts with a token packet. The token packet includes other smaller packets. These are, the synchronization pattern, packet type I.D. and token packet type. There are four types of token packets - start of frame, in packets, out packets and setup packets. The start of frame/token packet indicates the start of the packet. This tells the receiver that this is the beginning of the 1 ms frame. The in packets are packets that will transfer data in from the devices to the PC. The out packets are packets that will transfer data out from the PC to the device. The setup packet is used to ask the devices or hubs for startup information and have information for the devices or hubs. A special packet is only used on low-speed transfers. It is called the preamble packet. It is a shorter packet than the high-speed frame. It only holds up to 64 bytes of data and always uses handshaking. It only has three variations - in packet, out packet and setup packet. At the end of all packets, except the isochronous-frames, there is an error correction packet. On high-speed frames, it is a 16-bit CRC. Low-speed devices use a 5-bit CRC, because of their smaller packets. If a device or host hub sees an end of frame message, it checks the CRC. If the CRC is correct then it assumes that this is the end of the message. If the CRC is not correct and the time-out limit has not been reached, the receiver waits. If the CRC is not correct and the time has been reached, the receiver will then assume that the frame is not correct. 5. Application layer (user layer) The application layer can be divided into two sub-layers, the operating system (such as WIN 2000) and the device application software (such as a modem application program). The application layer of the USB standard is in reality a User layer. This is because the USB standard does not really define a true application layer. What it does define is a user layer that can be used (by an application programmer) to build an application layer. The operating system user layer includes: • Commands • Software drivers • Hub configuration • Bandwidth allocation Device applications would use: • Commands • Device drivers • Device configuration Specific user layer information can be found in the universal serial bus specifications at the USB implementers forum web page at http://www.usb.org 6 Conclusion Designed as a peripheral connection system for the PC, the universal serial bus can be adapted to be used on data acquisition systems. Now that the DAQ industry is developing more and more intelligent data acquisition and control systems, the USB is easily adaptable to modern DAQ. The devices can either be low- or high-speed devices, and are quickly and easily connected to a PC. There are many devices in the market now and it is bound to grow in the future. Engineers are usually more interested in getting the job done than in spending a lot of time and trouble getting the DAQ system up and running. With the plug and play system incorporated in USB the user does not have to spend hours or even days configuring a DAQ system. This time saved will often offset the added cost of the devices. The target speed of USB 2.0 is 480 Mbps, as announced by the USB 2.0 Promoter Group, consisting of Compaq, Hewlett-Packard, Intel, Lucent, Microsoft, NEC and Philips. The target speed announcement coincides with the release of the USB 2.0 specification draft to industry developers. NEXT: |
Updated:
Monday, March 17, 2014 4:44
PST