USB (Universal Serial Bus)

USB (Universal Serial Bus)

RH2T Magazine, Vol.3,March 2010

Nowadays, USB has replaced most computer port connectors such as serial port (DB9), parallel port, and PS/2.

 

Introduction

USB_Icon

Universal Serial Bus known as USB, seems to be very popular among computer peripherals for human device interfaces such as mice, keyboards, speakers, external hard discs, and many more devices. So why do we discuss USB? What does USB have to do with Robot? Well, robot involves interface and since USB has become very famous because of its flexibility and robustness of plug and play, it has been adapted in one of the major interfaces in robot parts. A simple example is Webcam; the most popular webcam comes with a USB interface, thus for those that need to use vision or image recognition on the robot, the USB is the ready-made choice for the interface. Today, we will not discover the specific role of USB in robot interfaces; but we will talk about USB in general. This will start with the history, specification, hardware, and some of the famous USB devices which are being used in the embedded world.

Let’s start with the history of USBs. It started with USB 1.0, this is the specification that was introduced and defined in 1996. It was intended to replace the various standard of cable (Serial Port, Parallel Port, PS/2) at the back of a personal computer, as well as to simplify the software configuration between computer users and devices such as mouse and keyboard. Thus, it comes with a plug-and-play feature. It was created by a group of big players in computer businesses which include Compaq, Digital, IBM, Intel, Northern Telecom, and Microsoft. Later in April 2000, USB 2.0 specification was released and standardized by the USB-IF (USB Implementer Forum) at the end of 2001. And do you know that USB 3.0 specification was released in November 2008? Yes, it was released by USB 3.0 Promoter Group. USB has become a very successful standard and connection. The standard and usage of USB have spread through many devices such as cameras, camcorders, handphones, MP3 players, and joysticks. Well, USB-IF did a great job of specifying the specification and providing easy-to-use features.

 

Overview

clip_image004

 

In a USB system, there must be a USB host and USB devices such as a keyboard, mouse, Pendrive, or Bluetooth dongle. And do bear in mind that a USB device cannot communicate with another USB device directly; it must go through a USB host. An example is the pen drive. If I wanted to copy data from Pendrive A to Pendrive B, I cannot connect these Pendrives together to copy the data I wanted. It must go through a USB host namely a computer or a laptop. You might be wondering, how could devices like photo frames and movie converters o read information from a Pendrive despite the fact that they do not have any computer to support the Pendrive. This is simply because they are another specification of USB i.e. USB OTG (On The Go) or USB Embedded Host. We will leave that for some other time because to discuss everything about USB would need probably more than 10 issues of the magazine. Now, do you know how many USB devices that you can connect to a computer? 10 or 20? The answer is 127 USB devices-far more than enough for a normal user. Yes, you get it right, though I would say this only happens in a test case for a USB host controller.

How can a USB device be plugged and played? One of the main processes that enable plugging and playing is the “Enumeration” process. Enumeration is the process where the USB host learns about the USB device when it was first plugged in. The information needed from the USB device includes communication speed, device class, and further investigation of the need for driver installation. Since most of USB device driver has already been installed during windows installation, no driver is needed for normal USB device. Of course, driver installation is essential in special circumstances or cases.

 

Communication Speed

Let’s talk about USB speed.

clip_image006

1.5 Mbit/s is classified as a low-speed rate and it is specified in USB 1.0. This speed is suitable for Human Interface Device (HID) such as keyboards, mice, and joysticks.

12 Mbit/s is classified as full speed rate and it is the basic communication rate in USB 1.1. All USB hubs must support at least this speed and most of the embedded devices such as Microchip USB enable the microcontroller to support this speed.

A High speed (USB 2.0) rate of 480 Mbit/s was introduced in 2001. All High-Speed devices are capable of falling back to full speed (12 Mbit/s) operation if necessary, they are backward compatible. The connectors are identical. In 2008, USB 3.0 gives a new Super Speed rate of 5.0 Gbit/s. The product that uses USB 3.0 is expected to hit the public at the end of 2009 or early 2010. The communication speed mentioned above is the data speed for USB raw data communication at the hardware layer only. When it goes up to the application layers such as file transfer between computer and Pendrive, the data rate must be minus the overhead and also the data checksum, which resulting a lower data rate.

Hardware Connection

Since USB intends to replace the serial port, parallel port, and other connectors at the back of the computer, it must define a standard connector and it actually does. Nowadays, laptop no longer have serial port, parallel port, or PS/2 port, it only has USB A-type jacks. There are actually several types of USB connectors, some of which have been added during the specification progress. The original USB specifications are Standard A and Standard B plugs and receptacles (sockets). The standard connection in USB plug and socket is 4, except for the mini and micro types. These 4 connections consist of -, +, D+ and D-.

USB connection

The negative (-) or ground pin and the Positive (+) connections are responsible to supply power to the USB device. You might ask, what is the voltage and maximum current that a USB hub may provide? There is another myth or doubt that needs to be clarified because many assume that a USB hub provides a stable voltage of 5V. In fact, USB specification allows the voltage to vary from 4.40V to 5.25V. Thus, if you are developing a USB-devised project, do ensure that it can work properly under this condition. Be that as it may, most of the USB powers are quite stable and stay at the range of 5V. Another myth is about the current from a USB hub. So what is the maximum current a USB hub may supply? How about the external hub that the user adds to extend the number of USB connections? A standard USB hub must supply a minimum of 100mA to a USB device; however, the current can be increased to a maximum of 500mA for software requests from the USB device. In short, A USB device must be able to start operating at 100mA. As to the external hub, there are 2 types of USB external hubs, namely self-powered and bus-powered. A self-powered USB external hub is a hub powered by an external adaptor. This kind of USB external hub will not be a problem because it can supply up to the maximum current, i.e. 500mA when necessary. On the other hand, a bus-powered USB external hub which is bus powered is only able to distribute the minimum current of 100mA to the 4 extra USB devices respectively and the remaining 100mA to itself. This has made up a total of 500mA from the computer USB hub. Now can you guess what the maximum length of a USB cable is?

  • USB 1.0 is 3.0 meters
  • USB 2.0 is 5.0 meters

USB 3.0 is any length as long as other specifications are met, 3.0 meters if the maximum speed is required.

 

Embedded USB

Ever since the day I started using USB devices such as mice, keyboards, and Pendrive, I have been thinking to create a homemade USB device with a microcontroller. However, I found out that there is no low-cost microcontroller that supports a USB engine, and I ended up holding on to my thought.

clip_image010

Fortunately, recently, Microchip Technology started to venture into USB applications for its microcontroller which provides great support. From the diagram shown, there are plenty of choices from 8-bit (PIC18F4550), 16-bit to 32-bit microcontrollers that support USB peripherals. Now, with the solution from Microchip, you can create your own USB mouse, game controller, serial port, parallel port, keyboard, Pendrive and even a USB OTG (On The Go) or USB-embedded host. Besides providing support in terms of hardware (microcontroller) and schematic, it also offers sample source codes. The best thing is that all the information is free and open source. You are welcome to download it from Microchip’s website and modify the sample circuit and source code for your own design. But you must use Microchip PIC Microcontroller.

Who else offers the USB microcontroller besides Microchip Technology? There are Atmel, Texas Instruments, Cypress, Infineon and NXP, etc. You are free to choose the microcontroller.

clip_image012

Cytron Technologies has also designed a USB game controller as one of our DIY (Do It Yourself) project series. PR26 uses PIC18F2550 and sample source code from Microchip. Users can modify the code to change this controller into a mouse. You may visit our latest DIY project for more information. Besides, Microchip Regional Training Center also offers a USB workshop entitled “USB from Scratch”. This workshop discovers USB’s history, specification, hardware, Microchip Framework, and Driver and there are a few hands-on lab exercises that use PIC18F4550 to create a USB mouse and USB to RS232 converter.

So, let’s say you need to create a USB device, do you need to pay for a license? Reference has to be made to VID and PID because every USB product comes with unique VID and PID. VID stands for Vendor ID while PID stands for a Product ID. USB-IF mandates each vendor has its own VID in order to market its product. There may be both legal and technical complications involved when using a non-unique VID/PID. Once a VID is purchased, how the PIDs are used within that VID is determined by the manufacturer. Microchip has its own VID for its USB-enabled microcontroller and they also have a sublicensing program for its VID. In other words, you can always send an email to Microchip to request for PID to further develop your own USB product using Microchip microcontroller. For academic research and development, you can change the PID. You do not need to pay for this. However, it is advised to confirm with Microchip with regard to this matter.

 

Getting Started

clip_image014

What are you waiting for? If you like to start, you can get the latest starter kit from Cytron Technologies, SK40C which comes with a USB mini socket that supports the PIC18F4550 PDIP package. You can download the sample program from Microchip’s website and download it into the chip through UIC00A and have a homemade USB device! To get more information about USB from Microchip, please visit www.microchip.com/usb.

Good luck! If you have questions, please do feel free to discuss them in our technical forum 

Information is taken from:

1: http://en.wikipedia.org/wiki/Universal_Serial_Bus

2: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2651¶m=en534460#P189_15342

BUY