Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views5 pages

Elektorusb

The document describes a USB data acquisition card designed by José Luis Rupérez Fombellida, featuring eight digital inputs and outputs, as well as eight analogue inputs and outputs, all operating within a 0 to 5 V range. Built on a compact PCB using a Microchip PIC18F4550 microcontroller, the card is aimed at providing low-cost connectivity for measurement and control applications. The document also includes details on firmware, construction, and testing procedures for the card and its associated add-on components.

Uploaded by

Mehmet Aşık
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Elektorusb

The document describes a USB data acquisition card designed by José Luis Rupérez Fombellida, featuring eight digital inputs and outputs, as well as eight analogue inputs and outputs, all operating within a 0 to 5 V range. Built on a compact PCB using a Microchip PIC18F4550 microcontroller, the card is aimed at providing low-cost connectivity for measurement and control applications. The document also includes details on firmware, construction, and testing procedures for the card and its associated add-on components.

Uploaded by

Mehmet Aşık
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

projects data acquisition

USB Data Acquisitio


José Luis Rupérez Fombellida

This data
acquisition card
for connection to the USB
has eight digital outputs, eight digital inputs, two 10-bit
analogue outputs and eight 10-bit analogue inputs for
voltage swings of 0 to 5 V. The system’s core is a Microchip
USB-savvy microcontroller type PIC18F4550 programmed in C. The
circuit is built on a compact PCB and requires no external power supply.

Measurement cards and systems you the PC recognise a valid USB device!
can connect to a PC have been a con- In this article hopefully we cater for DIP40 device which should
stant success factor in the long histo- readers only interested in digital and an- attract applause and other
ry of Elektor. Whether it’s stand-alone alogue connectivity with the real world, expressions of approval from
for control over the RS232 or LPT ports as well as for those with a deeper inter- the I-hate-SMDs camp.
(anyone remember those?), as a plug- est in how USB actually works on a mi-
in card for the ISA bus (ditto) or now, crocontroller and, equally important, can
recently, for the USB, it’s a blockbuster be made to do something really useful
The circuit
if our readers can (1) generate and read — all at very low cost, of course. The circuit diagram of this small
digital control signals, and (2) do the wonder of technology is given
same for analogue signals! The card in Figure 1. It’s not much more
described in this article could be at the
PIC 18F4550 for USB than a powerful CPU (IC1) sur-
hub of a great many applications to do Fortunately, there are microcontrollers rounded by input and output
with measurement and control. that make the USB interface between connectors and a few status
the PC (the host) and the circuit we LEDs. The function of the con-
wish to design (the device) more or less nectors is as follows, with the
We want USB transparent. That’s because they are relevant PIC lines in brackets:
Arguably, RS232, ISA and even Cen- provided with dedicated hardware and
tronics are things of the past when it software to implement USB ‘the easy K1 = 8-bit digital output for 0-
comes to digital and analogue signals way’. All totally invisible of course to 5 V TTL swing (RD0-RD7).
specifically for measurement and con- those who just want to use the USB de- K2 = USB connector for linking
trol by/on a PC. USB is the way forward vice yet know nothing about it (which to your PC (RC4-RC5).
both in terms of speed and ease of con- should not include you)! One such K3 = 8-bit digital input for 0-5 V
nection, although the latter is a com- processor is Microchip’s PIC 18F4550, TTL swing (RB0-RB7).
plex matter especially as far as soft- which has the additional advantage of K4 = two analogue outputs for
ware is concerned. For example, a lot lots of (free) software being available 0-5 V swing (RC1-RC2).
of thought (and time) goes into making for it. Also, the device is available as a K5 = 8 analogue inputs (AN0/

16 elektor - 11/2007
on Card digital & analogue;
input & output
+5V +5V
R1
C1 C2

10K
R2 100n 470n
470R
S1

11

32

18
C3

VDD

VDD

VUSB
100n K1 1 6
MCLR RA4
RD0 1 2 RD1
RD2 3 4 RD3 RD0 19 2 AN0
RD0 AN0/RA0 K5
RD4 5 6 RD5 RD1 20 3 AN1
+5V RD1 AN1/RA1
RD6 7 8 RD7 RD2 21 4 AN2 AN0 1 2 AN1
RD2 AN2/RA2
L1 9 10 RD3 22 5 AN3 AN2 3 4 AN3
RD3 AN3/RA3
+5V RD4 27 7 AN4 AN4 5 6 AN5
RD5 28
RD4 IC1 AN4/RA5
8 AN5 AN6 7 8 AN7
* CCP1 1 2 CCP2 RD6 29
RD5 AN5/RE0
9 AN6 9 10
RD6 AN6/RE1
3 4 RD7 30 10 AN7 +5V
C4 RD7 AN7/RE2
5 6
PIC18F4550
10n 7 8 15 33 RB0
RC0 RB0 K3
9 10 CCP2 16 34 RB1
RC1 RB1
K2 CCP1 17 35 RB2 RB0 1 2 RB1
+5V RC2 RB2
1 R3 K4 36 RB3 RB2 3 4 RB3
RB3
2 27R 23 37 RB4 RB4 5 6 RB5
RC4 RB4
3 R4 24 38 RB5 RB6 7 8 RB7
RC5 RB5
4 27R 25 39 RB6 9 10
RC6 RB6
26 40 RB7 +5V
RC7 RB7

OSC1

OSC2
5
6

VSS

VSS
LED0

LED1

+5V

12

13

14

31
R5
R6 R7 R8
1M
X1
* see text
1k

1k

1k
D1 D2 D3
C5 20MHz C6

22p 22p
070148 - 11

Figure 1. Circuit diagram of the data acquisition card with USB connectivity.

RA0-AN7/RE2) for 0-5 V swing. the aid of a PLL and a frequency di- by the author using two free software
visor from the 20 MHz supplied by tools from Microchip: IDE MPLAB V7.5
Internal pull-up resistors are available the quartz crystal. The frequency of and C18 Student Edition V3.02. The
on RB, the digital input port lines. The 48 MHz is an exact multiple of the USB Microchip website has instructions for
analogue outputs have a resolution of bus speed (full speed, 12 Mbits/s). installation and use of both programs.
10 bits each using PWM (pulsewidth The source code of the firmware is dif-
modulation) at 2.9 kHz. If necessary Two status LEDs, D1 and D2, indi- ferent from the Microchip original. All
these outputs can be filtered with a cate the USB status. D3 is obviously project software is available as a free
simple RC network. The DC output the supply power indicator that lights download # 070148-11.zip from our
voltage Vo obtained after the filtering when the card is connected to the USB website at www.elektor.com. You will
may be calculated from: port on your PC. find at least three folders in the archive
The circuit’s supply voltage arrives via file: ‘driver’, ‘firmware’ and ‘PC’. The
Vo = 5D [volts] USB connector K2 and a small choke, content is an Aladdin’s Cave for fans
L1, to suppress noise, with C4 assist- of C, PICs and USB (and that should
where variable D is the duty cycle of ing to that effect. cover a lot of our readers!). A piece of
the PWM, taking a value between 0 That effectively leaves components S1, C code is shown in Figure 2; it’s these
and 1. R1, R2 and C3 at the MCLR input of the PIC fuse settings you’ll need to know
The analogue inputs also have a reso- micro. Well it’s just another wholly tra- if you’re not buying the chip ready-pro-
lution of 10 bits. ditional Reset network. grammed from Elektor.
The firmware file contains the whole
The oscillator in the PIC micro ticks at project and the result of its compilation
20 MHz using quartz crystal X1 and
PIC Firmware called TAD_v1.hex. The microcontroller
the usual pair of small capacitors for Where there’s simple hardware, there’s must be programmed with this file.
the parallel loading, and a high-value a massive amount of software behind it Those of you interested in the deep-
resistor (R5) for the feedback. all and usually lurking inside microcon- er workings of USB should know that
Actually the microcontroller runs at trollers. The firmware (object code) the the connectivity implemented on the
48 MHz, generated internally with PIC is faithfully executing was created card described on this article is de-

11/2007 - elektor 17
projects data acquisition

which the component placement at


both sides is shown in Figure 3. Some
empty space has been left at the short
sides of the board be able to secure it
with screws.
Although building up the board will
be mostly plain sailing for experienced
readers, some remarks may be in order
for those just starting out in USB land
with the present card.
The opening in the collar of each box-
header is an orientation aid and should
be at the edge of the board to enable
an IDC connector on a flatcable to be
plugged in.
SMD components are fitted at both
sides of the board, so carefully study
the two overlays to establish the cor-
rect position and of each part, as well
as the orientation in the case of the
SMD LEDs.
We recommend fitting the programmed
PIC18F4550 in a good quality 40-way
DIL socket. Watch the orientation of
the large IC: pin 1 is near the reset
Figure 2. RU on MPLAB too? Lots of Elektor readers are. The C code for the project also contains useful information on the PIC fuse switch S1.
settings — an ongoing source of confusion to many microcontroller enthusiasts (and not just those on PIC). L1, finally, is a ferrite bead with three
or four holes through which a piece of
enamelled or other stiff wire is pulled.
fined by firmware in the PIC18F4550. Construction A ferrite bead with one hole and three
The following building blocks are used: turns of wire through it should also
bus power mode; custom class; full-speed The circuit is built on a compact dou- work. The final inductance of the RF
(12 mbit/s) and interrupt transfer. ble-sided printed circuit board of choke so made is uncritical.
To avoid possible damage to the PC,
verify that there are no short circuits
or other problems in the pins of USB
Data acquisition card connector K2.

trainer bench First connection


The author has developed four simple add-on cards for testing the data acquisition card for
the following functionalities:
Once the card is fully populated (and
the microcontroller properly pro-
1. LED card: 8 LEDs to visualize the digital output. grammed), connect it to a PC by means
2. Pushbutton and switch card: 4 pushbuttons and 4 switches to exercise the 8 digital inputs. of a standard USB cable. The power
3. LED voltmeter card: two LEDs that change their brightness according to the two analogue LED D3 lights and one of the LEDs D1
outputs. and D2 flashes while the other remains
off. At the same time the PC will tell
4. Potentiometer card: 8 potentiometers for testing correct operation of the 8 analogue inputs.
you that a new USB device has been
connected and that a driver is required.
The data acquisition card and the four Tell Windows where the driver is locat-
cards are shown in the picture. Although ed (folder driver\mchpusb.inf). Once
PCBs are shown and the author has the the driver is installed the USB status
schematics and board designs in OrCAD LEDs flash alternatively. The card is
format, these cards should be easy to then ready for use.
build using Vero board.

VID/PID (Product ID/Vendor ID)


To test the whole system, a program was
developed in C++ CLR, for which the All USB devices have a unique combi-
(free) Visual C++ 2005 Express compiler nation consisting of two numbers so
was used. This program is based on ex- that no two equal devices exist. The
amples from Microchip. first number, VID, identifies the manu-
A screendump of the program is shown facturer of the device and the second,
here. This software is included in the ar- PID, gives the product identifier.
chive file for the project. The combination used in this project
uses as VID the one of Microchip and

18 elektor - 11/2007
as PID the one of a demo card of the
PIC18F4550 Microchip. If the USB Data
Acquisition Card is used for commer-
cial purposes, it is essential to obtain

K3
a different VID/PID set of numbers—
this can be done, for example, through

R1
C3
R2
www.usb.org or through Microchip.

S1
This new combination should be in-
cluded in the source code of firmware

K5
that would be compiled again in or-

K1
der to obtain an updated .hex file
with which the microcontroller is

C1 R5

C5
programmed.

X1
The PC software would also have to

C6
be modified in the same way, since

R6
firmware and software must have the

D2 R7
IC1 K4
same VID/PID. Finally, the driver ‘mch-

C2
R4
R3
pusb.inf’ file would be modified.

D1
D3
Precautions

C4
K2

R8
L1
Some general precautions must be
mentioned. All expansion connectors
K1, K3, K4 and K5 include +5 V and
ground to power any cards that can be
connected to them. Great care must be Figure 3. Top side and bottom side component placement for the PCB. The PCB artwork is a free pdf download from our website but
taken to prevent short circuiting these bear in mind that the board is double-sided and through-plated.
terminals and not drawing more than
100 mA from any of them. Also, remem-
ber that these terminals are directly — avoid using family or kiddies PCs in ternal power supply, joining only appli-
connected to the +5 V and ground of any case). cation and USB Data Acquisition Card
the USB port of your computer (and If you need more current for a certain grounds.
you do not want that to take damage application, consider the use of an ex- Some precautions for the digital inputs

COMPONENTS LIST
Resistors
(all SMD 0805 case)
R1 = 10kΩ
R2 = 470Ω
R3,R4 = 33Ω
R5 = 1MΩ
R6,R7,R8 = 1kΩ

Capacitors
(all SMD 0805 case)
C1,C3 = 100nF
C2 = 470nF
C4 = 10nF
C5,C6 = 22pF

Semiconductors
IC1 = PIC18F4550 I/P, programmed, Ele-
ktor Shop # 070148-41
D1,D2,D3 = LED, SMD case 1206

Miscellaneous
K1,K3,K4,K5 = 10-way boxheader
K2 = type-B USB connector, PCB mount
X1 = 20MHz quartz crystal
L1 = VK200 or small ferrite bead with 2-
4 turns thin enamelled copper wire
S1 = pushbutton, PCB mount, 6mm
footprint
DIL40 socket for IC1
PCB (bare), Elektor Shop # 070148-1
Project software, file # 070148-11, free
download from www.elektor.com.

11/2007 - elektor 19
projects data acquisition

Files & file locations If you wish to modify the project to adapt it to your requirements it is
necessary to install the Visual compiler Microsoft C++ 2005 Express
and update it with Service Pack 1: Visual C++ 2005 Express SP1.
The complete project of the application for the PC is in PC\ TAD_V1_
Later we will install Microsoft Platform SDK for Microsoft Visual C++
win\ folder and its name is TAD_V1_win.vcproj. The compiled pro-
2005 Express. This serves to develop WIN32 applications, necessary
gram is in PC\TAD_V1_win\Release folder and its name is TAD_V1_
in this case to access the DLL mpusbapi.dll). All of it is free and can be
win.exe (for the program to work, the dynamic link library mpusbapi.
downloaded from the Microsoft website. There you will also find in-
dll created by Microchip must be in that same folder). The executable
structions about installation and examples.
one needs the .NET Framework. It is highly recommended to have the
operating system updated by means of Windows Update.

(K3): Do not apply voltages below zero in a comfortable manner. This card is
or higher than 5 volts to avoid damage
to the PIC microcontroller.
isolated using optotriacs.
2. Resistor-to-voltage converter card
About the
On the digital outputs (K1): each line
can supply a maximum current of
supplying a voltage proportional to the
input resistor. This voltage is applied
author
25 mA for logic High or Low levels. to the digital input. The author is a telecommunications tech-
On the analogue inputs (K5); the same 3. Voltmeter card with LED bar nical engineer working as a teacher of
as with the digital inputs. readout. electronics in a professional school in
On the analogue outputs (K4): each 4. Speed control of a DC motor. This Madrid since 1984. He is a keen electron-
ics enthusiast. He developed this card to
line can supply a maximum current of card controls the speed and direc-
enable his students to control small robots
25 mA for logic High and Low levels of tion of a motor through the analogue from the USB port in a PC by programmes
the PWM signal. outputs. written in C code.
Finally, the sum of all currents of all the 5. Driver card for stepper motors, capa-
digital and analogue outputs must not ble of microstepping through the dig-
exceed 200 mA. ital outputs.
6. Distance sensors card using the ana-
logue inputs.
Work in progress… 7. Relay card under control of the dig-
The USB data acquisition data card has ital outputs.
a lot of potential and the author has de-
veloped, and is busy developing, the Elektor and the author welcome other
following application cards: applications you may have developed.
Let us know!
1. Triac card for the 8 digital outputs, to (070148-I)
be able to control mains-powered loads

Follow these steps 5.2. Update the corewin_express.vsprops file.


One more step is needed to make the Win32 template work in Visual
C++ Express. You need to edit the corewin_express.vsprops file (found
The PC software available for this project should be relatively easy to
in C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults)
install use and/or adapt if you follow these steps.
and change the string that reads:
AdditionalDependencies=”kernel32.lib” to:
1. Install Visual C++ 2005 Express:
AdditionalDependencies=”kernel32.lib user32.lib gdi32.lib winspool.
http://msdn2.microsoft.com/en-us/express/aa975050.aspx)
lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.
2. Install Visual C++ 2005 Express SP1: lib”.
http://msdn2.microsoft.com/en-us/express/aa975050.aspx
5.3. Generate and build a Win32 application
3. Install PSDK: Microsoft Platform SDK for Microsoft Visual to test your paths.
C++ 2005 Express: In Visual C++ Express, the Win32 Windows Applicati-
http://msdn2.microsoft.com/en-us/express/aa975050.aspx on type is disabled in the Win32 Application Wizard. To ena-
4. Update the operating system using Windows Update. ble that type, you need to edit the file AppSettings.htm file lo-
cated in the folder “%ProgramFiles%\Microsoft Visual Studio
5. Tell Visual C++ to use PSDK.
8\VC\VCWizards\AppWiz\Generic\Application\html\1033\”.
The sequence to do so suggested by Microsoft is given below.
In a text editor, comment out lines 441 - 444 by putting a // (double
5.1 Update the Visual C++ directories in the Projects and
slah forward) in front of them as shown here:
Solutions section in the Options dialogue box.
Add the paths to the appropriate subsection: // WIN_APP.disabled = true;
Executable files: C:\Program Files\Microsoft Platform SDK for Windows
// WIN_APP_LABEL.disabled = true;
Server 2003 R2\Bin;
// DLL_APP.disabled = true;
Include files: C:\Program Files\Microsoft Platform SDK for Windows
Server 2003 R2\Include; // DLL_APP_LABEL.disabled = true.
Library files: C:\Program Files\Microsoft Platform SDK for Windows Save and close the file and open Visual C++ Express.
Server 2003 R2\Lib.

20 elektor - 11/2007

You might also like