introductory interfacing & electronics

53
ACSE Conference 11/2004 Intro. Interfacing & Electronics 1 Introductory Interfacing & Electronics Peter Beens [email protected] Presented at Durham College November, 2004

Upload: lemuel

Post on 21-Jan-2016

62 views

Category:

Documents


0 download

DESCRIPTION

Introductory Interfacing & Electronics. Peter Beens [email protected] Presented at Durham College November, 2004. Overview. This presentation covers a basic introduction to interfacing with the parallel port and just enough electronics to keep you from damaging your computer. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 1

Introductory Interfacing & Electronics

Peter [email protected]

Presented at Durham CollegeNovember, 2004

Page 2: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 2

Overview This presentation covers a basic

introduction to interfacing with the parallel port and just enough electronics to keep you from damaging your computer.

Page 3: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 3

Interfacing Introduction

Page 4: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 4

Interfacing Overview

Computer Interface Peripheral

•Wires•ICs•Resistors•Capacitors•Transistors•Connectors

•LEDs•Motors•Lights•Robots•Joystick•Music Box

Page 5: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 5

What Ports Can We Interface? Parallel Port (AKA Printer Port)

Serial Port (AKA RS232) Keyboard Port USB??? (Hopefully soon…)

We will concentrate on the Parallel Port

Page 6: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 6

Identifying the Parallel Port It’s the female connector with

25 pins “DB25”

Can be on a card

Page 7: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 7

Electronics Introduction

Page 8: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 8

Three Main Invisible Electrical Properties Voltage, V, Volts

Provides the “push” Current, I, Amperes (Amps)

Flow of Electrons Amount of Current is dependent on

Voltage and Resistance Resistance, R, Ohms ()

Limits the amount of current

Page 9: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 9

Safe Current & Voltage Levels Voltage: 30 V

Voltages inside a computer do not exceed 12 V, except at the power supply and power switch on older computers, which are at 120 V.Be careful in these areas!

Current: 5 mA (0.005 Amperes)

Page 10: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 10

Voltage Sources

Page 11: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 11

Current Is the flow of electrons

Direction depends on convention

Conventional Current Flow (+) to (-)

Electron Current Flow (-) to (+)

Page 12: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 12

Ohm’s Law

R

VI

“Current (I) is proportional to Voltage (V) and inversely proportional to

Resistance (R)”

RIV I

VR

Page 13: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 13

Ohm’s Law & Power Wheel

Reproduced by permission of Tony van Roon, 2002 http://www.uoguelph.ca/~antoon

Page 14: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 14

Kirchhoff’s Laws Kirchhoff’s Voltage Law

“The sum of the voltage drops equals the applied voltage”, or…

“The sum of the voltage drops around a closed loop equals zero”

Used in series circuits Kirchhoff’s Current Law

“The current entering a junction must equal the current leaving the junction”

Use in parallel circuits.

Page 15: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 15

Light Emitting Diodes (LEDs)

A type of diode designed toemit light

Can be visible or IR 2 V voltage drop Typically draws 20 mA (0.020 A) Schematic Symbol…

Page 16: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 16

Resistors Can be rated by…

Resistance (Ohms, ) Tolerance (% of nominal value) Power Rating (Watts)

Schematic Symbol…

Page 17: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 17

Resistor Types

Page 18: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 18

Resistor Colour Code

Reproduced by permission of Tony van Roon, 2002 http://www.uoguelph.ca/~antoon

Page 19: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 19

Resistor Colour Code Example

1st band: orange = 3 2nd band: orange = 3 3rd band: red = 2 (i.e. 102) 4th band: gold = 5%

33 x 102

= 3300

= 3.3 k

Page 20: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 20

Resistor Power Ratings

Page 21: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 21

Series Circuits

...21 RRRT

One current path, therefore the current is the same everywhere

Total resistance is the sum of the individual resistances

Page 22: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 22

Parallel Circuits

...21 IIIT

More than one current path Total current is the sum of the

individual currents

Page 23: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 23

The Parallel Port – The Hardware

Page 24: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 24

Parallel Port Specifications Output Voltage

0V for “low” 5V for “high” TTL (Transistor-Transistor Logic)

Output Current Limitation 10-15 mA (careful!)

Page 25: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 25

Parallel Port Pinout

Graphic from http://www.doc.ic.ac.uk/~ih/doc/par/

Page 26: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 26

Output Table

Pin # Label Bit Value2 D0 20 = 13 D1 21 = 24 D2 22 = 45 D3 23 = 86 D4 24 = 167 D5 25 = 328 D6 26 = 649 D7 27 = 128

Page 27: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 27

Input Table

Pin # Label Bit Value15 S3 23 = 813 S4 24 = 1612 S5 25 = 3210 S6 26 = 6411 /S7 27 = 128

Page 28: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 28

Interfacing an LED Circuit

D0

D6

D5

D4

D3

D2

D1

D7

Page 29: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 29

Understanding the LED Circuit The parallel port output is 5V

A standard red LED needs ~20 mA and drops about 2 V

A resistor is needed to “drop” the excess voltage

Page 30: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 30

Doing the Math

LEDRT VVV

150

020.0

3

A

VI

VR

R

R

mAII LEDR 20

V

VVV LEDTR

3

25

R

R

I

VR

From Ohm’s Law

From Kirchhoff’s Voltage Law

Currents equal in a series cct

Page 31: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 31

Motor Control

2N3904

TIP31

(A stepper motor would require more outputs)

D0

M

9V

E

BC

Page 32: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 32

High Current ControlDC Voltage

Source

Relay

Use a relay

Page 33: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 33

Parallel Port Connector Tip

Page 34: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 34

The Programming

Page 35: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 35

Turing: Preparing for Interfacing Turing is already prepared for

interfacing with the parallel port No preparation necessary!

Page 36: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 36

Turing: Turning On the LED Parallelput(value)

Parallelput(1) turns on the 1 bit (D0)

Parallelput(255) turns on all bits (D0-D7)

Page 37: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 37

Turing: Turning Off the LED Parallelput(0)

Page 38: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 38

Turing: Flashing the LEDloop

parallelput (1)

delay (250)

parallelput (0)

delay (250)

end loop

Page 39: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 39

Turing: LED Walking

loop % loops up for i : 0 .. 7 parallelput (2 ** i) delay (500) end for % loops down for decreasing i : 6 .. 1 parallelput (2 ** i) delay (500) end forend loop

Page 40: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 40

Java: Preparing for Interfacing Download

http://www.geocities.com/Juanga69/parport/parport-win32.zip

Extract the parport folder to your classes folder

Copy parport.dll to you bin folder import parport.ParallelPort; ParallelPort lpt1 = new

ParallelPort (0x378);

Page 41: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 41

Java: OutputParallelPort lpt1 = new

ParallelPort(0x378);

int byteVal = 255;

lpt1.write(byteVal);

System.out.println("Output toport: " + byteVal);

Page 42: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 42

Java: InputParallelPort portIn = new

ParallelPort (0x378);

int in;

in = portIn.read ();

System.out.println (in + " is currently being input.");

Page 43: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 43

Java Delay Methodprivate static void delay (int mS)

{

try {

Thread.sleep (mS);

}

catch (Exception e) {

;

}

}

Page 44: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 44

Delphi: Preparing for Interfacing Download io.dll from

http://geekhideout.com/downloads/io.dll

Copy into project folder

Page 45: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 45

Delphi: Outputprocedure PortOut(Port : Word; Data :

Byte); stdcall; external 'io.dll';

procedure TForm1.Button1Click(Sender: TObject);

begin

PortOut(888,1);

end;

Page 46: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 46

Delphi: Inputfunction PortIn(Port:Word):Byte; stdcall;

external 'io.dll';

procedure TForm1.Button3Click(Sender: TObject);

var

InValue : Byte;

begin

InValue := PortIn(889);

label1.Caption := IntToStr(InValue);

end;

Page 47: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 47

Delphi Delay Procedureprocedure xSleep(milliseconds:

LongInt); var iTemp : Longint;

Begin

iTemp:= GetTickCount + milliseconds;

while GetTickCount < iTemp

doApplication.ProcessMessages

End;

Page 48: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 48

Assembler: OutputMOV DX,0378H

MOV AL,n

OUT DX,AL

Where n is the value you want to output.

Page 49: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 49

Resources

Page 50: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 50

Web Resources http://www.epanorama.net/

circuits/parallel_output.html http://www.lvr.com/jansfaq.htm http://www.doc.ic.ac.uk/~ih/

doc/par/ http://www.southwest.com.au/

~jfuller/delphi/delphi1.htm

Page 51: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 51

Textbook References Computer Engineering: An Activity-Based

Approach (Holt) Networks, Interfaces and Integrated

Circuits (Holt)

Page 52: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 52

Q: Why can't programmers tell the difference between Christmas and Halloween?

A: Because DEC25 = OCT31

Page 53: Introductory Interfacing & Electronics

ACSE Conference 11/2004

Intro. Interfacing & Electronics 53

Contact Information Pete Beens

Westlane Secondary SchoolNiagara Falls, ONL2H1T5905.356.2401

Web: http://www.beens.org Email: [email protected]