7
8/9/2019 e051034.pdf http://slidepdf.com/reader/full/e051034pdf 1/7

e051034.pdf

Embed Size (px)

Citation preview

Page 1: e051034.pdf

8/9/2019 e051034.pdf

http://slidepdf.com/reader/full/e051034pdf 1/7

Page 2: e051034.pdf

8/9/2019 e051034.pdf

http://slidepdf.com/reader/full/e051034pdf 2/7

elopment Board

The PIC18F452 has become the de-

facto standard part of the 18F series,

and is an obvious choice for people

wishing to move on from designs

using the ubiquitous PIC16F84 and

16F877 devices.

PIC18flash offers the usual develop-

ment board features of a processor,

clock, some LED’s, some pushbuttons,

an interface to a standard 2×20 line

LCD display, an RS232 port, a piezo

ceramic sounder and DC power regu-

lation. Special features are:

– On-board hardware for ICSP (In-Cir-

cuit Serial Programming)

– Power I/O for real-world devices such

as solenoids, stepping and DC

motors.

– An interface to the Microchip ‘ICD-2’

debugger

With this hardware, the free Microchip

‘MPLAB’ development environment

and a free demonstration copy of the

‘C18’ compiler, you are able to develop

PIC ‘C’ code on a standard PC, and

upload it to the PIC18Flash board to

build sophisticated control systems for

many applications including robotics,

home automation, security and more.A ‘C18’ example program is provided,

demonstrating how each subsystem of

the PIC18Flash board is accessed from

the ‘C’ environment. As a self con-

tained development environment, the

PIC18Flash board provides an excel-

lent platform for educators and individ-

uals wishing to enter the world of

microcontrollers.

Circuit Description The circuit diagram of the develop-

ment system is shown in Figure 1.

Much of the circuit techniques will be

quite familiar to Elektor Electronics

readers, and the 78xx-based power

supplies (IC1; IC2, IC9) and MAX232

RS232 serial interface (IC5) constella-

tions have appeared countless times

beforehand.

The PIC18F452, IC6, is configured in a

standard manner, with the possible

exception of the secondary 32.768 kHz

watch crystal, X1, being provided to

allow real-time clock systems to be

implemented without consideration of

the master clock frequency. The mas-

ter clock runs at 4 MHz (X2), giving a

throughput of 1 MIPS, and this can be

internally multiplied by a 4×PLL to

16 MHz, which results in a processor

throughput of 4 MIPS. Users requiring

still more performance can substitute

a 10-MHz crystal, giving 10 MIPS

when used with the 4×PLL.

The 4 MHz ‘f osc’ value is not chosen

arbitrarily; this clock rate is a good ‘fit’

with the PIC’s USART baud rate gen-

erator and enables the generation of

RS232 data at 1.2 to 76.8 kbps with an

accuracy of better than 0.16%.

Processor pins assigned to SPI and I2C

communications are routed to header

K8 for expansion purposes; it is

intended that any add-on hardware

would communicate solely by these

protocols and any communication to a

host computer would be via RS232.

The SPI/I2C header also delivers a

spare processor pin (W; pin 7 on K8)

which can be used for example to bit-

bang other protocols such as the Dal-

las One-Wire interface.

In order that the PIC18Flash can per-

form some real work, the basic board

is equipped with several power

devices intended to permit the control

of relays, solenoids, lamps, DC motors

and stepper motors. Two separately

powered Infineon TLE4207 H-bridges,

IC3 and IC4, are provided, which per-

mit the bidirectional control of two DC

motors, or one bipolar stepper motor.

Two power MOSFET switches are also

provided. Via connector K6, they can

be used to control resistive or inductive

loads such as solenoids and lamps.

A pinheader, K7, for the ubiquitous

2?20 character LCD module is pro-

vided, and this is configured as a stan-

dard 4-bit interface, with the onlyunusual feature being the use (via the

RC2 line) of the PIC’s PWM module to

provide software control of display

contrast.

1/2005 - elektor electronics 35

The development system described in this article continues afine tradition of Elektor Electronics microcontroller articles,

and follows in the lineage of the popular PICee board,

AVRee and others. The board described here employs the

most recent and powerful of Microchip’s PIC family, the ‘18F’

series, and specifically, the PIC18F452.

Page 3: e051034.pdf

8/9/2019 e051034.pdf

http://slidepdf.com/reader/full/e051034pdf 3/7

Finally, an RJ-11 header, K2, is pro-

vided to enable the use of Microchip’s

ICD-2 in circuit programmer / debug-

ger, which enables the target hard-ware to be debugged in real-time. The

user should take care not to use the on-

board (MTSP) programmer and the

ICD-2 interface at the same time!

Introducing theMTSP programmer

An important feature of the PIC18Flashsystem is the provision of onboard pro-

gramming electronics. This enables

the user to flash the microcontroller

without having to remove the PIC from

its socket and load it into a standalone

programmer.

In 1996, the ‘Tait Classic’ programmer

design was widely published,enabling the PIC16 series to be pro-

grammed using a PC parallel port and

some simple software. Since then,

many variations on the Tait theme

elektor electronics - 1/200536

C 8

1 0 0 n

C 6

1 0 0 n

+ 5 V

X 2

4 MH z

C 1 9

2 2 p

C 2 0

2 2 p

7 4 H C T 5 4 1

I C 7

1 1

1 2

1 3

1 4

1 5

1 6

1 7

1 8

1 9

E N

2 3 4 7 8 9 5 6

&

1

R J - 1 1

K 2

1 2 3 4 5 6

K 4

1 0

1 1

1 2

1 3

1 4

1 5

1 6

1 7

1 8

1 9

2 0

2 1

2 2

2 3

2 4

2 5

1 2 3 4 5 6 7 8 9

K 3

1 2 3 4 5 6 7 8 9

MA X 2 3 2

T 1 O U T

T 2 O U T

R 1 O U T

R 2 O U T

R 1 I N

I C 5

T 1 I N

T 2 I N

R 2 I N

C 1 –

C 1 +

C 2 +

C 2 –

1 1

1 2

1 0

1 3

1 4

1 5

1 6

V +

V -

7 8

9

3 1 4 5

2 6

+ 5 V

R 2 1

1k5

R 2 2

1k5 C 2 5

1 0 0 n

C 2 2

1 0 0 n

R 1 1

4k7

9

8

1

I C 8 .D

5

6

1

I C 8 . C

R 9 1

k 5

R 1 3

4k7

3 4 1

I C 8 .B

R 7

680Ω

1 1

1 0

1

I C 8 .E

1

2

1

I C 8 .A

1 3

1 2

1

I C 8 .F

+ 5 V

T 4

B S 1 7 0

D 1 2

1 0 M Q 0 6 0 N

D 1 3

R 1 4

4k7

R 1 7

10k

T 3

+ 5 V

S 1

S 2

S 3

R

1 9

1k

R 1 2

1k

R 2

680Ω

R 3

680Ω

D 6

D 7

D 8

R 4

680Ω

R 5

680Ω

D 9

D 1 0

+ 5 V

+1 2 V '

+1 2 V '

C 9

2 2 µ

2 5 V

C 1 0

2 2 µ

2 5 V

K 5

D 5

T 2

R 1 0 1

0 0 Ω

D 4

1 0 M Q 0 6 0 N

T 1

I R L L 0 2 4 N

R 8 1

0 0 Ω

K 6

R 1 6

10k

B Z 1

+1 2 V

1

2

3

4

5

6

7

8

9

1 0

K 8

+ 5 V

1

2

3

4

5

6

7

8

9

1 0

1 1

1 2

1 3

1 4

K 7

1 5

1 6

+ 5 V

R 1 8

1k

T L E 4 2 0 7 G

I C 3

O U T 2

O U T 1

I N 2

I N 1

I N H

1 1

1 0

1 3

E F

1 4

1 2

5

6

1

2

4

9 7

8

3 T L E 4 2 0 7 G

I C 4

O U T 2

O U T 1

I N 2

I N 1

I N H

1 1

1 0

1 3

E F

1 4

1 2

5

6

1

2

4

9 7

8

3

R 1 5

4k7

X 1

3 2 .7 6 8 k H z

C 1 8

1 5 p

C 1 7

1 5 p

R E 0 / R D / A N 5

R E 1 / WR / A N 6

R E 2 / C S / A N 7

P I C 1 8 F 4 5 2

R A 4 / T 0 C K I

R C 0 / T 1 O S O

R C 1 / T 1 O S I

R C 2 / C C P 1

R D 0 / P S P 0

R D 1 / P S P 1

R D 2 / P S P 2

R D 3 / P S P 3

M C L R / T H V

P S P 7 / R D 7

P S P 6 / R D 6

P S P 5 / R D 5

P S P 4 / R D 4

R C 3 / S C K

S D I / R C 4

S D O / R C 5

R A 3 / A N 3

R A 2 / A N 2

R A 1 / A N 1

R A 0 / A N 0

R A 5 / A N 4

P GD / R B 7

P G C / R B 6

P GM / R B 3

I N T / R B

0

T X / R C 6

R X / R C 7

I C 6

O S C 1

O S C 2

R B 5

R B 4

R B

2

R B

1

1 2

4 4

3 4

1 3

3 5

1 4

1 5

1 0

1 1

1 6

1 9

2 0

2 1

2 2

2 3

2 4

2 5

2 6 2

7 2 9

1 8

4 3

4 2

4 1

3 9

3 8

3 7

3 6

3 3

3 2

3 1

3 0

2 7 6 5 4 3 8

9

B S

1 7 0

K 1

D 1

1 N 4 0 0 1

C 1 4

7 0 µ

2 5 V

C 2

1 0 0 n

7 8 0 5

I C 1

C 4

1 0 0 n

R 1 6

8 0 Ω

D 2

C 3

1 0 0 n

7 8 1 2

I C 2

C 5

1 0 0 n

R 6 1

k 5

D 3

+ 5 V

+1 2 V

K 9

D 1 1

1 N 4 0 0 1

C 2 6

1 0 0 µ

2 5 V

C 2

1

1 0

0 n 7 8 1 2

I C 9

C 2 4

1 0 0 n

+1 2 V '

I C 7

2 0

1 0

I C 8

1 4 7

C 7

1 0 0 n

+ 5 V

M C L R

P GD

P G C

T X D

R X D

M C L R

P GD

P G C

SDO

SDA

1-W

PGM

SS

SCL

S P I / I 2 C / 1 W / GP I O

2 x

D C M OT OR

2 x

D C L OAD

CONTRAST

D6

D4

RW

D5

D7

RS

EN

L C D

+1 2 V

0 4 0 0 1 0 - 1 1

I C 8

=7 4 H C T 1 4

2 x

2 x

2 x

C 2 3

1 0 0 n

C 1 5

1 µ

C 1 6

1 µ

C 1 1

1 µ

C 1 4

1 µ

C 1 3

1 µ

C 1 2

1 µ

V +

Figure 1.The circuit diagram of the PIC18Flash board reveals a classic microcontroller design.

Page 4: e051034.pdf

8/9/2019 e051034.pdf

http://slidepdf.com/reader/full/e051034pdf 4/7

have appeared, and several good soft-

ware programmers have been written

with (David) Tait hardware support.

The original Tait design does not work

correctly with the PIC18F series, so we

present a new implementation of the

Tait standard, compliant with the

PIC18F and with a low component

count. The design is called MTSP – ‘ My Tait Serial Programmer ’. (note that

‘serial’ indicates that the hardware

programs the PIC serially, using a PC

parallel interface.)

The MTSP design criteria were:

– Must support HVP (high voltage pro-

gramming). LVP (low voltage) pro-

grammers are easier to construct,

but if the user inadvertently un-sets

the LVP enable bit, then LVP is dis-

abled and the part can only be re-

programmed in a HVP programmer.

– Must use a standard interface, and

be supported by a good, public

domain software programmer. MTSP

implements the ‘Tait Classic’ or ‘Tait

Serial’ interface and can be pro-

grammed using the freeware ‘IC-

Prog’.

– Must be able to remain in circuit dur-

ing the program-test-debug cycle.

MTSP tri-states PGD/PGC and raises

MCLR to allow the target processor

to run while not in program mode.

The MTSP port is accessed via ‘printer’

connector K4.

Printed circuit board assembly

The PIC18Flash board (Figure 2) uses

a mixture of pin-thru-hole and SMD

technologies in order to produce a PCB

that is both compact and yet quite

easy to assemble. Ready-made printed

circuit boards for this project (double-

sided, through-plated) are available

from our Readers Services under no.

040010-1. All surface mount compo-

nents are ‘1206’ size or larger, and can

be soldered using a fine soldering iron

and tweezers. Similarly, there are sev-

eral surface mount ICs to be fitted.

It is advisable to assemble the PCB in

the following sequence:

1. Power supply. Once the PSU parts

are installed, test that 5 V and 12

V exist and the PSU LEDs D2 and

D3 light up.

2. All SMD resistors, capacitors andremaining LED’s.

3. All small-outline ICs.

4. All remaining pin-thru-hole (leaded)

parts.

1/2005 - elektor electronics 37

C 1

C 6

C 9

C 1 0

C26

D 1

D2

D3

D4

D 5

D 6

D7D8D9D10

D 1 1

IC1

IC2

I C 6

IC7

IC8

IC9

K1

K2

K3

K 4

K5

K6

K 7

K 8

K9

R 8

R 1 0

R 1 2

S1

S2

S3T1T2

T

3

T 4

X 1

X 2

+0 + +DC

LOAD

Bz1

V+ T

2 x DC motor

0 4 0 0 1 0 - 1

C 2

C 3

C 4

C 5

C 7

C 8

C11

C12

C 1 3

C 1 4 C

1 5

C16

C17

C18

C19

C20

C21

C 2 2

C23

C 2 4

C

2 5

D 1 2

D 1 3

IC3

IC4

IC5

R 1

R2R3R4 R 5

R 6

R 7

R9

R 1 1

R

1 3

R14

R 1 5

R16

R 1 7

R 1 8

R 1 9

R 2 1

R 2 2

Figure 2. PCB artwork designed for the PIC18Flash board(board available ready-made).

COMPONENTSLISTResistors:All resistors SMD, case shape 1206

R1-R5,R7 = 680ΩR6,R9,R21,R22 = 1kΩ5R8,R10 = 100ΩR11,R13,R14,R15 = 4kΩ7R12,R18,R19,R20 = 1kΩR16,R17 = 10kΩ

Capacitors:All capacitors SMD, case shape 1206

unless otherwise indicatedC1 = 470µF 25V radialC2-C8,C21-C25 = 100nFC9,C10 = 22µF 25V radialC11-C16 = 1µFC17,C18 = 15pFC19,C20 = 22pFC26 = 470µF 25V radial

Semiconductors:D1,D11 = 1N4001

D2,D3,D6-D10 = LEDD4,D5,D12,D13 = 10MQ060NT1,T2 = IRLL024NT3,T4 = BS170IC1 = 7805

IC2,IC9 = 7812IC3,IC4 = TLE4207GIC5 = MAX232ACSE (SMD case)IC6 = PIC18F452-I/LIC7 = 74HCT541IC8 = 74HCT14

Miscellaneous:K1,K9 = 2-way PCB terminal block, lead

pitch 5mmK2 = 6-way RJ11 connector, PCB mountK3 = 9-way sub-D socket (female),

angled pins, PCB mountK4 = 25- way sub-D plug (male), angled

pins, PCB mountK5,K6 = 4-way PCB terminal block, lead

pitch 5mm (or 2 off 2-way)K7 = 16-way boxheaderK8 = 10- way boxheaderS1,S2,S3 = miniature pushbutton, 1

make contact, e.g., DTS61K (6 x 6mm)BZ1 = AC buzzerX1 = 32.768kHz quartz crystalX2 = 4MHz quartz crystal44-pin PLCC socket for IC6.20-pin DIL socke for IC7

14-way DIL socket for IC8PCB, order code 040010-1, seeReaders Services page

Disk, misc. software utilities, order code040010-11 or Free Download

Page 5: e051034.pdf

8/9/2019 e051034.pdf

http://slidepdf.com/reader/full/e051034pdf 5/7

We recommend fitting the 74HCT541

and the 74HCT14 in sockets.

Once the board is fully populated,

apply a power supply of roughly 15

VDC to K1 and confirm that the

PIC18Flash board draws a quiescent

current of around 50 mA. Once the

board has powered up correctly, it is

time to attach an LC display, flash the

CPU and test each subsystem on the

board.

Flashingthe demo firmware

Traditionally, one writes and loads a

‘flash-an-LED’ or ‘Hello World’ program

to test a microcontroller board. Here, asuccessfully blinking LED confirms

that the CPU is powered, has a viable

clock, and is executing code. We have

provided self-test firmware which not

only flashes LEDs but also exercises

the serial port, the sounder, the LCD,

the MOSFET switches, the H-Bridges

and the real time clock. The construc-

tor should upload this demo firmware,

PIC18flash.hex to the microcontroller

using the IC-Prog programming soft-

ware to fully test the PCB. The source

code, PIC18flash.c can then be used as

a template for further developments.

Configuring IC-Prog Download the archive files

icprog105c.zip and icprog_driver.zip

from www.ic-prog.com and extract

icprog.exe and icprog.sys to a suitable

folder on your hard drive.

If you are running Windows 2000 orWindows XP, you should enable

access to the parallel port as follows:

right click on icprog.exe, and select

the Compatibility tab. Check the Run

this program in compatibility mode for

option and select Windows 2000 in the

drop down box; see Figure 3.`

Now run icprog.exe and you will be

prompted to configure the programmer

interface; see Figure 4.

Select Settings, Options, Misc and

select the Enable NT/2000/XP Driver checkbox, and set Process Priority to

High; see Figure 5.

Click ‘Yes’ to install the icprog.sys

driver when prompted and finally

select the PIC18F452 microcontroller

type as shown in Figure 6.

Uploadingthe demo firmware using IC-Prog

Download the Elektor PIC18Flash

demonstration firmware, file number

040010-11.zip from the Free Down-

loads page at www.elektor-electron-

ics.co.uk and unpack the zip file to a

suitable folder.

Connect a short parallel cable between

the PC printer port and the PIC18Flash

MTSP port K4, run IC-Prog and select

File, Open File, PIC18flash.hex. Now

click Command, Program All to

upload the demo firmware. At the end

of the program / verify sequence, the

PIC CPU will start to run, and will

begin to cycle through a sequence of

hardware subsystem tests.

Each test is depicted on the LCD dis-

play and are:

1. LCD display test. Data is displayed

on the LCD display.

2. Speaker test. A sequence of audio

tones is generated.

3. LED test. The on-board LEDs are

illuminated in sequence.

4. DC Load test. 12-V DC loads con-

nected to JPXX and JPXX are ener-

gized.

5. H-Bridge test. 12-V DC motors con-

nected to K5 are spun in forward

and reverse directions.

6. RS232 comms test. Data is emitted

from the RS232 port, K3, at a bau-

drate of 9600,8,N,1 and this data

can be viewed by connecting the

port to a PC COM port and using

Hyperterminal or similar to display

the data stream.

7. Real Time Clock (RTC) test. Tests the 32-kHz crystal timebase and

runs forever. Hours and Minutes

can be incremented using the

pushbuttons.

elektor electronics - 1/200538

Figure 3. Our finished and tested prototype of the PIC18Flash development board.

Page 6: e051034.pdf

8/9/2019 e051034.pdf

http://slidepdf.com/reader/full/e051034pdf 6/71/2005 - elektor electronics 39

Figure 4. IC-Prog properties.

Figure 5. IC-Prog Programming. Figure 6. IC-Prog Driver.

PIC18F452 FeaturesThe PIC18F452 has a similar pinout to the venerable

PIC16F877 and as such is a natural upgrade to that device,

but offers much higher capabilities and performance:

– High Performance Harvard RISC CPU optimized for C com-piler usage

– Linear program and data memory,

– 32K Flash ROM, 1536 bytes RAM, 256 bytes EEPROM

– 10 MIPS performance at 40 MHz clock

– 16 bit instructions, 8 bit data path

– 4 separate Timer modules (Timer0,1,2,3)

– 25-mA sink & source current

– 3 external interrupt pins

– High & low priority level assignments for interrupts

– Secondary oscillator for timekeeping using a watch xtal

– 2 capture compare (CCP) & pulse width modulation (PWM)modules

– Master Synchronous Serial Port (MSSP) supporting SPI & I2C

– Addressable USART supporting RS232 and RS485

– Parallel slave port (PSP)

– 10 bit analogue to digital converter (ADC)

– Programmable low voltage detection and brown out reset

– 100,000 erase/write cycle endurance on Flash ROM

– 1,000,000 erase/write cycle endurance on EEPROM

– EEPROM data retention of >40 years

– Self-programmable, and programmed code protection

– Power on reset, power up timer, oscillator startup timer

– Low power sleep mode

– x4 PLL on main oscillator

– In circuit programming (ICSP) and in circuit debugging (ICD)

– Wide operating voltage of 2.0 V to 5.5 V

About the AuthorPeter Moreton (42) has beeninvolved with computers and elec-tronics since his youth. Working for

various international banks, he hasarchitected computer networks that span the globe. He welcomes emailcorrespondence at [email protected] and willhost firmware updates and circuit

ideas at:http://freespace.virgin.net/peter.moreton

Page 7: e051034.pdf

8/9/2019 e051034.pdf

http://slidepdf.com/reader/full/e051034pdf 7/7

Compiling the demo firmware using MPLAB/C18

The demo firmware is written in ‘C’

and designed to be used as a basis

for custom application development,

since it provides a template showing

how each of the PIC18Flash subsys-

tems can be manipulated from the ‘C’

environment.

You should download and install the

latest releases of MPLAB and

C18demo from www.microchip.com,

and from within MPLAB, select Pro-

ject, Open, PIC18flash.mcp. ‘C’ source

code can now be edited and then

compiled by hitting F10 and the

A TinyBoot TutorialTo enable the PIC18Flash board for serial loading of firmware, simply follow thesesteps:

1. Using the IC-Prog/MTSP programmer, upload Tinybld18F.hex to the PIC18Flashboard.

2. Connect a spare COM port to the PIC18Flash board using a DB9–DB9 cable (thisRS232 cable should not be crossed, i.e., pins 2 and 3 should be ‘straight

through’).3. Run TinybldWin.exe, select the COM port; select an application firmware hex file

(e.g., PIC18flash.hex); cycle the PIC18flash power supply and within 5 seconds of applying power, click Write Flash.

The Tinyboot bootloader (Figure 8) is configured to watch for hex data arriving onthe RS232 port for 5 seconds from power-up or reset, after which time the firmwareapplication code will be activated.

resultant HEX file uploaded to the

PIC18Flash system.

Using an RS232 bootloader

There are three ways to load firmware

into PIC18Flash:

1. MTSP using the parallel port;

2. ICD-2 using the RJ-11 port;

3. RS232 bootloader .

The MTSP method provides a low-cost

method of bootstrapping code into the

uC, whereas the ICD-2 approach

requires an expensive external debug-

ger, but — on the positive side —

enables firmware to be debugged in

real time within MPLAB.

An RS232 bootloader is a small ‘stub’

program that is initially flashed into

the microcontroller by a traditional pro-

grammer. At power-up it communi-

cates with a PC through the serial

interface in order to erase and program

the microcontroller’s flash memory. If

no PC client communication is

detected, the bootloader passes con-

trol to the main firmware application

on the uC.

The RS232 bootloader method requires

only a Windows COM port and

enables firmware upgrades to be easily

applied to products ‘in the field’. To

take advantage of this programming

method, the user must first use MTSP

or ICD-2 to initially flash the bootloader

code. Once the bootloader is in place,

you can use a PC bootloader client to

upload your PIC *.hex firmware.

There are many freeware bootloaders

available on the Internet, and we have

tested several suited to use with the

PIC18F, including the Tiny Bootloader

which is included in the support zip

file, and is described in the inset.

(040010-1)

Web LinksMicrochip: www.microchip.com

IC-Prog: www.ic-prog.comBasic18: www.midwest-software.com

Tiny Boot:www.ac.ugal.ro/staff/ckiku/software/

picbootloader.htm

Further reading

Goodbye ’16, Welcome PIC18F, ElektorElectronics October and November 2003.

l kt l t i 1/200540

Figure 7. IC-Prog uC Selection.

Figure 8. Tiny BootLoader in action.