Monday, May 16, 2011

USB prototyping board part 2: Breadboarding it

You can draw schematics all day long, but the only way to make sure the circuit works is to get busy on the bench. You can see the result in the picture below. I affectionately call it "the world messiest USB keyboard". 

Let's run through the main parts of the circuit:

To Edge Connect or Not to Edge Connect

PCB edge connectors are a cheap and easy way to connect USB devices to a host by using the PCB itself as a USB-A plug. It looks like this:

You really want the PCB to be thick enough so that it lodges tightly into the USB-A socket. A thickness of 2mm is recommended. My manufacturer quoted a surcharge of $40 for 10 PCBs to lay out my design on a 2mm board. An USB-B socket costs 30 cents.

The USB prototype board will not sport a PCB edge connector.

USB prototyping board part 1: Design and Schematic

The USB connector has become the lingua franca of electronics. Whether you need to receive data, send data or just get quick access to DC power, the little USB plugs are now the preferred way to interface with gadgets large and small. Unfortunately, getting USB to work with hobbyist electronics is still a bit of a black art. In order to facilitate experimentation with USB-connected devices, in a series of blog posts we are going to develop a basic, cheap, low part count USB prototyping board.

This project will also double as my first-ever PCB design

Design Outline
There are AVRs that include a USB controller on the microcontroller die, but they are only available in hobbyist-hostile TFQP packages. Instead we are going to base the design on a small 8-bit AVR micro-controller using the VUSB firmware-only USB stack. We want to keep the part cost down, as well as the PCB real estate footprint so that we have more room left over for prototyping. To that end we select an ATTiny micro-controller in DIP8 format. Our micro-controller needs to have at least 4kB of flash memory. The VUSB stack needs 2kB, and we need enough flash left over for the application we are going to prototype. Our micro-controller will be the ATTiny45.

Our main challenge is micro-controller pin allocation: of the eight in the package, two are used up by power and ground, and another one is used up by reset to enable in-system programming. Another two are used by the differential USB transmission lines D+ and D-. Since we'd rather not sacrifice two of our three remaining pins to connect an external clock source (crystal), we will need to use the internal clock at 16.5 MHz. This means that we need to run the micro-controller at 5V. 

According to the VUSB documentation, the reference project for running VUSB ousign the microcontroller's internal oscilaltor is EasyLogger. We will be using this design as a starting point.


As I mentioned before, the schematic is derived from the Easylogger.

Because we are running the micro-controller at 5V, we need to adjust the pull up resistor (R3) upward from 1K5 as mandated by the USB standard so that the proper voltages are seen on the bus on the host side. We also need two zener diodes to limit the voltage on the USB bus. Tip: if you can find LEDs with a forward drop between 3.3V and 3.6V (usually blue), you can use them instead of the zeners to get instant activity indicators. Remember that in this case you need to forward-bias them by connecting the cathode to ground.

We have added two additional connectors. The connector labelled ISP is a standard 6-pin in-system programming connector. This will allow us to program the micro-controller without having to remove it from the circuit. The pull-up resistors on the NRES (R4) and MOSI (R3) pins have been dimensioned not to interfere with ISP. If ISP is not required, this connector can be left unpopulated.

The connector labelled PROTO is a female six-pin connector that enables us to quickly wire any micro-controller pin (with the exception of the ones used for USB communication) to a breadboard using jumper wires. If this functionality is not desired, the header can be left unpopulated. The pads can be connected the prototyping area using components of the circuit being prototyped, wiring or zero-ohm resistors. Note that adding strong pull-up or pull-down resistors to the pins used for ISP can interfere with programming.