Lesson 2. Two displays
To know whether a factory works well, you have to measure it. In this lesson two displays appear on the base: on the left — how many parts are released into the line, on the right — how many are made (reached the sink). Each display is counted by a pair of CD4029 chips, and button R clears both.
2.1. Idea: what to count
Two numbers describe the whole factory:
- released — how many parts went into the line;
- made — how many came out finished.
Their difference is the work in progress: the parts that are inside the factory right now — on the belts, in the machines' buffers and being worked on. While the line is healthy, the work in progress stays at one level: as many go in as come out.
2.2. Idea: where the pulses come from
«Released» is counted by the source itself: for every part that leaves it, the OUT leg gives a short pulse. Why not a beam at the source? When the first machine is snowed under, the parts stand on the first belt touching each other, and the beam between them never opens — two parts would merge into one.
«Made» is counted by an IR pair across the last belt — that is how parts are counted on real conveyors too. The emitter always shines (In = VCC), the receiver gives 1 while the beam is whole. A part enters the beam — 0, passes — 1 again. That 0 → 1 edge is the «+1». The last belt runs fast (160 pixels a second), so even two parts in a row go along it with a gap, and the beam has time to open between them.
2.3. Idea: the CD4029 is a 4-bit counter
On a rising edge of its CLOCK leg the CD4029 adds 1 (or subtracts). Its legs:
| Leg | What it does | Here |
|---|---|---|
| CLOCK | edge 0 → 1 — the next count | OUTR / OUTM |
| UD | 1 — up, 0 — down | VCC (up) |
| BD | 1 — binary (0…15), 0 — decimal (0…9) | VCC (binary) |
| PE | 1 — load J4…J1 at once, without a clock | RST (button R) |
| J4…J1 | what to load on PE | GND (0000) |
| CI | 0 — counting allowed | see below |
| CO | 0 — «I am at 15 and about to roll over to 0» | see below |
| Q4…Q1 | the count: Q1 is the low bit | R3…R0 / M3…M0 |
Button R puts PE = 1 on all four counters: each loads J = 0000, and the displays go to 0.
2.4. Idea: two CD4029 — eight bits
One CD4029 counts only up to 15, and a shift will have 128 parts. So we take two: the low one counts Q1…Q4, the high one the next four bits. The high one must add 1 only when the low one goes from 15 to 0. That is exactly what the low one's CO leg tells: it is 0 while the low one stands at 15. We feed it to the high one's CI:
- the low one's
CI= 0 (GND) — the low one always counts; - the high one's
CI= the low one'sCO— the high one counts only on the 15 → 0 step.
| Parts | High Q4…Q1 | Low Q4…Q1 | low CO |
|---|---|---|---|
| 14 | 0000 | 1110 | 1 |
| 15 | 0000 | 1111 | 0 |
| 16 | 0001 | 0000 | 1 |
| 17 | 0001 | 0001 | 1 |
Both CD4029 are clocked by the same signal and switch at the same moment — such a counter is called synchronous. Eight bits — numbers from 0 to 255.
2.5. Idea: a display reads a bus
The counters' outputs are labels R0…R7 («released») and M0…M7 («made»). A display needs no wires: its setting names a bus — R or M — and it reads the labels with that name and the numbers 0…7 by itself and shows the number in decimal.
2.6. Assembly
- Import the kit's chips: the file
dice-chips.json(the import button in the library). A «Dice» folder appears: CD4029, CD4069, CD4081. - Insert the lesson with
Cmd+Ion top of lesson 1 (the text is at the end of the lesson). You get: - on the base — an IR pair across the last belt, button R, the «released» display (bus R) and the «made» display (bus M); - outside — four CD4029; - the source'sOUTleg gets the labelOUTR.
2.7. Check
- Switch the power on and press R — both displays show 0.
- The left display grows once a second, the right one starts to grow after about 13 seconds — that is a part's way through the line.
- After that both grow alike, the right one about 13 behind.
| What you look at | What you see |
|---|---|
| left display (R) | = the number on the source |
| right display (M) | = the number in the sink, or 1 more |
| difference | about 13 and does not change |
The right display may be 1 ahead of the sink: a part has already passed the beam but has not reached the sink yet. If the left display is less than the number on the source, R was pressed after the first parts had already left. In lesson 3 START appears, and the order becomes right: power → R → START.
Lesson 2 insert (Cmd+I)
# Lesson 2 — two counters. "Released": the source gives a short OUT pulse for every part it lets out.# "Made": an IR pair across the last belt — a part passes, the beam is whole again (0 -> 1), the counter adds one.# Each counter is two CD4029 in binary mode (BD = 1): 8 bits, 0...255. R — reset (PE loads J = 0000).# Insert on top of lesson 1 (needs the chip file dice-chips.json).reconnect(src.OUT = OUTR)irtx txM{channel=1, ang=90}(In=VCC)at(txM, B, 710, 120)irrx rxM{channel=1, ang=90}(Out=OUTM)at(rxM, B, 690, 260)button rst{label="R"}(RST)at(rst, B, 140, 290)display shR{busSource=R}at(shR, B, 300, 290)display shM{busSource=M}at(shM, B, 460, 290)"TI CD4029B"(CLOCK=OUTR, UD=VCC, BD=VCC, PE=RST, CI=GND, J1=GND, J2=GND, J3=GND, J4=GND, Q1=R0, Q2=R1, Q3=R2, Q4=R3, CO=COR)"TI CD4029B"(CLOCK=OUTR, UD=VCC, BD=VCC, PE=RST, CI=COR, J1=GND, J2=GND, J3=GND, J4=GND, Q1=R4, Q2=R5, Q3=R6, Q4=R7)"TI CD4029B"(CLOCK=OUTM, UD=VCC, BD=VCC, PE=RST, CI=GND, J1=GND, J2=GND, J3=GND, J4=GND, Q1=M0, Q2=M1, Q3=M2, Q4=M3, CO=COM)"TI CD4029B"(CLOCK=OUTM, UD=VCC, BD=VCC, PE=RST, CI=COM, J1=GND, J2=GND, J3=GND, J4=GND, Q1=M4, Q2=M5, Q3=M6, Q4=M7)¿No te sale? Algo no funciona →