Electronica PANDORA

7
Este com Si desea h Yp Si a e Docum pleta en as más in http:// htt odrás de Libros Manual Tutorial Cursos Program Música Película G algún Archiv ento Ha EBook nformac /www.en tp://ww escargar es les mas as Grupo E En vo Requiriera www.e a sido de s y Tut ción o lib nigmae ww.foro r muchas nigma E nigma Te a de Contras enigmaelect escargad toriales. bros, ent electro oenigma s aplicac lectrónic eam seña de acce ronica.tk o desde tonces i onica.t a.tk ciones út ca eso siempre la Web ngresa a tk tiles. será: más a:

Transcript of Electronica PANDORA

Page 1: Electronica PANDORA

Este

com

Si desea

h

Y p

Si a

e Docum

pleta en

as más in

http://

htt

odrás de

Libros

Manual

Tutorial

Cursos

Program

Música

Película

G

algún Archiv

ento Ha

E‐Book

nformac

/www.en

tp://ww

escargar

es

les

mas

as

Grupo E

En

vo Requiriera

www.e

a sido de

s y Tut

ción o lib

nigmae

ww.foro

r muchas

nigma E

nigma Te

a de Contras

enigmaelect

escargad

toriales.

bros, ent

electro

oenigma

s aplicac

lectrónic

eam

seña de acce

ronica.tk

o desde

tonces i

onica.t

a.tk

ciones út

ca

eso siempre

la Web

ngresa a

tk

tiles.

será:

más

a:

Page 2: Electronica PANDORA

This project was originally conceived for model making

applications as a cheap way to provide high quality audio

playback in response to a trigger signal (typically from a

pushbutton or PIR detector), but we’re pretty sure Elektor

readers can find many other uses.

elektor electronics - 4/200452

Ken Bromham

Pandora’sSound & Music BoxRecycle an old CD-ROM drive for (triggered) playback

Page 3: Electronica PANDORA

The standard low cost solution to creat-ing auto-playback sounds is to use arecord/playback chip (say, the ISD25XXseries) but these devices are limited toabout 3 kHz audio bandwidth, not tomention a lot of hiss and noise, so thesound quality is not the best unlessyou’re specifically after for voice mes-sages of the Stephen Hawking type.

The Elektor approachOver the past few years we havereceived many requests from readersasking for a circuit that would allowthem to use an old CD-ROM player forthe sole purpose of playing back musicCDs. In many cases, that is possible

just by connecting a power supply andheadphones to your drive, inserting aCD and pressing the Play button. Sim-ple as this may sound, there are pit-falls, particularly with later CD-ROMdrives that do not have a music play-back button. Also, we really could notstand the thought of being unable toselect and skip tracks, etc. In trueElektor fashion we wanted to be incontrol of things and make the old CD-ROM drive do something really useful.The alternative approach developed byKen Bromham and described in thisarticle makes use of a 40-pin PIC16F87X microcontroller which, helpedby a small number of external compo-nents, provides a versatile controller

module that will interface to any oldATAPI CD-ROM drive. Mind you,ATAPI is not a brand, but a connectiv-ity standard for 99% of all CD-ROMdrives in PCs for home and office use.Don’t worry about it, just start rum-maging around in the attic or cellar, diga CD drive out the IT skip at work, orcommandeer the oldest (usually read-only) CD drive from the kiddies’ PCleaving a note saying ‘drive removedfor scientific purposes’. Never tell themyou got the idea from Elektor, instead,tell them to keep using the CD/RWdrive which is much faster, better, etc.or better still buy them a mini MP3player and headphones.

4/2004 - elektor electronics 53

IC3

7805

C1

47u

C2

47u

100n

C3

100n

C4

IC1

7812

100n

C5

100n

C6R1

10

k

4MHz

X1

C7

22p

C8

22p

R2

10

k

R3

1k

R4

3k3

R5

6k8

R6

10k

R7

22k

R8

33k

R9

68k

R10

1k

R11

1k

TRIGGER

0V

K4

10

11 12

13 14

15 16

17 18

19 20

21 22

23 24

25 26

27 28

29 30

31 32

33 34

35 36

37 38

39 40

1 2

3 4

5 6

7 8

9

DD6

DD5

DD4

DD3

DD2

DD1

DD0

DD8

DD9

DD10

DD11

DD12

DD13

DD14

DD15

R12

1k

D1

100n

C9

100n

C10

IC4

7805

IC2

7812

100n

C11

100n

C12

100n

C13

100n

C14

0V

RC0/T1OSO/T1CKI

RA3/AN3/VREF+

RA2/AN2/VREF-

MCLR/VPP/THV

RE0/RD/AN5

RE1/WR/AN6

RE2/CS/AN7

PIC16F871

RA4/T0CKI

RC1/T1OSI

RC7/RX/DT

RC6/TX/CK

RC2/CCP1

RD0/PSP0

RD1/PSP1

RD2/PSP2

RD3/PSP3

RD7/PSP7

RD4/PSP4

RD5/PSP5

RD6/PSP6

RB0/INTRA0/AN0

RB7/PGD

RB6/PGC

RA5/AN4

RA1/AN1

RB3/PGM

IC5

OSC1 OSC2

RC3

RC4

RC5

RB1

RB4

RB5

RB2

11

15

40

39

38

37

35

36

34

33

3112

10

32

16

17

18

19

20

21

22

13 14

26

25

24

23

30

27

28

29

1

3

2

4

6

5

7

8

9

K3

1

K2

1

DD7

IDE-Interface

DD15

DD0

DD14

DD1

DD11

DD4

DD10

DD5

DD13

DD2

DD12

DD3

DD9

DD6

DD8

DD7

S9

CS0

DA2

DA0

DA1

INTRQ

DIOR

DIOW

CS1

CS1

DA2

DIOW

DIOR

INTRQ

DA1

DA0

CS0

+5V

S1

S2

S3

S4

S5

S6

S7

S8

+12V

K5

+5V

1

2

3

4

K1

030402 - 11

+12V

+5V

+5V

+12V

DELAY

IMMEDIATE

OUTPUT

OUTPUT

gelb

schwarz

schwarz

rot

Figure 1. The modern version of Pandora’s Box is a black one governing triggered response from an old CD-ROM drive playingback music or sound samples. You determine what ‘horrors’ (if any) lurk inside the box.

Page 4: Electronica PANDORA

What can it do?The controller module has two mainmodes of operation, single trigger useor multiple-trigger use, with furtheroptions selected by a 4-way DILswitch (psst… in fact both modes runsimultaneously). There are also twodigital switching outputs, assertedduring playback, to allow other fea-tures (for example, lights or a motor) tobe automatically switched on for theduration of the audio playback.

Single-trigger modeThe function here is very simple. Acti-vating the single trigger input willcause playback of one track from theCD. There are four options (selectedwith a DIL switch), as follows :

DIL switch # 1off = normally open contact for single

triggeron = normally closed contact for sin-

gle triggerDIL switch # 2off = no response to trigger until end

of trackon = respond anytimeDIL switch # 3off = random track selectionon = sequential track selectionDIL switch # 4off = keep disc continually spinning

(defeat drive’s inactivity timeout)on = allow the CD-ROM drive to

power down.

The latter options may require someelucidating. In the first case the play-back will always start almost immedi-ately as the disc is always spinning,but this may have some impact on thedrive MTBF value (mean time betweenfailure — you’ll find it hard if notimpossible to find data on this). In thesecond case, if the disc has stoppedspinning, there will be a short ‘spin up’delay before playback starts. No prob-lem for applications that are likely to

elektor electronics - 4/200454

(c) ELEKTOR

030402-1

C1

C2

C3C4

C5C6

C7

C8

C9 C10

C11C12

C13C14

D1

HO

EK

1

HOEK2

HO

EK

3

IC1

IC2

IC3

IC4

IC5

K1 K2

K3

K4

K5

R1

R2

R3

R4

R5

R6

R7

R8

R9

R10R11

R12

S9

X1

0V0V

+5V

+12V

S8

S7

S6

S5

S4

S3

S2

S1

TRIG

0V

IMM

DELAY0V +

030402-1

Resistors:R1,R2,R6= 10kΩR3,R10,R11,R12 = 1kΩR4 = 3kΩ3R5 = 6kΩ8R7 = 22kΩR8 = 33kΩR9 = 68kΩ

Capacitors:C1,C2 = 47µF 16V radial

COMPONENTS LIST

Figure 2. The printed circuit board is single-sided and contains seven wire links.

Figure 3. When in doubt about any constructional aspect, just use this photographfor guidance.

Page 5: Electronica PANDORA

spend a lot of time ‘doing nothing’.There may be up to 24 tracks on the CD(the PIC chip is storing the table of con-tents data in its limited RAM). The mul-tiple trigger inputs should be left open.

Multiple-trigger modeIn this mode you can have a maximumof eight separate triggers (for instance,push buttons). Pressing button 1 willalways play track 1, button 2 willalways play track 2, etc., up to andincluding track 8. It can be used withnormally-open contacts only. If, forexample, there are only three tracks onthe CD then pressing buttons 4 – 8 willhave no effect.

DIL switch 1 must be configured asnormally open and the single trig-ger input left open.

DIL switch 2 is not relevant.DIL switch 3 has the same function as

above.DIL switch 4 has the same function as

above.

Digital switching outputsPandora’s Sound & Music Box has twodigital outputs for control of externaldevices like sounders, lamps, ampli-fiers, signal routers, door locks, youname it, anything can be controlled aslong as it has a simple 0/5 V (TTL) dig-ital control input, or can be switched onand off with a few mA of drive current.The ‘Output Immediate’ output goeshigh immediately after triggering andremains high until end of playback.The other output called ‘Output Delay’goes high only after playback hasstarted (that is, after any spin-up delay)and remains high until end of playback.

Circuit and constructionThe circuit diagram shown in Figure 1has few surprises, basically showing amicrocontroller sitting between a

bunch of switches and some connec-tors. The heart of the circuit is a 40-pinPIC16F871 microcontroller which fortu-nately has enough input/output pins toconnect to all of the necessary ATAinterface lines with enough left over tohandle the trigger inputs, option selec-tions and the switching outputs. Ascan be seen from the schematic, only ahandful of extra components arerequired. Note that the single triggerinput RB0 (K3) and the option selectinputs RB1-RB4 (S9) make use of inter-nal, that is, invisible, pull-up resistors.All other port lines of the PIC16F871are connected to the drive’s IDE(ATAPI) interface via connector K4.Together with R2, resistors R3–R9 pro-vide a simple potential divider networkconnected to input A0 on the PIC. Theupshot is that a different voltage isapplied to A0 depending on which but-ton is pressed (multiple-trigger mode).This voltage is read by an internal A/Dconverter. It is assumed here that it isnot necessary to distinguish multiplesimultaneous button presses. If multi-ple trigger mode is not required thenresistors R3–R9 and switches S2-S8can be omitted, but R2 must beretained to keep input A0 pulled high.The PIC ticks at 4 MHz as determinedby quartz crystal X1 and its usual pairof small satellite capacitors, here iden-tified as C7 and C8. The user-definedsettings are read from DIL switch S9.One LED, D1, has been included toacts as a ‘PIC awake’ indicator (veryuseful!). Capacitors C5 and C6, finally,ensure the 5-V supply voltage to thePIC remains as clean as possible.The circuit has been designed to oper-ate from a single 15-18V DC supply,which should be ‘heavy’ enough to alsosupply the drive’s 12-V line. Two paral-leled 7805 fixed voltage regulators, IC3and IC4, provide +5 V for the PIC andthe CD-ROM drive’s 5 V line. The 12-volt supply is realised in a similar wayby two 7812s in parallel. Alternatively,

an old PC power supply can be used topower the CD-ROM drive directly. Inthis case it is recommended to retainthe 7805s and use 12 V from the pcpower supply for the controller board.A heatsink will still be necessary.Resistors R10 and R11 provide currentlimiting for the digital outputs andhave been given the nominal value of1 kΩ. The PIC chip can source/sink anabsolute maximum of 25 mA for eachpin, so the value of these resistors canbe changed so long as this maximumis not exceeded. In any case, it is suf-ficient to drive a transistor/relay com-bination for example.The PCB shown in Figure 2 wasdesigned for ease of use by you, theconstructor. It is available ready-made through our Readers Servicesunder number 030402-1. Alterna-tively, you may decide to make yourown board using the artwork file thatcan be downloaded free of chargefrom our website.As there are only regular componentsto fit on the board we doubt the con-struction will present any problems.The simplest and cheapest componenton the board, however, is often the onethat’s forgotten, causing majorheadaches and dozens of unnecessaryemails of the ‘Help it don’t work’ type!We’re talking about the infamous wirelink. There are seven of them on theboard and they are best fitted beforeany other component so they’re notforgotten. Bolt the voltage regulatorsonto a common heatsink (see Figure 3and the parts list), insulating washersare not required as all metal tabs areconnected to ground. The PIC beingthe most expensive part, it deserves tobe fitted into a 40-way DIL socket withgood quality contacts.Although the circuit diagram suggeststhat there are rather a lot of wires andother things to connect to the board, inreality the situation is not that bad asyou can see from Figure 4. The cables

4/2004 - elektor electronics 55

FreeDownloadsPIC source and hex code files.File number: 030402-11.zip

PCB layout in PDF format. Filenumber: 030402-1.zip

www.elektor-electronics.co.uk/dl/dl.htm,select month of publication.

C3..C6,C9-C14 = 100nFC7,C8 = 22pF

Semiconductors:D1=LED, red, low currentIC1,IC2 = 7812IC3,IC4 = 7805IC5 = PIC16F871/P, programmed, order

code 030402-41 (see ReadersServices page)

Miscellaneous:S1-S8 = pushbutton, 1 make contact

S9 = 4-way DIP switchX1 = 4.000MHz quartz crystalK1,K2,K3 = 2-way PCB terminal block,

lead pitch 5mmK4 = 40-way boxheaderK5 = power supply plug for CD-ROM

drivePCB, order code 030402-1 (see Readers

Services page)Heatsink, e.g., Fisher SK59 (6 K/W)Disk, PIC source and hex code files, order

code 030402-11 or Free DownloadCD-ROM drive

Page 6: Electronica PANDORA

between the board and the CD-ROMdrive, for example, are ready-madeones pulled from the junkbox or an oldcomputer.

ProgramThe program that runs inside the PICmicro has been written in assemblylanguage. The source code and hex fileare available on floppy disk (anyoneout there still using these?) or as freedownloads from the Publishers’ web-site. If you wish to program your ownPIC, please feel free to do so using thefiles supplied. Alternatively a pre-pro-grammed PIC is available from Read-ers Services, the order code being030402-41.The source code supplied by KenBromham is well worth studying, evenif you do not build the project. Ken suc-ceeded in including plenty of com-ments so if you are familiar with thisassembly language it should be possi-ble to follow the program, despitesome classic spaghetti code. If not, youmay still want to grasp the ‘broaderlines’ offered by the flowchart of themain program shown in Figure 5.The actual ATAPI commands used bythe PIC firmware are:

PLAY AUDIO MSF (play from specifiedstart to end location. MSF = Min-utes, Seconds, Frames, 75 Frames= 1 Second).

READ TOC (get the table of contents).READ SUBCHANNEL (used to get the

current audio status).SEEK (position the head at start of

track 1, but will also cause the discto spin up, so used to defeat the

CD-ROM drive inactivity timeout).The READ SUBCHANNEL command isused at various points in the abovesequence, whenever the programneeds to know if playback is currentlyin progress or if playback has finished.

TestingAs usual, check for the presence of 5-Vbefore inserting the PIC chip. The mod-ule can then be tested without con-necting to a CD-ROM drive. Simplypower up and check that the LED onpin A4 flashes a few times. Nothingelse will happen, but this confirms thatthe PIC is up and running. Switch off,connect to CD-ROM drive, power up.The LED should flash a few times andthen continue to flash until a disc isinserted, the tray is closed and the TOC(table of contents) successfully read.When the LED stops flashing, the mod-ule is ready to respond to a trigger andthe different options can be experi-mented with.Note that the CD-ROM drive must beconfigured as a MASTER device, andpin 1 on the PCB socket (K4) must goto pin 1 on the CD-ROM ATA interfacesocket (usually indicated by a red wirein the ribbon cable). When used with asingle 12-V DC supply make sure thissupply can provide a minimum ofabout 1.2 A. The audio output can betaken from the analogue out on theback of the CD-ROM drive or from theheadphone jack a the front. To continuethe low-cost theme, we recommend acheap pair of active ‘multimedia’speakers (whatever that means),unless, of course, you really want tobuild your own amplifier!

elektor electronics - 4/200456

C1

C2

C3

C4

C5

C6

C7

C8

C9

C10 C

11C

12

C13

C14

D1

IC1

IC2

IC3

IC4

IC5

K1

K2

K3

K4

K5

R1

R2

R3

R4

R5

R6

R7

R8

R9 R10

R11

R12

S9

X1

0V 0V+5V

+12V

S8

S7

S6

S5

S4

S3

S2

S1

TR

IG

0V IMM

DELAY

0V+

030402-1

S8 S1030402 - 12

8 x S

0

Figure 4. How to connect it all up.

initialisation

wait afew seconds

store TOC inRAM

READ TOCerror

?

select track basedon

mode and options

get track startand end point

from stored TOC

sendPLAY AUDIO MSF

command

triggerdetected

?

playback starts

030402- 13

check DIL switch#4

send SEEKcommand

if appropriate

wait for playbackto finish

error?

Figure 5. Use this flowchart of themain program if you don’t fancyreading assembly code but still want tounderstand how the software works.

Page 7: Electronica PANDORA

(030402-1)

There’s only one limit to the applications of Pandora’s Sound &Music Box: your imagination. Just couple the two notions ‘somekind of trigger’ to ‘an audible, pre-recorded response’ and awayyou go. Here are some possible applications to get you going, infairly random order:

– a voice message system employing the public address soundequipment in a large building. Very useful for guiding the pub-lic to fire exits in case of an emergency, when written noticesare hardly ever seen, let alone read.

– an electronic dog barking in response to your doorbell; a trackwith More & Fiercer Dogs for really persistent callers thatpush the bell a second time (Pandora must have heard ofCerberus), gunfire for a third time, then police sirens, and soon.

– a door- or doormat-triggered muzak or ‘welcome’ generator.

– a voice guide in museums, triggered by visitors approaching anexhibit.

– a low-cost jingle-and-tune box for quizmasters and deejays.

– a language training aid.

– a spoken Callsign / ‘CQ Contest’ generator for radio ama-teurs.

For all of the above applications, you will need to burn your ownmusic CD. Programs to compile music or sound samples ontoyour own CDs abound in PC land, CoolEdit being one of the bestknown. Note however that you can’t use MP3 files just like that— a suitable decoder will have to be added.

4/2004 - elektor electronics 57

ATAPI (AT Attachment Packet Interface) devices use the samephysical interface as ATA (AT Attachment) devices such as a harddisk drive, so it is necessary to understand how this works first. Insummary, the ATA device has a limited number of 8-bit registers(for example,. COMMAND, STATUS) and a single 16 bit DATAregister. The interface is of the parallel type with 16 bi-directionaldata lines, where only the lower 8 data lines are used for read-ing/writing the 8 bit registers. ATAPI devices use the same regis-ter set, although some registers have been renamed and serve adifferent function. Unfortunately this does not provide enoughflexibility for the increased range of commands required, so theconcept of a command packet was introduced along with a newATA command, the ‘ATAPI packet command’. To send a com-mand to an ATAPI device the general procedure is to first writethe (generic) ATAPI packet command to the device’s COMMANDregister, and then send the command packet by writing multipletimes to the device’s DATA register. For CD-ROM drives the com-mand packet is 12 bytes in length and so 6 consecutive writes tothe DATA register are required, sending 2 bytes each time. Thecommand packet contains an opcode for the specific ATAPI com-mand along with any additional parameters that are required.

Here is an example of the packet for the PLAY AUDIO MSF com-mand:

Byte 0: Operation Code (0x47)Byte 1: ReservedByte 2: ReservedByte 3: Start Location MinutesByte 4: Start Location SecondsByte 5: Start Location FramesByte 6: End Location MinutesByte 7: End Location SecondsByte 8: End Location FramesByte 9: ReservedByte 10: ReservedByte 11: Reserved

You can see that the command packet is padded with spare(reserved) bytes if necessary to give the 12-byte length.

Detailed documentation can be found on the web,www.t13.org is a good place to start looking, just be preparedfor some serious bed-time reading.

ATA Interface pinningPin no. Label Description1 HRESET Reset2 GND Ground3 HD7 Data bus bit 74 HD8 Data bus bit 85 HD6 Data bus bit 66 HD9 Data bus bit 97 HD5 Data bus bit 58 HD10 Data bus bit 109 HD4 Data bus bit 410 HD11 Data bus bit 1111 HD3 Data bus bit 312 HD12 Data bus bit 1213 HD2 Data bus bit 214 HD13 Data bus bit 1315 HD1 Data bus bit 116 HD14 Data bus bit 1417 HD0 Data bus bit 018 HD15 Data bus bit 1519 GND GND20 N/C Key pin21 DMARQ DMA request22 GND Ground23 HWR I/O write24 GND GND25 HRD I/O read26 GND Ground27 IORDY I/O channel ready28 SPSYNC:CSEL Spindle sync or cable select29 DMACK DMA acknowledge30 GND Ground31 INTRQ Interrupt request32 IOCS16 16 BIT I/O33 HA1 Address bus bit 134 PDIAG Passed diagnostics35 HA0 Address bus bit 036 HA2 Address bus bit 237 CS1FX Chip select 038 CS3FX Chip select 139 DASP Drive active/drive 1 present40 GND Ground

ATAPI protocol in brief

With compliments, Pandora