Sunday, December 16, 2007

The Brain

Well, the first thing that comes to your mind as soon as you think about a new robot is how are you gonna control the whole thing. I have used Microchip's PIC18F4550 controller for the purpose. The best part of this controller is its inbuilt support for USB interface.
Here are various steps for implementing this microcontroller....

Step 1: Build an USB devlopment board based on a PIC18F4550

Minimum requirement arround the PIC:
- an 20MHz crysal oscillator & the two 15 or 22pF associated capacitors.
- an USB-B connector powering the PIC (Vss & Vdd) and linked to D- & D+ pins.
- a 'decoupling' capacitor between Vss & Vdd (100nF & eventualy an other between 1 and 10 uF)
- a 'decoupling' capacitor between Vss & Vusb (220nF min, 470nF is also good)
- a button/switch S1 for hard reset on MCLR'
- a button/switch S2 for entering in Boot mode on RB4.



Step 2: Install needed softwares, get Boot Firmware Source Code & PDFSUSB utility
Microchip MPLAB 7.00+ available from http://www.microchip.com/ide/
Microchip C18 2.40+ Student Ed from http://www.microchip.com/c18/
Microchip USB Bootloader files

Step 3: Connect USB & 1st bootload detection
Connect the USB cable. It powers the PIC (not visible at this time).
Enter Boot Mode by holding down S2 (enter boot) and then pressing S1 (reset).
Normally, Windows will start detecting a new USB unknown device.

Step 4: Manually specify Microchip "PIC18F4550 Family Device" INF driver to MSWindows
At this point, you must have a window asking a driver for the new USB device.
The procedure depends on your Operating System version.

For Win XP, refuse Windows Update search, then choose "install from specific location", and "include the following location in the search": C:\MCHPFSUSB\Pc\MCHPUSB Driver\Release\
It should be recognised as "PIC18F4550 Family Device".

Ok, all is configured.

Note: I am assuming that you have already boot loaded your PIC.

Step 5: Testing a code on the PIC

Let us run the Microchip Demo02 project, a test program that can be USB-bootloaded.


1)Open the project "C:\MCHPFSUSB\fw\Demo02\Demo02.mcp" in MPLAB. Click 'Build all' or press Ctrl+F10.
2) On the BOARD enter Boot Mode by pressing [S1 Reset] while maintaining [S2 enter Boot].
3) Lauch Microchip tool : "C:\MCHPFSUSB\Pc\Pdfsusb\PDFSUSB.exe" (I call it "Microchip USB-Bootload utility").
4) In the drop-down list, select your PIC, actualy named "PICDEM FS USB 0 (Boot)".
5) Click "Load HEX File" : "C:\MCHPFSUSB\fw\Demo02\Demo02.hex" .
6) Click "Program Device".
7) Click "Execute" to start the PIC in user mode (ignore the error).
8) On the BOARD with this Demo02 program, when pressing S2, the state of pin RD1 must change (0V to 5V...).


Step 6: So, finally we can now program this PIC with our own programs written in language C. For details like the pin diagram of the PIC read its datasheet. You can get it from www.create.ucsb.edu/~dano/CUI/PIC18F4550datasheet.pdf

3 comments:

ProblemSolver said...

wonderfully done... i can see this is going to be really helpful to get me started...

G Kills said...

if the originally loaded firmware gets erased and now if we connect the pic to the pc then no new hardware is added & aso in the usb-bootloaded no option to select a pic appears.
now what do i do to fix this problem

G Kills said...

u can reply me on gundeep_1@yahoo.co.in
or
put the solution on ur blog