Translate It!

    Translate to:

Print This Page Print This Page

USB Project Development Using PIC18F4550 & PIC18F2550

Items on this page include:

PIC USB development Board

Let me admit it – I’m quite deaf! Despite having a digital hearing-aid in each ear, I still miss hearing the doorbell when I’m working in my den. All to often I find that a parcel delivery has been attempted – the result of my not hearing the doorbell is usually a card inviting me to pick up the parcel at the post-restante not less than 48 hours from the failed delivery attempt. Then there’s the problem of hawkers and cold-callers – on the occasions when I do hear the doorbell, it’s inevitably someone who simply wants to waste my time trying to sell me new windows, a new drive, new roof or whatever. These people get a curt ‘No thank you’. Those that persist get something much stronger – which I won’t repeat here. When I do have to go out, and I’m half-expecting a parcel delivery, I have to stick a hastily-written note on the inside of the window beside the front door. I thought I’d have a go at addressing these issues with a messaging system connecting up the various items and linked in to my PC in the den. It had to be cheap, reliable and easy to modify, so a home-brew solution was sought. I’ve ruled out wireless-connected TCP/IP because to date my experience with wireless networking has been a complete waste of time – with transmission dropping out just when it’s needed. The next choice was a USB-based connection, and so a trial was done with a 20 metre length of high quality cable connecting the PC to a lashed-up USB slave unit based on Microchips 18f4550 PIC. No problems were apparent transmitting short messages and commands. A £5.00 USB camera from Tesco again connected to the PC by high quality cable completes the surveillance part of the system.

Because of the conflicting timing requirements of USB & Servo-drivers, I used a small SPI-connected 2nd microcontroller out of my spares drawer – a PIC18f252. This will easily drive up to 6 model-control servo motors – I used some really old Futaba units from a defunct model car, plus there are a few extra pins for other peripherals if needed.

To facilitate development of the unit I put together the main components of the system on a small PCB provided with 4 X 10-way headers to connect to a breadboard for the hardware development. This article documents the development of the board and software and briefly introduces some of the interfaces I developed for my ‘DCS’. (Door Control System!)

My PIC18F4550 development board has the following features:

  • No SMDs – Standard components throughout
  • Free Single-sided printed Circuit Board Design
  • Free Source Software for all PIC and PC programs, togther with ready-to-run binaries
  • Software Development for PC uses Free Microsoft Visual C++ Express 2008
  • Software development for PIC in Microchip ‘C’ compiler
  • USB Bootloader allows speedy iterative development/testing of software
  • Facility to use either PC or PSU for power supply
  • All port pins available
  • Provision in software for LCD Display, Hexpad, Relay Drivers, input switches, SPI-connected peripherals etc.
The first prototype

The first prototype

 

The prototype connected to a LCD

The prototype connected to a LCD

 

The prototype hooked up to the PC & controlling several relays

The prototype hooked up to the PC & controlling several relays

 

Component (top) side of board

Component (top) side of board

 

Track-side of prototype board (reflected)

Track-side of prototype board (reflected)

 

Schematic (note S2 has been omitted in this version)

Schematic (note S2 has been omitted in this version)

 Components

A word about components. In the above Q1 is a 20Mhz crystal & this frequency is used on all of the USB projects in this section. Load capacitors for the crystal are 33pF. L1 is an inductor, the value of which does not seem to be of much importance, as long as it will carry the current drawn by the micro-controller. It serves mainly to reduce radiated interference and I have used home-made versions (a handful of turns on a small ferrite toroid) as well as the neat little inductors that look like resistors. For pull-up resistors I have used 10Kohms almost exclusively, and for 3mm LED series resistors a value of 1Kohm. Almost all decoupling capacitors are 100nF. (or 0.1uF if you prefer) For N-Channel power MOSFETs I have used are IRF630, chosen for their low ‘on’ resistance and for P-Channel power MOSFETs I favour the FQP17P10 – again for a low ‘on’ resistance. (and price!)

On most of the boards I make, I nearly always implement a connector for the UART, comprising RX, TX and GND, usually to a 6-way pin-header. For those readers not familiar with the FTDI USB->TTL convertor lead, this provides a handy connection to a PC, either as a debug facility, or for uploading new revisions to the PIC using the TinyBld boot-loader. For more information regarding the convertor lead see FTDI here http://www.ftdichip.com/

Downloads

The printed-circuit for the above (bottom tracks) (posted 10 Aug 2008) (PDF format) is here

The printed-circuit (wire links) (posted 10 Aug 2008) (PDF format) is here

The Eagle files for the board (posted 10 Aug 2008) (WinRAR zip file) are here

Added 21st July 2010
The full Eagle project for this board and the version 2 below, including generated Gerber Files is here. Please note, Gerber files can be generated from any Eagle project, and full instructions are available on the web.

TOP

Below: The draft design for my SPI-connected 2nd microcontroller – I use this to control the Tilt & Pan of a £5.00 USB-connected camera, with a good view of anyone at the front door! The FQP17P10 MOSFET is a TO220 100W DMOS unit with a very low ‘on’ resistance, to allow on/off control of the supply to the servos. These are manufactured by Fairchild, and are available from Farnell for a few pence each. This facility can be left out if you regard it as inessential. The TILT/PAN of the camera can now be operated remotely using a couple of slider controls on the PC program. I’ve generalised the implementation of the SPI interface so that this can be expanded to cover controlling further SPI-connected peripherals from the main USB-based controller and ultimately the PC.

Schematic of Servo Controller

Schematic of Servo Controller

Example code (in ‘C’) is included here as an example of how straightforward it is to drive model-control servos.

 PIC USB Door control System

Features supported by the door-control system are:

  • Software update of main processor PIC18F4550 code using Microchips free USB Bootloader.
  • Software update of slave servo-controller PIC18F252 code using free TinyBld bootloader.
  • 2 X High-power Changeover relay contacts. (10Amp at 240V)
  • 4 X Low-power single-pole make relay contacts. (250ma at 24V)
  • Opto-isolated mains-level input.
  • 6 X servo outputs.
  • 1 X stepper-motor interface.
  • Serial (UART) interface.
  • Hexpad.
  • 4 X TTL-level inputs. (Bell-push, door-contacts etc.)
  • LCD Display 20X4 characters. (Display ‘friendly’ messages to callers)
  • Full autonomous operation. (Need not be connected to remote PC)
  • Full control of system from PC. (when connected)
  • PC-program allows use of manual rotary-encoder(s) and joystick for camera focus and Tilt/Pan.
  • Spare input/outputs on SPI-connected slave processor.

The final door-control system has been built on 3 printed-circuit boards, with the main board effectively combining the 2 circuits given above. A web-friendly version of the schematic is given here, and the full Eagle project files are listed later on this page.

Main Controller card.

Main controller card schematic using PIC18F4550 & PIC18F252

Main controller card schematic using PIC18F4550 & PIC18F252

 As with most PIC designs, the real detail is hidden in the installed firmware, and the reader is invited to study the source, whilst looking at the above circuit. However, a quick run-down of the main components and their use may help. Starting on the left, SV10 is mostly used to connect inputs to the main PIC. Note that I have fitted 10Kohm pull-ups on all digital inputs in this circuit. There are also 2 analog-convertor inputs on SV10, but these could easily changed to digital by modifying the software. SV14 together with Q2 are used to illuminate the LCD display, should this be necessary. I’ve included the polarity change-over switch SV14, because I’ve been caught out in the past with manufacturers switching pins positions on the PC2004 displays. You should ascertain the polarity of the LED on your display (if it has one) and fit two links either north or south depending on the LED connection to SV11.

The small group of discrete components R15, C1, C10, D1, and D2 comprise the charge pump to supply the necessary negative bias for the LCD display if necessary. SV13 is used to connect the bottom end of the bias pot. R16 to either connect to the -4.3V charge-pump output, or VSS if the negative bias is not required. SV17 and SV18 can be used to connect a hex-pad if required. S2 is used to reset the main PIC and S3, together with S2 are used to put the PIC in boot-mode, to upload new firmware. Note that there are 2-pin connectors installed where necessary to connect switches etc. external to the board – should this facility be used, then the component can be omitted from the board and installed externally. SV15 is used to connect to the interface (relays) board.

Moving now to the second PIC, the 18F252. This is slave-driven via SPI by the 18F4550, from whence it also steals its system clock, and can also be reset by the main PIC by use of a link connecting RD4 of the main PIC with the MCLR pin on the 18F252. SV8 is used to connect to the stepper-motor, and SV2-SV7 are used to connect up to 6 model-control servos. The power for the servos is switched on or off as required by the MOSFET Q1. (an FQP17P10) SV1 is used to connect to a USB->TTL-level FTDI cable for serial communications to a PC. (mainly to update the firmware) SV9 can be used to control more inputs and outputs if required, as most pins on the connector are uncommitted. The link X4 is used to allow powering of the board by the PCs USB 5V – just for test purposes only. DON’T overload your PCs’ USB supply by connecting relays etc. to it. In this case a separate supply 7.5V – 9V should be connected to X7, and any link on X4 removed. The regulator IC3 is a standard TO220-cased 7805 5Volt 1.5A item.

Downloads

Hardware.

  • The main controller printed-circuit (bottom tracks) (posted 10 Aug 2008) (PDF format) is here
  • The main controller printed-circuit (top tracks or wire links) (posted 10 Aug 2008) (PDF format) is here
  • The Eagle files for the board (posted 10 Aug 2008) (WinRAR zip file) are here

PIC Software.

  • The Servo controller software project source (Microchip C18) and pre-compiled HEX files (posted 10 Aug 2008) (WinRAR zip file) are here
  • The TinyBld boot-loader software project source for the 18F252 servo-controller (Microchip MPLAB assembler) (posted 10 Aug 2008) (WinRAR zip file) is here
  • The main PIC controller software project source (note is work-in-progress) (Microchip C18) and pre-compiled HEX files (posted 10 Aug 2008) (WinRAR zip file) are here
  • The main PIC USB boot-loader software project source (Microchip C18) and pre-compiled HEX files (posted 10 Aug 2008) (WinRAR zip file) are here

PC Software.

The PC Software is provided as a .NET executable together with Visual C++ 2008 source code which are both installed using Setup (inside the WinRAR archive), with both Debug and Release versions. You should unpack the archive, and simply execute the setup.exe file to install. Please note that use of the software can be made in your own projects, whether commercial or otherwise, as long as an acknowledgement is made. Also note that the software is provided on an ‘as is’ basis, should be regarded as strictly a work-in-progress and is not guaranteed in any way by the author.

  • The Debug version (posted 12 Aug 2008) (WinRAR zip file) is here
  • The Release version (posted 12 Aug 2008) (WinRAR zip file) is here

Other links

Check out the following for the excellent TinyBld Bootloader (PC program) by Claudiu Chiculita at his Tiny Bootloader Site

Microchip documents their USB products and provides a download package of executables, necessary drivers together with source examples. I’ve posted a link to a local copy of the MCHPFSUSB Framework 2.2 which is a distribution package containing a variety of USB related PIC18 and PIC24F firmware projects, along with other USB related drivers and resources intended for use on the PC. The USB embedded host stack is API compatible with the USB Device and Embedded Host Stack for PIC32. All release notes are included in the .zip file bundle. This is available here or at Microchips website www.microchip.com/USB

USB sockets can be obtained (along with all the other components, printed circuit board etc., except the PICs) from ESR in Cullercoats, in the North-East of England. ESR will ship, at reasonable cost, to anywhere in the world. www.esr.co.uk

TOP

Interface card.

An interface board has been developed to accompany the above, the schematic for which is as follows:

Interface

Interface

The circuit is very simple, each stage is repeated for as many outputs as necessary. I’ve specified the BS170 MOSFET transistor, because of its low ‘on’ resistance. On my prototype, the first two stages are used to control mains voltages and use changeover contacts, the other 4 relays are low-power DIL types, with simple make contacts. The small circuit built around the 4N25 is used to provide a mains-level to TTL opto-isolated input. With the input to X1 and an isolated TTL-level (active-low) from the collector of the transistor. I use this on my system by connecting two wires across a PIR-controlled spotlight, so that when triggered, the mains voltage (240V) appears across X1. You may need to tweak the values of the input resistors R9-R11 – as the 4N25 sensitivity can vary a lot. Note that the value of the resistors R1-R6 are 10Kohms on my prototype.

Downloads

The interface printed-circuit (posted 10 Aug 2008) (PDF format) is here

The Eagle files for the board (posted 10 Aug 2008) (WinRAR zip file) are here

TOP

Stepper motor controller card.

This is augmented by a simple stepper-motor interface as follows:

Stepper-motor Interface

Stepper-motor Interface

The circuit above is used to drive a uni-polar stepper motor. The specified power MOSFETs have a very low ‘on’ resistance, but if a large motor is to be used, then it is wise to have these on heatsink(s). The LEDs are for re-assurance that the driver is working, but could be omitted if not required.

Downloads

The stepper printed-circuit (posted 10 Aug 2008) (PDF format) is here

The Eagle files for the board (posted 10 Aug 2008) (WinRAR zip file) are here

TOP

View of main controller and interface cards

Main Controller & Interface cards

Main Controller & Interface cards

 

The Relay Interface Card

The Relay Interface Card

 

Rear View of the Controller Prototype whilst testing

Rear View of the Controller Prototype whilst testing

 USB-Connected Rotary Encoder

Although a PC program to remotely-control the camera etc. has been developed, I am old enough to be more comfortable with a real joystick for Tilt and Pan, and a round knob for camera focus.

I tried out 2 different methods of implementing the focus control – one using a standard rotary encoder, and the other a re-cycled Hard Disk motor. Implementing both was an interesting exercise so I’ve included both in the encoder implementation. The standard controller is a Bourns – type ECW1J-B24-AC0024.

Encoder Schematic

Encoder Schematic

 In the above SV1 is used to connect to the re-cycled hard-drive motor. This particular motor has 3 windings connected together with a common. Two of the windings are connected to PH1 and PH2 of SV1 and the common lead connected to COM on SV1. The signals, after amplification by the LM393 comparator, are fed to the PIC RB0 and RB4 inputs. Software sets up RB0 to generate interrupts whenever a negative-going edge appears on RB0 (from PH1) and the interrupt routine triggers the instantaneous read of the RB4 line. From the value read, a determination of whether the encoder is making a clockwise or anti-clockwise rotation. Similarly, the Bourns unit is connected to RB1 and RB5. (these bits have weak pullups enabled) The Bourns unit suffers from serious contact bounce, so I’ve slugged its outputs to RB1 and RB5 with 2 100nF capacitors (connected between each phase and ground), (note NOT mounted on board, but directly on the component) similarly to suppress noise, I’ve also added 100nF to each of the inputs from the comparators. The joystick pots and two other pots (all 10K linear) are connected using SV3. There are sufficient spare pins for other use, should you require it. (I have re-used the circuit board and implemented a hex-pad – see Windows Media Player controller spin-off) The board can be powered via the USB cable, or if you prefer it, install the power regulator etc., and power from a wall-wart. The UART pins are brought out via SV2, to connect an FTDI/USB cable if required for software update using TinyBld. (A USB boot-loader could be used if you prefer, but an extra switch will be required, plus changes to the software.)

Encoder PCB - Components & wire links

Encoder PCB - Components & wire links

 

PCB - Bottom Tracks

PCB - Bottom Tracks

Downloads

Hardware

The Encoder printed-circuit (posted 10 Aug 2008) (PDF format) is here

The Eagle files for the board (posted 10 Aug 2008) (WinRAR zip file) are here

PIC Software

The Rotary Encoder software project source (Microchip C18) and pre-compiled HEX files (posted 10 Aug 2008) (WinRAR zip file) are here

TOP

Rotary Encoder during construction – the re-cycled hard-drive encoder is the large shiny thing towards the rear of the panel

Rotary Encoder during construction

Rotary Encoder during construction

USB-Connected Windows Media Player Controller – a ’spin-off’ project!

USB-Connected PIC Media Controller

USB-Connected PIC Media Controller

Like everyone else these days, I have a plethora of so-called ‘wireless’ gadgets. The problem is, that so have all my neighbours, so that interference and channel-stealing are common. I gave up on my wireless-connected IP network a while ago and installed UTP cables – which now means a trouble-free network. Now one of my PCs is a cheap unit which is used solely as a juke-box, the only problem is that it is not sited in the kitchen, where I like to listen to music whilst preparing food. What I needed was a remote ‘volume’ control and a means of selecting ‘pause’, ‘next track’, ‘previous track’ etc.

Having built the encoder board above, I made another circuit-board and implemented a hex-pad (4X3) to give me the necessary means of control. A PC program periodically polls this USB-connected unit and when necessary sends appropriate messages to both the Windows Media Player and Volume Control. The whole thing took me one morning to code and build and I’m very pleased with the result. Details are published here because it truly is a real ’spin-off’ project.

The completed Windows Media Controller unit using PIC18F2550 encoder card

Windows Media Player Controller

Windows Media Player Controller

View of WMP controller showing minimal population of the encoder card

View of WMP Controller card

View of WMP Controller card

The circuit board is, of course exactly the same, except the LM393 and associated components, and the power-supply are not implemented. A separate PIC software project is not necessary, as I’ve implemented the hex-pad facility into the Encoder software given above. However a separate PC program (and source) are listed below.

Downloads

The PC Software is provided as a .NET executable together with Visual C++ 2008 source code which are both installed using Setup (inside the WinRAR archive), with both Debug and Release versions. You should unpack the archive, and simply execute the setup.exe file to install. Please note that use of the software can be made in your own projects, whether commercial or otherwise, as long as an acknowledgement is made. Also note that the software is provided on an ‘as is’ basis, should be regarded as strictly a work-in-progress and is not guaranteed in any way by the author.

The Debug version (posted 12 Aug 2008) (WinRAR zip file) is here

The Release version (posted 12 Aug 2008) (WinRAR zip file) is here

TOP

Velleman P8055 USB Board Firmware Upgrade

I’ve had the Velleman P8055 card for a while and was never satisfied with either its performance nor firmware. Since the PIC18F2550 is pin-for-pin compatible with the installed PIC18C745, I created a version of the software used in the main system above and installed it in a PIC18F2550, and plugged it in the board. I made a couple of mods to the Velleman card, to support use of the serial port and a reset-switch. (mainly to use the TinyBld bootloader) These are detailed below. By the way, I also removed the resistor connecting VUSB to D-. (between pins 14 and 15) The card can now be controlled from my own PC software and runs at full-speed USB 2.0.

Velleman P8055 Amended Schematic

Velleman P8055 Amended Schematic

Downloads

PIC Software

The Velleman P8055 project source (Microchip C18) and pre-compiled HEX files (posted 10 Aug 2008) (WinRAR zip file) are here

TOP

Copy the code below to your web site.
x 
  • Share/Bookmark

1 comment to USB Project Development Using PIC18F4550 & PIC18F2550

You must be logged in to post a comment.