Lesson 2. The turret: four pens
In picturesAfter this lesson the plotter head is a turret: a turntable with four pens — black, red, green and blue. The SELECT button picks a colour, and the circuit turns the table by itself until the right pen reaches the work point. While the table is turning, the yellow BUSY lamp is lit and no pen touches the paper.
2.1. Idea: changing the pen means turning
The Apple colour plotter had just such a head: several pens in a circle, a turn brings the right one to the paper. Our table is a stepper motor with a disk and four holes d0…d3, 90° apart. The work point is where the black pen stands now (d0). A quarter turn — and the next pen comes to it.
2.2. Idea: the motor is two flip-flops in a ring
The table motor has four windings A B C D. Two neighbouring windings on — the rotor stands between them; switch to the next pair — the rotor steps 15°. The pairs go round: AB → BC → CD → DA → AB. A pair of CD4013 D flip-flops closed in a ring does exactly this: D1 = NJ2, D2 = J1, both clocked by the step STEPT. What happens on each step:
| Step | J1 | J2 | A=NJ1 B=NJ2 C=J1 D=J2 | Windings |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 1 0 0 | A B |
| 1 | 1 | 0 | 0 1 1 0 | B C |
| 2 | 1 | 1 | 0 0 1 1 | C D |
| 3 | 0 | 1 | 1 0 0 1 | D A |
| 4 | 0 | 0 | 1 1 0 0 | A B — round |
Every clock — the next pair, the motor turns always the same way. Reset RST puts both flip-flops to 0 — the AB pair.
2.3. Idea: a quarter turn = 6 steps
A step is 15°, a quarter is 90°, so 6 steps. The CD4017 counts the steps: on each clock the next output O0, O1, … lights. When O6 lights, the counter is reset to O0 at once: QR = Q6 OR RST — the spare OR gate of the panel CD4071. We get a ring of 6 steps. The carry output CO is 1 on O0…O4 and 0 on O5; on the step O5 → O0 it rises — an edge once per quarter turn (QCO).
2.4. Idea: two two-bit counters
The colour number — 0 black, 1 red, 2 green, 3 blue — is two bits. Two toggle flip-flops from lesson 1 count 0, 1, 2, 3:
LC0toggles on every SELECT press;LC1toggles whenLC0falls from 1 to 0 — its clock isNLC0, which rises at that moment.
| SELECT (n) | LC1 | LC0 | Colour |
|---|---|---|---|
| 0 | 0 | 0 | black |
| 1 | 0 | 1 | red |
| 2 | 1 | 0 | green |
| 3 | 1 | 1 | blue |
| 4 | 0 | 0 | black |
The same counter CP1 CP0 remembers which pen is now at the work point; it counts quarter turns (clock QCO).
2.5. Idea: turn until they match
What we want: if the chosen colour is not the pen at the work point — turn. Two numbers are equal when all their bits are equal. A bit «differs» is exclusive OR (CD4070): X0 = LC0 ⊕ CP0, X1 = LC1 ⊕ CP1. The numbers differ if at least one bit differs:
MOVE = X0 OR X1(CD4071);- motor steps:
STEPT = CKT AND MOVE(CD4081) — the 10 Hz clock passes only while we need to turn.
They match — MOVE = 0, the clocks stop coming, the table stands. Chose a colour «backwards» — the table still turns forward until it gets there: the turret has one direction, but the circuit is simpler.
2.6. Idea: BUSY — the pen is up while turning
The pen must not touch the paper while the table turns: an arc would be drawn across the sheet. A subtlety: MOVE goes out together with the last clock, while the rotor needs a moment to get there. So the circuit remembers for half a tick that it was turning: the second CD4013 flip-flop copies MOVE to MOVED on the falling edge of the clock (NCKT = NOT CKT). Hence:
BUSY = MOVE OR MOVED— the yellow lamp;PDN = LPEN AND NOT BUSY— the pen may go down: the button says «down» and the table stands.
2.7. Idea: which pen to lower
We lower only the pen at the work point: the number CP1 CP0 → one of the four pins DOWN0…DOWN3 (a decoder on ANDs):
| CP1 | CP0 | Pen | Formula |
|---|---|---|---|
| 0 | 0 | DOWN0 | PDN AND NOT CP1 AND NOT CP0 |
| 0 | 1 | DOWN1 | PDN AND NOT CP1 AND CP0 |
| 1 | 0 | DOWN2 | PDN AND CP1 AND NOT CP0 |
| 1 | 1 | DOWN3 | PDN AND CP1 AND CP0 |
The shared halves of the formulas are built once: E0 = PDN AND NOT CP1, E1 = PDN AND CP1, then DOWN0 = E0 AND NOT CP0 and so on — eight AND gates on two CD4081s.
Why red goes into hole d3 and not d1: the table turns forward, and after a quarter turn the hole that comes to the work point is the one that stood before it — d3, then d2, then d1. Round: black d0, red d3, green d2, blue d1.
2.8. Build
On top of lesson 1. New chips and a few rewirings: to rename a label on a pin, double-click the label and type the new name; on an empty pin, double-click the pin.
Step 1. The SELECT button
| Part | Pin / action | Label / where |
|---|---|---|
| Button «SELECT» | output | SELB |
Step 2. The colour counter
The second flip-flop of the lesson 1 CD4013 (PEN UP/DOWN) was tied to GND — now it is the low bit of the colour.
| Part | Pin / action | Label / where |
|---|---|---|
| TI CD4013B | S1 R1 D1 CL1 Q1 QN1 S2 R2 D2 CL2 | GND RST NLC1 NLC0 LC1 NLC1 GND GND GND GND |
| Part | Pin | Detach from | Attach to |
|---|---|---|---|
| TI CD4013B, the one whose output = LPEN | R2 | GND | RST |
| TI CD4013B, the one whose output = LPEN | D2 | GND | NLC0 |
| TI CD4013B, the one whose output = LPEN | CL2 | GND | SELB |
| TI CD4013B, the one whose output = LPEN | Q2 | — (not connected) | LC0 |
| TI CD4013B, the one whose output = LPEN | QN2 | — (not connected) | NLC0 |
Leave unconnected: Q2, QN2 on the CD4013B.
Step 3. The motor clock
Clock — click until it shows 10Hz.
| Part | Pin / action | Label / where |
|---|---|---|
| Clock 10Hz | output | CKT |
Step 4. Compare and BUSY
| Part | Pin / action | Label / where |
|---|---|---|
| TI CD4070B | A B J C D K E F G H | LC0 CP0 X0 LC1 CP1 X1 GND GND GND GND |
| TI CD4071B | A B J C D K E F G H | X0 X1 MOVE MOVE MOVED BUSYH GND GND GND GND |
| TI CD4013B | S1 R1 D1 CL1 S2 R2 D2 CL2 Q2 | GND GND GND GND GND RST MOVE NCKT MOVED |
| TI CD4069UB | A B C I D J E F | GND GND BUSYH NBUSY CKT NCKT GND GND |
Leave unconnected: L, M on the CD4070B; L, M on the CD4071B; Q1, QN1, QN2 on the CD4013B; G, H, K, L on the CD4069UB.
Step 5. The motor and the pens
| Part | Pin / action | Label / where |
|---|---|---|
| TI CD4081B | A B J C D K E F L G H M | CKT MOVE STEPT LPEN NBUSY PDN PDN NCP1 E0 PDN CP1 E1 |
| TI CD4081B | A B J C D K E F L G H M | E0 NCP0 DOWN0 E0 CP0 DOWN1 E1 NCP0 DOWN2 E1 CP0 DOWN3 |
| TI CD4013B | S1 R1 D1 CL1 Q1 QN1 S2 R2 D2 CL2 Q2 QN2 | GND RST NJ2 STEPT J1 NJ1 GND RST J1 STEPT J2 NJ2 |
| TI CD4017B | CLOCK RESET INH O6 CO | STEPT QR GND Q6 QCO |
| TI CD4013B | S1 R1 D1 CL1 Q1 QN1 S2 R2 D2 CL2 Q2 QN2 | GND RST NCP0 QCO CP0 NCP0 GND RST NCP1 NCP0 CP1 NCP1 |
| Part | Pin | Detach from | Attach to |
|---|---|---|---|
| TI CD4071B, the one whose output = LR | G | GND | Q6 |
| TI CD4071B, the one whose output = LR | H | GND | RST |
| TI CD4071B, the one whose output = LR | M | — (not connected) | QR |
Leave unconnected: O0, O1, O2, O3, O4, O5, O7, O8, O9 on the CD4017B.
Step 6. The BUSY LED
| Part | Pin / action | Label / where |
|---|---|---|
| LED, yellow | input | BUSYH |
Step 7. The head
The table pins A…D were empty — put labels on them. The lesson 1 pen — from LPEN to DOWN0. Three new pens go into holes d3, d2, d1; colour — Alt/⌘+click the pen.
| Part | Pin / action | Label / where |
|---|---|---|
| Pen — red | colour (Alt/⌘+click) DOWN mount | red DOWN1 on d3 (hole d3 of the table) |
| Pen — green | colour (Alt/⌘+click) DOWN mount | green DOWN2 on d2 (hole d2 of the table) |
| Pen — blue | colour (Alt/⌘+click) DOWN mount | blue DOWN3 on d1 (hole d1 of the table) |
| Part | Pin | Detach from | Attach to |
|---|---|---|---|
| Turntable — the head | A | — (not connected) | NJ1 |
| Turntable — the head | B | — (not connected) | NJ2 |
| Turntable — the head | C | — (not connected) | J1 |
| Turntable — the head | D | — (not connected) | J2 |
| Pen — black | DOWN | LPEN | DOWN0 |
2.9. Check
- Turbo mode, switch the power on. The black pen is at the work point.
- PEN UP/DOWN, draw a line — black.
- SELECT — the yellow
BUSYlights up, the pen lifts, the head turns a quarter: red is at the work point.BUSYgoes out — red comes down by itself (PEN UP/DOWN is still «down»). An arrow — a red line from the same point. - SELECT again — green, blue, black again.
| SELECT (n) | At the work point | While it turns |
|---|---|---|
| 0 | black | |
| 1 | red | BUSY lit, the pen is up |
| 2 | green | BUSY lit, the pen is up |
| 3 | blue | BUSY lit, the pen is up |
| 4 | black again | BUSY lit, the pen is up |
Lesson 2 paste (Cmd+I)
Paste into the Apple ][ machine (the DEMO button) instead of lessons 1–2: it places everything built by the end of lesson 2.
# Lesson 2 - the turret: 4 pens on a turntable, SELECT, turning to the chosen pen.# ---------- mechanics: X axis, Y axis on its carriage, the head on the Y carriage, black pen, paper ----------maxis ax{len=400}(STEP=LXS, DIR=RIGHT, L0=XL0, L1=XL1, STALL=XSTALL)maxis ay{len=300, ang=90}(STEP=LYS, DIR=DOWN, L0=YL0, L1=YL1, STALL=YSTALL)mount(ay, ax.car)mtable tt(A=NJ1, B=NJ2, C=J1, D=J2)mount(tt, ay.car)mpen k0{color=black}(DOWN=DOWN0)mount(k0, tt.d0)mpaper p{w=460, h=360}at(p, 0, 0)at(ax, p, -41, -138)# ---------- panel: step clock, arrows, PEN UP/DOWN ----------clock{rt=60}(CKL)button{label="LEFT"}(LEFT)button{label="RIGHT"}(RIGHT)button{label="UP"}(UP)button{label="DOWN"}(DOWN)button{label="PEN UP/DOWN"}(PENB)# ---------- CD4071: an X arrow pressed, a Y arrow pressed; ERROR - a carriage is stuck ----------"TI CD4071B"(A=LEFT, B=RIGHT, J=LR, C=UP, D=DOWN, K=UD, E=XSTALL, F=YSTALL, L=ERROR, G=Q6, H=RST, M=QR)# ---------- CD4081: steps - the 60 Hz clock while an arrow is pressed ----------"TI CD4081B"(A=GND, B=GND, C=GND, D=GND, E=CKL, F=LR, L=LXS, G=CKL, H=UD, M=LYS)# ---------- CD4013: PEN UP/DOWN - a toggle flip-flop ----------"TI CD4013B"(S1=GND, R1=RST, D1=NLPEN, CL1=PENB, Q1=LPEN, QN1=NLPEN, S2=GND, R2=RST, D2=NLC0, CL2=SELB, Q2=LC0, QN2=NLC0)# ---------- POWER and ERROR LEDs ----------led{color=green}(VCC)led{color=red}(ERROR)# ---------- the SELECT button ----------button{label="SELECT"}(SELB)# ---------- CD4013: the high bit of the colour ----------"TI CD4013B"(S1=GND, R1=RST, D1=NLC1, CL1=NLC0, Q1=LC1, QN1=NLC1, S2=GND, R2=GND, D2=GND, CL2=GND)# ---------- the turret motor clock ----------clock{rt=10}(CKT)# ---------- CD4070: colour differs from the pen at the work point ----------"TI CD4070B"(A=LC0, B=CP0, J=X0, C=LC1, D=CP1, K=X1, E=GND, F=GND, G=GND, H=GND)# ---------- CD4071: MOVE - turn; BUSY - turning or has just finished ----------"TI CD4071B"(A=X0, B=X1, J=MOVE, C=MOVE, D=MOVED, K=BUSYH, E=GND, F=GND, G=GND, H=GND)# ---------- CD4013: MOVED - MOVE half a tick ago (second flip-flop; the first one - lesson 3) ----------"TI CD4013B"(S1=GND, R1=GND, D1=GND, CL1=GND, S2=GND, R2=RST, D2=MOVE, CL2=NCKT, Q2=MOVED)# ---------- CD4069: NOT BUSY, NOT the clock (inputs A and B - lesson 3) ----------"TI CD4069UB"(A=GND, B=GND, C=BUSYH, I=NBUSY, D=CKT, J=NCKT, E=GND, F=GND)# ---------- CD4081: motor step, the pen may go down, a pair of pens ----------"TI CD4081B"(A=CKT, B=MOVE, J=STEPT, C=LPEN, D=NBUSY, K=PDN, E=PDN, F=NCP1, L=E0, G=PDN, H=CP1, M=E1)# ---------- CD4081: which pen to lower ----------"TI CD4081B"(A=E0, B=NCP0, J=DOWN0, C=E0, D=CP0, K=DOWN1, E=E1, F=NCP0, L=DOWN2, G=E1, H=CP0, M=DOWN3)# ---------- CD4013: motor phases - two flip-flops in a ring ----------"TI CD4013B"(S1=GND, R1=RST, D1=NJ2, CL1=STEPT, Q1=J1, QN1=NJ1, S2=GND, R2=RST, D2=J1, CL2=STEPT, Q2=J2, QN2=NJ2)# ---------- CD4017: a quarter turn = 6 steps ----------"TI CD4017B"(CLOCK=STEPT, RESET=QR, INH=GND, O6=Q6, CO=QCO)# ---------- CD4013: the number of the pen at the work point ----------"TI CD4013B"(S1=GND, R1=RST, D1=NCP0, CL1=QCO, Q1=CP0, QN1=NCP0, S2=GND, R2=RST, D2=NCP1, CL2=NCP0, Q2=CP1, QN2=NCP1)# ---------- the BUSY LED ----------led{color=yellow}(BUSYH)# ---------- pens: red, green, blue ----------mpen k1{color=red}(DOWN=DOWN1)mount(k1, tt.d3)mpen k2{color=green}(DOWN=DOWN2)mount(k2, tt.d2)mpen k3{color=blue}(DOWN=DOWN3)mount(k3, tt.d1)Stuck? Something doesn't work →