Sunday, 06 July 2008
 
  Home arrow PIC arrow USB arrow 18F4550 USB Interface  
Main Menu
Home
Car PC
PIC
Electronics
Brewing
Links
Contact Me
FAQs
Forums
PayPal Donation

Enter Amount:

18F4550 USB Interface PDF Print E-mail
Written by Evan   
Sunday, 06 August 2006
Article Index
18F4550 USB Interface
Page 2 - Burning in the Bootloader
Page 3 - USBDemo PIC Firmware and C# Software
Page 4 - Understanding the Demo Firmware

This article contains information about getting a USB interface working between an 18F4550 PIC and a PC using C# .NET 2.0, using the Microchip-supplied driver mpusbapi.dll.  In this article, the PIC is configured using some (slightly modified) demo code originally for the PICDEM FS USB demo board, in which it is configured as a generic class device, with one IN + OUT interrupt endpoint.  The device is set up with a bootloader, allowing the PIC to be programmed through software after the initial programming.  For this article, it should not be necessary for the reader to know much about the details of USB in general, but I would still highly recommend Jan Axelson's book "USB Complete " to anyone interested in going further with USB.  I owe a big thanks to Mat at PICCoder.co.uk for his own PIC USB tutorial, which is what got me started in the first place.

 The Microchip PIC 18F4550 microcontroller is a popular device for interfacing with USB.  Aside from being a very full-featured PIC (by the current standards) it of course has a full-speed USB 2.0 interface built in.  Since much of the existing USB example code is for this device, it makes a good starting point.  The information in this article is expected to be usable on other similar USB-capable PICs (such as the lower-pin-count 18F2550, or the cheaper versions of both chips with less memory space), but conversion is up to the reader. 

Microchip produces a full-speed USB demo board.    The amount of hardware required to get a working USB interface going is very minimal.  Here is a small prototyping board that I made; there are a few surface-mount parts (decoupling capacitors and LED resistors) on the underside, but in all, you can see that it is quite simple.

The board includes the PIC, reset/bootload buttons, USB connector, 4 USB LEDs, a power LED, a spot for an optional voltage regulator for self-powered operation, and the obligatory decoupling capacitors.  You can download the schematic and PCB layout of the board below, made in Eagle 4.16 by cadsoft.de.  One thing of note is that you don't have to use a 20MHz crystal; you can use a number of speeds (4, 8, 12, 16, 20, or 24 MHz) by choosing the right division ratio in the configuration settings later on.

DOWNLOAD PCB + SCHEMATIC FILES
(Cadsoft Eagle 4.16 format)

 

For the purposes of getting started, this circuit can also very easily be built on a breadboard, as you can see.  The USB connector is connected through some short wires to a 4-pin header to plug into the breadboard.  I also included an ICSP connector as you can see, this isn't shown on the schematic because it was only used for the initial programming of the bootloader, and thus isn't very necessary; just pull the chip and program it externally.

 

There are a few things you need to pay attention to.  First, you MUST include the capacitor on pin 18 (Vusb).  This is required by the internal USB voltage regulator.  The actual value is not critical, I believe the actual recommended value is 0.33uF, so use what you've got that's close.  Second, make sure you keep the wires between the USB socket and the PIC pins as short as you can, and make sure to put a decoupling capacitor across the power pins of the USB socket as close to it as you can; I used 0.1uF. 

Once you have that constructed, it's time to get some firmware on it.  In the interest of convenience, it is tremendously beneficial to use a USB bootloader to upload code to the PIC.  Once the bootloader is programmed onto the chip, no separate programmer is needed for development, and the PIC can be programmed quickly and with minimal effort.  So, it's time to get the bootloader set up!

 


Last Updated ( Monday, 02 June 2008 )
 
< Prev
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.
For usage outside the terms of this license, contact me by email to discuss.

© 2008 eegeek.net
Joomla! is Free Software released under the GNU/GPL License.

Get The Best Free Joomla Templates at www.joomla-templates.com