pcb drilling machine 2

Upload: ana-maria-c

Post on 14-Oct-2015

31 views

Category:

Documents


0 download

DESCRIPTION

An interesting article!

TRANSCRIPT

  • 5/24/2018 PCB Drilling Machine 2

    1/7

    GENERALINTEREST

    60 Elektor Electronics 4/2001

    Part 2: T he controller

    Design by T. Mller (Radix GmbH) www.radixgmbh.de

    Our PCB drilling machine provides a link between a Windows PC and themotors and solenoids of the machine itself: a microcontroller integrated

    with a high current drive circuit.

    PCB

    Drilling Machine (2)

  • 5/24/2018 PCB Drilling Machine 2

    2/7

    operating system, has other things to do

    w hile generating our output w aveform.

    Updat ing the mouse position, checking for

    incoming e-mail, reading audio data from a

    CD, communicat ing w ith peripherals : a l l

    these ta ke processor time.Window s is event-driven, w hich means

    that the various parts of the machine can

    caus e the operat ing syst em to carry out oper-

    at ions. This can b e seen w hen printing, for

    example: Window s launches a process t o

    communicate w ith the printer, and s upplies

    i t w i th new da ta as and w hen it i s ready to

    accept it. When that ha ppens and how much

    dat a is transferred at a t ime is tota lly unde-

    fined, but nevertheless consumes processor

    time. This ca n interfere w ith the timing of our

    sq uare wa ve and ca use var ia t ions in i ts

    period.There are tw o w ay s to overcome this prob-

    lem. We could shut d ow n all other process es

    and disable multitasking w hile w e generate

    our sq uare w ave. Then w e might as w ell use

    DOS, w hich is w hat most manufacturers of

    this type of control softw are for small

    ma chines do. Under DOS, an app lica tion pro-

    gram can use the full pow er of the processor

    for itself. Of course, w e sa crifice the ea se of

    use of Window s, a nd, in spite of i ts pow er,

    the computer cannot be used for anything

    else.

    There a re various operating s ystem ad d-ons a vailable for Window s w hich ameliorate

    this situation and provide quasi-real-time

    fac ilities . Thes e a re most ly VXD or TSR pro-

    In the previous instalment (March

    2001) w e des cribed in det ail the

    ba sic principles of t he CNC d rilling

    machine. The controller is just as

    unconventional: the machine is not

    driven directly from a PC, but indi-

    rectly via a specia l controller circuit.For trouble-free communication

    betw een the Window s PC a nd the

    controller over the Centronics inter-

    face w e need to make use of several

    tr icks tha t ta ke us beyond the s tan-

    dard Centronics protocol.

    Lets start b y ta king a look at t he

    rather straightforw ard hardw are of

    the controller boa rd. The b as ic circuit

    consists on one side of a microcon-

    troller w ith a PC interface and on the

    other the output d rive circuits, con-

    nect ed to I/O-port pins. Of coursethere is rather more to the design

    than tha t .

    Real-time with Windows?

    How ca n w e control a st epper motor

    from a PC? I t goes w ithout sa ying

    tha t w e need an output d rive circuit

    capable of supplying the current

    required by the motor, since none of

    the PCs interfaces ca n drive a motor

    directly. And then, in order to make

    the motor step smoothly, w e needvery accurate timing.

    At first blush it w ould be ideal if

    w e could somehow c onnect the out-

    put s tages d irect ly to the PC and

    han dle practica lly a ll the control sig-

    nals d irectly a s b its from the PC. The

    circuit w ould t hen be very simple,

    consist ing of just a couple of latch es

    and an address decoder.

    Unfortunately, Window s ha s a

    rather unpleasa nt cha racteristic: its

    operations a re tot ally as ynchronous.

    I t is impossible to say at exactlyw hat t ime an event w ill occur.

    Approximate timing is possible, but

    as t he specified time betw een

    events g ets s maller and more pre-

    cise, something eventually w ill go

    w rong. Windows on its ow n w as not

    designed for control applications,

    and indeed is not suitable for them.

    I t may b e easy to use, but from the

    hardw are point of view it is no more

    suitable than older operating sys-

    tems such a s DOS.

    First of all, modern programminglanguages offer hardly any com-

    ma nds for acc ess t o the I/O-ports ;

    and second, multita sking prevents

    direct hardw are access by programs

    that a ttempt to bypass t he operating

    sys tem. Special drivers a re req uired,

    such as por t . dl l found in the Elek-

    t or Elect ronicsbook PC Ports under

    Window s (to be published soon).Let us suppose that you have

    ava i lab le a programming language

    that lets you control the port signa ls

    at w ill . We w ish to generate a con-

    tinuous sq uare w ave on one of the

    da ta pins of the Centronics port at a

    given freq uency. In softw are this is a

    trivial matter: w e simply need to tog -

    gle the bit in question regularly. In

    order to obtain the desired fre-

    quency, the appropriate delay must

    be used. I f the delay is reasona bly

    large, say 0.5 s, w e obtain a perfectoutput s ignal w ith a freq uency of

    1 Hz.

    If, how ever, w e reduce the delay

    to sa y 0.5 ms and hence raise the fre-

    quency to 1 kHz, we hi t a problem.

    The right freq uency app ears a t the

    output, but only w hen averaged over

    a long period. The individua l pulse

    lengths are a little longer or shorter

    in a random pattern, and some are

    very different from the specified

    period. Why is this?

    Of course, mod ern processors a refast enough to toggle a bit 2,000

    times per second . No, the reason is

    tha t Window s, as a multi tas king

    GENERALIN TEREST

    614/2001 Elektor Electronics

    A un iver sal con t r o l l e r boar d

    The contro ller board, w ith its pow er output stages and integrated microcontroller, has

    been designed not just for use with the PCB drilling machine, but also with enough flexibil-

    ity to be used for many other purposes. The driver stages make it a very handy controller

    board for other equipment or machines that employ stepper motors and other high cur-rent devices. For this reason there are a few places in the layout w here we have made

    additions that are not strictly necessary for the drilling machine application.

    To t ake one example, the output stages are controlled by a GAL. The GAL is simply pro-

    grammed to combine the PWM signal w ith a tw o-bit address to activate the solenoid drive,

    and (with an enable input) the drill motors. This function could easily have been carried out

    using a simple address decoder such as a 74138. However, by using a GAL we can com-

    pletely reconfigure the eight output stages. To this end, you will see that we have routed

    extra signals from the microcontroller to the GAL, in particular signals that can be assigned

    special functions in the microcontroller.

    Series resistors and capacitors can be fit ted a t t he inputs to the driver stages. The pow er

    MOSFETs used in the drilling machine contro ller do not require these; but if you w ish to

    use bipolar transistors in the drive stages, the spaces we have left on the board will come in

    handy.

  • 5/24/2018 PCB Drilling Machine 2

    3/7

    grams that are loaded w hen Window s sta rts

    up and then run in the b ackground. These

    programs run briefly, but at an exact moment

    in time; and they run at the highest priority

    to guarant ee having the necessary processor

    pow er ava ilab le to them.

    These progra ms a re rat her critica l and con-siderably increase the cha nces of Window s

    crashing. They a lso permanently consume

    memory and processor time, because t hey are

    alw ays present and must alw ays be ready to

    spring into a ction w hen req uired.

    These programs a re also often w ritten

    using undocument ed features or ba ck doors

    in the operat ing syst em, and so a re usually

    only fully compa tible w ith one part icular ver-

    sion of the sys tem.

    Offloading the synchronisation

    problemWe have therefore chosen an alternative

    approach to d riving a s tepper motor under

    Window s. Synchronisat ion is not left up to

    Window s softw are, but rather trans ferred to

    a microcont roller. The microcont roller receives

    a control command (for example for a mot or

    pulse), a nd rat her than executing it immedi-

    at ely, w aits for further timing information to

    indicate w hen the data are to be processed.

    In this w ay, as long a s the overall system is

    fast enough, w e can obta in perfectly syn-

    chronised results using Window s.The information pa sse d to t he microcon-

    troller to generat e a sq uare w ave runs as fol-

    low s: bit high in 500 s, bit low in 500 s,

    Repeat. This information is sufficient for the

    microcontroller to produce the signal inde-

    pendent ly, requiring no further intervention

    from the PC . The PC mus t deliver the da ta

    fast enough, each command arriving w ithin

    500 s. This s hould not present an y d ifficulty

    for a reasona bly fas t PC.

    To prevent the PC ha ving to w ait until the

    microcontroller is ready for a new comma nd,

    the controller is eq uipped w ith a small FIFOmemory w ith spa ce for 40 entries. This a llow s

    the cont roller to be w ell decoupled from the

    PC. The PC can send off 40 precalculated

    commands for sw itching the va rious output

    signals to the controller and then has

    40500 s to prepare new da ta or carry out

    other tasks.

    Shortly before the FIFO empties, this s ta te

    is flag ged t o the PC, w hich can then refill the

    FIFO w ith new da ta . This does not affect the

    controller, w hich continues executing com -

    mands one after another w ith perfect timing.

    Using the Centronics interface

    Communication w ith the controller could b e

    carried out over any PC interface.

    The Centronics and V24 (serial)

    interfaces a re alw ay s ava ilab le, and

    are particularly suita ble candidat es.

    There are certa in problems a ss o-

    ciated w ith the V24 interface: get-

    ting the w iring right and a rrang inghand sha king can be full of pitfa l ls .

    Matters a re also more complicat ed

    for the microcontroller, w hich must

    first convert the serial bit stream into

    parallel bytes. And, if the microcon-

    troller does not cont a in a UART, th e

    controller must detect and interpret

    the st art bits its elf. This consumes

    processor time in the controller and

    ultimately creates difficulties in

    ensuring timely execution of com-

    mands .

    For these reas ons, w e have cho-sen the Centronics interface. This

    interface is also superior from the

    point of view of speed, because

    eight bits a re transferred at a t ime:

    this a lso makes the da ta easy to

    process. The da ta are simply w ritten

    to a specific I/O add ress a nd t he job

    is done. It is also convenient for the

    microcontroller to receive t he da ta in

    a simple 8-bit format .

    Eight bits may be a convenient

    number, but it is too few to specify a

    command w ith timing informat ion.Multiple bytes must be a ssembled

    together to c onstruct a useful com-

    mand so that the controller can

    know w hat to do w i th the da ta . For

    our application, tw o bytes a re

    enough for each command, but that

    is too much to t ransfer in one g o over

    the Centronics interface. But w hen

    the 16 bits a re divided into tw o inde-

    pendent bytes , a synchronisation

    problem can arise.

    The strobe-edge trickHow can t he controller know w hich

    of the byt es is the firs t a nd w hich

    the second? Counting is one option,

    but not a very reliable one: a sing le

    transmission error and all successive

    commands w ill be w rongly inter-

    preted. The error must be d etect ed

    and the controller reset. Alterna-

    tively, the dat a bytes could include

    further information to allow the con-

    troller to identify w hich is w hich.

    However, this also has i ts disad -vant ag es. The ma rker bits na turally

    reduce the amount of real informa-

    tion trans ferred, and so w e have

    few er bits a vailable for commands .

    For this reason w e distinguish the

    bytes externally using a means

    already provided w ithin the Cen-

    tronics interface. Take a look at the

    protocol as show n in Figure1. First

    consider normal operation,described at the top of the f igure.

    The interfac e, how ever, w ill let us

    transfer two by tes at a t ime w ithout

    modifica tion. How t hat is achieved is

    described at t he bottom of the fig ure.

    The hand sha king process is

    unchanged : w e have s imply

    chang ed the meaning of the signals.

    Tw o bytes a re coalesced into a s in-

    gle packet, w here the falling edg e of

    the STROBE signal marks the first

    byte, and the ris ing edge, the sec-

    ond.If a n error occurs w hen the first

    byte is a lready in the process of

    being sent , STROBE w ill event ua lly

    rise, if only because of the pull-up

    resistor fi tted to the cont roller board.

    The trans fer is then terminat ed, an d

    the pa ir of bytes remains t ogether.

    Synchronisat ion problems a re there-

    fore impossible, even though the

    contents of the tw o bytes w ill be in

    error. I f on the other hand w e ha d

    simply counted b ytes , then all sub-

    seq uent bytes w ould be interpretedw rongly, as t hey w ould a ll be inter-

    chang ed. I f w e w ere to continue in

    this ma nner, the cont roller w ould

    ceas e operating correctly hence the

    syst em w ould ha ve to be re-ini-

    tialised.

    At st art-up the control softw are

    sends a RESET command, w hich

    causes the controller to clear its

    FIFOs a nd b ring to a halt a l l move-

    ments in progress in the sys tem.

    Controller functionsWe have now described the ma in

    functions of the controller: a ccepting

    the 16-bit w ide instructions, st oring

    them in the FIFO, and synchronously

    executing t he commands stored in

    the FIFO. Of course, the calculation

    of trajectories is not ha ndled by the

    microcontroller, since it is not

    designed for trigonometric calcula-

    tions and w ould be too slow. It

    w ould a lso imply programming the

    dyna mic characteristics of the sys-tem once a nd for all into the micro-

    controller.

    Instead, t he movements a re pre-

    GENERALINTEREST

    62 Elektor Electronics 4/2001

  • 5/24/2018 PCB Drilling Machine 2

    4/7

    processed in the PC and then sent to

    the cont roller in th e form of primitive

    instructions such as motor 1 one st ep

    count erclockw ise. All movements are

    defined in the P C in this w ay. I t is

    possible to compute the step infor-

    mat ion for any d esired motion andthen send it to the controller : and

    thus the microcontroller never needs

    to be reprogrammed.

    Data format

    Now tha t w e have expla ined how

    the command da ta are calculated in

    the PC a nd tran sferred over the Cen-

    tronics interface t o be s ynchronously

    processed by the controller, w e can

    ta ke a look at to the internal s truc-

    ture of the command da ta .The tw o bytes are concat enated

    to form a w ord. This w ord contains a

    da ta va lue, or operand, a long w ith

    an a ddress w hich determines how

    the operand is interpreted: in other

    w ords, the particular command to be

    executed. The number of address

    and data bit is variable, the number

    of data bits shrinking as more

    address bits are required. A com-

    mand w ith a short ad dress field can

    contain a longer operand , and vice

    versa. This kind of addressingscheme can be processed using a

    seq uence of branches, decoding the

    command using the divide and con-

    q uer principle.

    This w orks a s follow s: the first

    address bit determines w hether w e

    are dealing w ith one particular type

    of command (w hen the b it is a 1) or

    not (w hen it is 0). In the second

    case w e sti ll do not know w hat type

    of command w e are processing, so

    w e examine the second bit. If this is

    a 1 , then w e have decoded a sec-ond class of command s, w hile if it is

    0, w e proceed to examine t he third

    bit, and so on. Of course, as w e con-

    tinue to examine bits is this w ay,

    there remains less a nd less spa ce for

    the operand data .

    The advanta ge is tha t w e only

    need one address bit for the f irst

    command t ype, and so w e have a full

    15 bits available for the operand

    data . For commands w hose address

    field is, say, three bits long w e have

    13 bits a vailable. Note tha t a three-bit address field allow s a t most eight

    different commands to be separately

    decoded.

    GENERALIN TEREST

    634/2001 Elektor Electronics

    1

    1

    2

    2

    3

    3

    4

    4 5

    5

    6

    6 7 8

    010024 - 2 - 12

    DATA

    STROBE

    BUSY

    1. Quiescent condition:

    STROBE from PC to microcontroller is high. BUSY from microcontroller to PC is low.

    2. The PC wishes to transfer data as usual, and puts the data byte on the eight data lines.

    3. The PC takes STROBE low. The connected microcontroller (or peripheral device) sees

    the low state and knows that the data are ready to be read.

    4. The microcontroller takes the data byte and sets BUSY high in acknowledgement.

    5. The PC takes the STROBE signal high again.

    6. When the microcontroller has processed the byte, it indicates this state by taking the

    BUSY signal low. This completes the transfer of a byte. The system is ready to transfer

    another byte, the control signals (BUSY and STROBE) being once more in their original

    states.

    1. Quiescent condition:

    STROBE from PC to microcontroller is high. BUSY from microontroller to PC is low.

    2. The PC wishes to transfer data using the special mode, and puts the data byte on the

    eight data lines.

    3. The PC takes STROBE low. The microcontroller sees the low state and knows that thedata are ready to be read.

    4. The microcontroller now takes the data byte and sets BUSY high in acknowledgement.

    5. The microcontroller processes the byte immediately and leaves the BUSY signal high.

    6. The PC observes that the BUSY signal is high and therefore that the first byte has been

    accepted. It then puts the second byte on the data lines.

    7. The PC indicates that the second byte is present by taking STROBE high again. This

    causes the microcontroller to accept this byte also.

    8. When the microcontroller has finished its processing, it sets BUSY low again.

    Figure 1. T he original Centronicsprotocol (above) and asmodified for the drilling machine(below).

  • 5/24/2018 PCB Drilling Machine 2

    5/7

    GENERALINTEREST

    64 Elektor Electronics 4/2001

    PIC16C64

    OSC2

    IC13

    OSC1

    MCLR

    RB0

    RB1

    RB2

    RB3

    RB4

    RB5

    RB6

    RB7

    RE0

    RE1

    RE2

    RD0

    RD1

    RD2

    RD3

    RD4

    RD5

    RD6

    RD7

    RA0

    RA1

    RA2

    RA3

    RA4

    RA5

    RC0

    RC1

    RC2

    RC3

    RC4

    RC5

    RC6

    RC7

    13 14

    33

    11

    12 31

    32

    34

    35

    36

    37

    38

    39

    40 10

    19

    20

    21

    22

    27

    28

    29

    30

    15

    16

    17

    18

    23

    24

    25

    26

    1

    8

    9

    2

    34

    5

    6

    7

    X1

    16MHz

    C63

    15p

    C64

    15p

    +5V

    R41

    10k C60

    100n

    +5V

    JP1

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    K21

    R23

    1k

    C39

    820p

    R24

    1

    !

    1W

    C40

    820p

    R25

    56k

    K15

    +5V +30V

    C38

    100n

    C41

    100n

    R26

    1k

    C43

    820p

    R27

    1

    !

    1W

    C44

    820p

    R28

    56k

    K16

    +5V +30V

    C42

    100n

    C45

    100n

    R17

    1k

    C31

    820p

    R18

    1

    !

    1W

    C32

    820p

    R19

    56k

    K13

    +5V +30V

    C30

    100n

    C33

    100n

    R20

    1k

    C35

    820p

    R21

    1

    !

    1W

    C36

    820p

    R22

    56k

    K14

    +5V +30V

    C34

    100n

    C37

    100n

    SEL

    R11

    1k

    C23

    820p

    R12

    1

    !

    1W

    C24

    820p

    R13

    56k

    K11

    +5V +30V

    C22

    100n

    C25

    100n

    R14

    1k

    C27

    820p

    R15

    1

    !

    1W

    C28

    820p

    R16

    56k

    K12

    +5V +30V

    C26

    100n

    C29

    100n

    R35

    1k

    C55

    820p

    R36

    1

    !

    1W

    C56

    820p

    R37

    56k

    K19

    +5V +30V

    C54

    100n

    C66

    100n

    R38

    1k

    C58

    820p

    R39

    1

    !

    1W

    C59

    820p

    R40

    56k

    K20

    +5V +30V

    C57

    100n

    C67

    100n

    R29

    1k

    C47

    820p

    R30

    1

    !

    1W

    C48

    820p

    R31

    56k

    K17

    +5V +30V

    C46

    100n

    C49

    100n

    R32

    1k

    C51

    820p

    R33

    1

    !

    1W

    C52

    820p

    R34

    56k

    K18

    +5V +30V

    C50

    100n

    C53

    100n

    SEL STEPA1

    PBL3717A

    PHASEIC7

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC8

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC5

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC6

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC3

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC4

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC11

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC12

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC9

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    PBL3717A

    PHASEIC10

    RSNS

    IN0

    V+A

    CIN

    IN1

    REF V+B

    16

    11

    12

    14

    13 10

    PT

    OB OA

    15

    9

    6

    4 5

    87

    3

    2

    1

    D7

    D5

    D3

    D1

    D0

    D2

    D4

    D6

    STROBED0

    D1

    D2

    D3

    D4

    D5

    D6

    D7

    R44

    10k

    +5V

    ERROR

    PE

    SELECT

    STEPA2

    STEPB2STEPA3

    STEPB3

    STEPA5

    PL

    SELECT

    PE

    IC2

    16V8

    GAL

    19

    20

    10

    I0

    I1

    I2

    I3

    I4

    I5

    I6

    I7

    I8

    F7

    11I9

    12F0

    13F1

    14F2

    15F3

    16F4

    17F5

    18F6

    1

    2

    3

    6

    7

    8

    4

    5

    9

    +5V

    D5

    C15

    220n

    C14

    100n

    +15V

    T5

    R7

    100!

    K7

    D1

    C7

    220n

    C6

    100n

    +15V

    T4

    R3

    100!

    K3

    D6

    C17

    220n

    C16

    100n

    +15V

    T6

    R8

    100!

    K8

    D2

    C9

    220n

    C8

    100n

    +15V

    T3

    R4

    100!

    K4

    D7

    C19

    220n

    C18

    100n

    +30V

    T7

    R9

    100!

    K9

    D3

    C11

    220n

    C10

    100n

    +30V

    T2

    R5

    100!

    K5

    D8

    C21

    220n

    C20

    100n

    +30V

    T8

    R10

    100!

    K10

    D4

    C13

    220n

    C12

    100n

    +30V

    T1

    R6

    100!

    K6

    ADR1

    DRILL

    ADR0

    PWM

    SPARE1

    SPARE0

    R1

    10k

    R2

    10k

    R43

    10k

    R42

    1k

    BU4B U1 B U2 B U3

    +5V

    STEPB5

    CLK

    STEPB4

    STEPA4

    STEPB1

    STEPA1

    SEL

    SPARE0

    SPARE1

    PWM

    ADR0

    ADR1

    DRILL

    STROBE

    ERROR

    SOUT

    8x 47k1

    2 3 4 5 6 7 8 9

    R48

    +5V

    BO1

    BO2

    BO3

    BO4

    BO5

    R47

    560!

    T11 T10 T9

    R46

    560! R45

    560!

    +5V

    R49

    1k

    D12

    PL

    K1

    K2

    C3

    3300 50V

    C4

    3300 50V

    C5

    3300 50V

    2A T

    F2

    2A T

    F1

    C1

    100n

    C2

    100n

    7805

    IC1

    B1

    B2

    +30V

    +5V

    +15V

    SOUT

    PL

    CLKC1[LOAD]

    74HC165

    IC14

    SRG8

    C2/

    10

    11

    12

    13

    14

    "1

    2D

    1D

    1D

    1D

    15

    7

    9

    3

    4

    56

    2

    1

    C65

    100n

    IC14

    16

    8

    +5V

    C62

    100n

    C61

    100n

    SPARE

    SEL

    SEL

    SEL SEL

    SEL

    SEL

    SEL

    SELSTEPB1

    STEPA2

    STEPB2

    STEPA3

    STEPB3

    STEPA4

    STEPB4

    STEPA5

    STEPB5

    DRILL4

    DRILL3

    DRILL2

    DRILL1

    COIL4

    COIL3

    COIL2

    COIL1010024 - 2 - 11

    COIL1/DRILL1

    COIL2/DRILL2

    COIL3/DRILL3

    COIL4/DRILL4

    TARGETADR0 ADR1

    0

    1

    0

    1

    0

    0

    1

    1

    D1 ... D8 = 1N4001

    T1 ... T8 = BUZ11

    GBU6B

    GBU6B

    Figure 2. T he drilling machine controller board: lotsof brawn, and a little bit of brains!

    The variable-length address field also

    allow s a higher priority to be as signed to

    more common or more urgent comma nds. For

    a ra rely used command , or one that initiates

    a lengthy act ion, we ca n a l low the address

    decoding t o ta ke a little longer.

    The command s w hich are most commonlyused, and w hich sent to the controller at the

    fas tes t ra te , a re w i thout doubt the s t epper

    motor commands; they also require a long

    operand , w hich is provided by t he highest

    priority comma nd format . The format of the

    commands for sending st epping pulses to the

    motors is s et out in Table1.The second comma nd cla ss is the d rilling

    command . Three address b its ca n be used for

    this command w ithout ca using any d ifficulty

    because its execution time is much

    longer than the motor step com-

    mands, and because i t requires a

    shorter operand . The mea ning of the

    va rious bits in the d rilling comma nd

    is set out in Table2.

    These tw o comman ds s uffice forbasic operation of the PCB drilling

    machine. In fact there is a range of

    other commands w hich are less rel-

    evant t o our discussion and w hich

    are not d escribed here.

    Brawn and brains

    At fi rst glance t he circuit diagram in

    Figure 2may look like an impene-

    trab ly complex piece of electronics,

    but on closer inspection w e see that

    the b rains of the circuit are a ctua lly

    very s imple. The intelligence is con-

    cent rated in a ty pe PIC16C64 micro-

    cont roller from Microchip, clocked a t

    20 MHz. This microcontroller boa ststhe ma gnificent tota l of 33 individu-

    a lly a dd ressa ble I/O-ports , but only

    2 K of EPROM progra m memory an d

    128 bytes of internal SRAM, here

    used for (among other things) the

    FIFO memory. The PIC16C64 is

    equipped w ith peripherals such as a

    real-time clock, timer/coun ter a nd

    ca pture/compa re inputs . In this

    ap plica tion w e do not use the 3-w ire

  • 5/24/2018 PCB Drilling Machine 2

    6/7

    sy nch ronous seria l SPI/I2C bus.

    The modified Centronics interface uses

    port D (data signals), RC6 (active-low

    STROBE), RE1 (SELECT) and RC7 (ERROR).

    The BUSY sig na l from t he microcont roller is

    not w ired to the sta nda rd connection on pin

    11, but to t he PAPER EMP TY signa l (PE) onpin 12. There are s everal reas ons for this: fi rst,

    it prevents the PCB drilling machine from

    springing into action w hen a print job is

    sta rted under Window s, and s econd, it

    allow s a printer to operat e in parallel w ith the

    ma chine. Further, pulses on t he STROBE a nd

    BUSY signals appear to af fect the internal

    interrupt processing of Window s: a nd t hat is

    best left w ell alone.

    R44 is the pull-up resistor referred to above

    tha t pulls STROBE high in the event of a sy s-

    tem crash, thus deactivat ing the signa l.

    The microcontroller determines the config-uration of the drilling mac hine via t he d rilling

    head limit sw itches connected to Bo1-Bo4. I fa d rilling arm is fit ted a nd the hea d is in the

    up position, the corresponding s w itch is

    closed. If an a rm is not equipped w ith a limit

    sw itch, the corresponding conta cts remain

    open.

    OptSpare is an opt ical input tha t, like thesw itch input Spare, is not used in the present

    design. OptBase is an optical input used t ocalibrate the reference positions of arm 1,

    arm 2 and the rota t ing tab le . OptAdd does

    the same job for arms 3 and 4. How exactlythe ca libration is ca rried out w ill be des cribed

    in a la ter a rticle in this series. The LED can

    be used t o indicat e tha t the ma chine is oper-

    at ing: it lights during drilling a nd d uring the

    calibrat ion process.

    It ma y s eem t hat 33 I/O-ports are plenty,

    but unfortunately are not enough for all the

    signals just described. We therefore use a

    shift register type 74HC165 (IC14) to combine

    the bits into a single byte read serially by the

    microcontroller over a single port bit RA4

    (SOUT). A para llel load p ulse load s th e bits

    into an intermediat e register where they a rebuffered b efore being clocked out us ing th e

    CLK sig na l (RB2).

    The final item of informa tion read by the

    controller is the st op sign al from the sole-

    noid l imit sw itch. These sw itches are con-

    nect ed t o BU1-BU4. Since the current must be

    sw itched off quickly, it is not fea sible to read

    these signa ls out s lowly via a shif t register.

    Instead, the stop signal drives the interrupt

    input RB0 low. Since only one d rilling hea d is

    act uated at a time, the four limit sw itches can

    be c onnected in pa rallel.

    The rest of the circuit consists of the fouridentical output drive stag es for the solenoids

    (T1, T2, T7 a nd T8), the d rill m ot ors (T3-T6)

    and ten identical integrated stepper motor

    GENERALIN TEREST

    654/2001 Elektor Electronics

    Table 1: M ot or pu lse com m and

    MSB Byte1 Byte2 LSB

    1 Z Z Z D T T T Z Z Z Z Z Z Z Z

    Addressing:bit 7, byte 1 = 1.

    Z (11 bits): Time

    The time value specifies how long AFTER the execution of the motor pulse com-

    mand the controller must w ait before executing the next instruction. If the value

    is zero, then the next command (assuming it is also a motor pulse command) is

    executed immediately and synchronously w ith the present one.

    T (3 bits): TargetThese three bits select the stepper motor drive stage affected by the co mmand.

    The order runs from Target 1 (000), the o utput stage driving connectors K11

    and K12, through to Target 5 (100), the o utput stage driving connectors K19 and

    K20.

    Target addresses 6, 7 and 8 (101, 110 and 111) are reserved.

    D (1 bit): Direction

    This bit specifies the direction in which the motors are to turn. D= 1 specifies

    clockwise rot ation, D = 0 counterclockwise.

    Table 2: Dr i l l i ng com m and

    MSB Byte1 Byte2 LSB

    0 T T T 1 1 B B B B B D D D D D

    Addressing:bit 7, byte 1 = 0; bits 2 and 3, byte 1 = 11.

    T (3 bits): Target

    These three bits select the output stage for the drilling command. The machine

    can be fit ted w ith up to four arms, and each of these arms has its own drill and a

    dedicated driver stage on t he controller board. The targets are numbered from

    left to r ight, start ing with Target 1 (000) at connect or K10, where the solenoid

    for the first arm is connected. The corresponding drill motor is connected to K8.

    Target 4 (011) is driven from connectors K5 (solenoid) and K3 (drill mot or). Tar-gets 5 to 8 (100 to 111) are reserved.

    D (5 bits): Drilling force

    The force applied to the drill by the solenoid can be controlled by this five-bit

    data value. The value sets the amuont of energy delivered to the solenoid, and

    can be set to any number in the range 0 to 31.

    B (5 bits): Braking control

    When the drilling head is withdrawn the solenoid cannot simply be switched off,

    since this would cause long-term w ear on the mechanism. To prevent undue

    stress on the motor guide spring, the magnetic field in the solenoid is gradually

    reduced, so that the drilling head is withdrawn gently.

    In principle this value can be set in advance for a particular weight of drilling head.Here, however, we have the possibility of optimising the value. If, for example,

    you use a more powerful drill motor or a 3-jaw chuck instead of the collet chuck,

    the weight of the drilling head may be significantly different.

  • 5/24/2018 PCB Drilling Machine 2

    7/7

    drivers type PBL3717A from ST Microelec-

    tronics. The da ta sheet for this IC can read ily

    be found on STs w ebsite a t w w w .s t .com.

    First let us consider the drill motors and

    solenoids. These are not driven directly, but

    rather via a programma ble logic device type

    GAL 16V8. You ca n read t he reason s for thisin the box A universal control ler board.

    Address signals ADR0 (RC3) and ADR1 (RC4)

    select from the a t most four motors a nd s ole-

    noids in t he order show n. The level on DRILL

    (RC5) select s eithe r the mot or (w hen RC5 is

    low ) or the s olenoid (w hen RC5 is high). In

    this w ay w e make sure that in the case of a

    failure in the c ircuit the drill w ill not turn a nd

    the d rilling hea d w ill be up. When the circuit

    is sw itched on, the PICs ports are in a high

    impedance state , and resistors R1 and R2

    hold the signals at suitable levels to ensure

    that the motors and solenoids are safelyturned off.

    The controller activates the selected

    motor/solenoid p air us ing port pin RC2. The

    pin does not just t urn on and off, but provide

    a current c ontrol using a PWM signa l, different

    for the s olenoid a nd for the motor.

    The solenoids a re controlled using a rather

    complicat ed current w av eform. The timing

    depends on the instanta neous position of the

    drilling head (w hich is determined from the

    tw o sw itches on the head g uide), the value

    specif ied in the dril l ing command, and on

    w hether an error s ituation a rises d ue, forexample, to a timeout resulting from a

    jam med or dirty g uide. The importa nt fa ct is

    that the PWM control value is calculated a t

    each point in time to actua te the g uide sole-

    noid as smoothly as poss ible.

    The solenoid coils are rated for continuous

    opera t ion a t 12 V, and t hey are dr iven

    (althoug h only moment arily) from the

    s a me + 30 V s upply a s the s te pper

    motors. This produces an enormous

    magnetic field to force the drilling

    head dow n. As soon as the appro-

    priat e Bo sw itch opens, the PIC can

    deduce tha t the solenoid ha s movedand it then proceeds to regulate the

    current to t he value specified in the

    drilling command using the PWM

    signal. Although the solenoid is ini-

    tially overdriven, in continuous oper-

    ation it is only driven at effectively

    12 V w ith a n 80%dut y cy cle. This is

    w ithin the sp ecified limits. Overall,

    w ith typical activity, the duty cycle

    is only a few percent, and in pract ice

    the coils only get w arm to the touch.

    The drill motors are controlled

    during sw itch-on and running usinga PWM ramp that reaches 100%duty

    cycle d uring drilling .

    The stepp er motors are ac tiva ted

    using the STEP s ignals . Ea ch

    PBL3717A integrated driver controls

    one motor w inding, and tw o drivers

    (STEPAx and STEPBx) are allocated

    to each motor. The drivers are

    responsible for producing the d rive

    pulses and for conver t ing the + 5 V

    logic levels to + 30 V, the operat ing

    voltage of the stepper motors. The

    microcontroller act ivates the d rivervia the level (repsectively from

    STEPAx and STEPBx) at the PHASE

    input, and a current then fl ow s from

    OA to OB. Input s IN0 a nd IN1 have a

    special function: they allow control

    of the output sta ge d rive current.

    This is norma lly a chieved us ing a

    retriggerable timing circuit for each

    output stage. If no more motion is

    required of the motors, the pulses

    stop a nd t he current is reduced in

    the mot ors. Here, this is realised via

    the s igna l from RB7 (pin 40) con-

    nected to the IN1 pins of all thePBL3717s. When motion is required,

    all the motors a re driven w ith full

    current (even those w hich are not to

    move), by setting IN1= 0. Shortly

    aft er the motion stops, IN1 is set t o

    1 again, and the current drive is

    redu ce d to 19%.

    Why do w e increas e the current

    to the motors not involved in a

    motion? Partly because in this w ay

    the pow er supply is loaded to the

    same extent independent of the

    motion, and partly because, as aresult of various resonances in the

    sys tem, those mot ors driven at 19%

    of the maximum current can be

    jogg ed out of position. Althoug h this

    is rath er unlikely, it w ould lead t o

    errors almost impossible to track

    d ow n.

    (010024-2)

    In t he next instalm ent of thi s seriesw e get dow n to t he constr uct ion of

    t he contr ol ler board as well as t he

    nut s and bolt s of the project. The var-

    ious parts of the PCB dri l l ing

    machine w i l l be brought t ogeth er,

    w ith il lustrati ons and lots of glue

    and g rease!

    GENERALINTEREST

    66 Elektor Electronics 4/2001