By: Ober Choo
RH2T Magazine, Vol.3，March 2010
Nowadays, USB has replaced most of the computer port connectors such as serial port (DB9), parallel port and PS/2.
Universal Serial Bus known as USB, seems to be very popular among computer peripheral for human device interfaces such as mouse, keyboard, speaker, external hard disc and many more devices. So why do we discuss about USB? What does USB have to do with Robot? Well, robot involves interface and since USB has become very famous because of it 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 USB interface, thus for those that need to use vision or image recognition on robot, USB is the ready-made choice for interface. Today, we will not discover the specific role of USB in robot interface; but we will talk about USB in general. This will start with the history, the specification, hardware, and some of the famous USB devices which are being used in embedded world.
Let’s start with the history of USB. It’s started with USB 1.0, this is the specification that being 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 user and devices such as mouse and keyboard. Thus, it come the 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 being 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 camera, camcorder, handphone, MP3 player and joystick. Well, USB-IF did a great job in specifying the specification and provide easy-to-use features.
In USB system, there must be a USB host and USB device such as 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. As 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 frame and movie converter 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 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 normal user. Yes, you get it right, though I would say this only happens in 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 “Enumeration” process. Enumeration is the process where the USB host learns about USB device when it was first plugged in. The information needed from the USB device include: communication speed, device class and further investigate the need of 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.
Let’s talk about USB speed.
1.5 Mbit/s is classified as low speed rate and it is being 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 enables 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 in the end of 2009 or early of 2010. The communication speed mentioned above is the data speed for USB raw data communication at hardware layer only. When it goes up to application layer such as file transfer between computer and pendrive, the data rate must minus out the overhead and also data checksum, which resulting lower data rate.
Since USB intends to replace serial port, parallel port and other connectors at the back of 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 them 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-.
The negative (-) or ground pin and the Positive (+) connections are responsible to supply power to USB device. You might ask, what is the voltage and maximum current that a USB hub may provide? There is another myth or doubt need to be clarified because many assume that 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 USB hub. So what is the maximum current a USB hub may supply? How about the external hub that user adds to extend the number of USB connection? 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 to software request 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 hub, namely self-powered and bus-powered. A self-powered USB external hub is a hub powered by 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 of 100mA for itself. This has made up to a total of 500mA from the computer USB hub. Now can you guess what the maximum length of 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.
Ever since the day I started using USB devices such as mouse, keyboard and pen drive, I have been thinking to create a home-made USB device with microcontroller. However, I found out that there is no low cost microcontroller that support USB engine, I ended up hold on to my thought.
Fortunately, recently, Microchip Technology started to venture in USB’s application for its microcontroller and provides great support. From the diagram shown, there are plenty of choices from 8-bit (PIC18F4550), 16-bit to 32-bit microcontroller that support USB peripheral. Now, with the solution from Microchip, you can create your own USB mouse, game controller, serial port, parallel port, keyboard, pendrive and even an USB OTG (On The Go) or USB embedded host. Besides providing support in term 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 welcomed 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 offer USB microcontroller besides Microchip Technology? There are Atmel, Texas Instruments, Cypress, Infineon and NXP, etc. You are free to choose the microcontroller.
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. User 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 USB workshop entitled “USB from Scratch”. This workshop discovers USB’s history, specification, hardware, Microchip Framework, Driver and there are a few hands-on lab exercises which use PIC18F4550 to create USB mouse and USB to RS232 converter.
So, let’s say you need to create a USB device, do you need to pay for license? Reference has to be made to VID and PID because very USB product comes with unique VID and PID. VID stands for Vendor ID while PID stands for Product ID. USB-IF mandates each vendor has their own VID in order to market their 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 regards to this matter.
What are you waiting for? If you like to start, you can get the latest starter kit from Cytron Technologies, SK40C which comes with USB mini socket that supports PIC18F4550 PDIP package. You can download the sample program from Microchip’s website and download into the chip through UIC00A and have a home-made USB device! To get more information about USB from Microchip, please visit: www.microchip.com/usb.
Good luck! If you have question, please do feel free to discuss in our technical forum
Information taken from: