Lesson 1. The buffer counter
We start from the built kits FL-01 «The Dice Game» and FL-02 «The Bottleneck»: the factory, the panel, Herbie (machine 3, 2 seconds per part), the idle meter and the SLOW switch. If you don't have them yet, build them from the FL-01 and FL-02 books: this kit is built on top. In this lesson the panel gets a display that shows how many parts are waiting for Herbie — the buffer.
First, bring Herbie back. In the last experiment of FL-02 machine 3 was sped up to 1 second, and the bottleneck was gone. Make it slow again: Alt/⌘ + click on machine 3 (third from the source) until it shows «2s» — at the bottom of the screen «Machine: 2 s per item». The time changes in turn: 0.5 → 1 → 2 → 4 seconds.
1.1. Idea: what the buffer is
The buffer is all the parts between the source and Herbie: on the belts, in the buffers of machines 1–3 and the one Herbie is working on now. It is the queue Herbie takes his work from. Measuring it is easier than it looks: the buffer is the difference of two numbers:
- in — how many parts the source has released. The panel already has this number: the «released» counter of FL-01, labels
R0…R7; - out — how many parts have passed Herbie. A new IR pair across the belt after machine 3 (
OUTH) will count them, just as the IR pair before the sink counts «made».
buffer = in − out
The sensor stands after Herbie, yet we measure the queue before him: everything that has left the source and has not yet passed the sensor is either waiting for Herbie or in his work.
1.2. Idea: subtracting by adding
There is no subtractor among the CMOS 4000 chips, but there is an adder — the CD4008, four bits. We will subtract by adding, the same trick as in any processor: add the number with a minus sign.
How do we get «minus out»? The CD4029 counter can count down (UD = 0). Start at zero and subtract one for every part: 0 → 255 → 254 → … In eight bits 255 is exactly −1, and 254 is −2: add one to 255 and an eight-bit counter goes to 0. This way of writing negative numbers is called two's complement. So the «out» counter, going down from zero, holds −out right away.
| Out | Counter down | In, for example 10 | Sum (8 bits) |
|---|---|---|---|
| 0 | 0 | 10 | 10 |
| 1 | 255 | 10 | 265 → 9 |
| 3 | 253 | 10 | 263 → 7 |
The ninth bit of the sum (the carry out of the high CD4008) is not connected anywhere — that is what «eats» the extra 256.
1.3. Formula
H = −out— two CD4029 counting down:CLOCK = OUTH,UD = 0,BD = 1(binary),PE = R(button R clears), lowCI = 0, highCI = COof the low one →H0…H7;Q = R + H— two CD4008: lowA1…A4 = R0…R3,B1…B4 = H0…H3,CI = 0; highA1…A4 = R4…R7,B1…B4 = H4…H7,CI = COof the low one →Q0…Q7;- the «buffer» display reads bus
Q.
Why two CD4029 and two CD4008 rather than one of each: when a part is released every second, up to 18 parts pile up before Herbie, and four bits only count to 15.
1.4. Assembly
- Import the kit's chips: the file
drum-chips.json. It holds everything from FL-02 plus the CD4585 and CD4008. If the editor asks about identical chips — they are the same, you can keep yours. - Insert the lesson with
Cmd+Ion top of FL-02 (the text is at the end of the lesson). You get:- on the base — an IR pair across the belt between machines 3 and 4, and the «buffer» display at the top right with its caption;
- outside — two CD4029 and two CD4008.
1.5. Check
- Power off and on → R → START (SLOW off).
- Watch the «buffer» display.
| What you look at | What you see |
|---|---|
| buffer, first 30 seconds | grows: 5 → 9 → 14 → 18 |
| buffer later | stays about 18: no more room before Herbie, the source waits |
| IR pair after Herbie | a part passed — buffer −1 |
| the source releases | buffer +1 |
Then a new shift with SLOW on (Herbie's rhythm): the buffer stays about 4.
Eighteen parts before Herbie — that is 36 seconds of his work. He does not need that much stock. In the next lesson the panel will release a part only when the buffer drops below a set number.
Lesson 1 insert (Cmd+I)
# Lesson 1 — the buffer meter. Insert on top of FL-01 «The Dice Game» + FL-02 «The Bottleneck» (chip file drum-chips.json).# Buffer = parts between the source and Herbie (machine 3): on the belts, in the buffers of machines 1–3 and in Herbie.# In = the «released» counter of FL-01 (R0…R7). Out = a new IR pair across the belt after Herbie (OUTH).# The «out» counter (two CD4029) counts DOWN from 0: it holds −out (two's complement).# Two CD4008 add: Q = in + (−out) = in − out (mod 256).irtx txH{channel=2, ang=90}(In=VCC)at(txH, B, 450, 120)irrx rxH{channel=2, ang=90}(Out=OUTH)at(rxH, B, 430, 260)"TI CD4029B"(CLOCK=OUTH, UD=GND, BD=VCC, PE=RST, CI=GND, J1=GND, J2=GND, J3=GND, J4=GND, Q1=H0, Q2=H1, Q3=H2, Q4=H3, CO=COH)"TI CD4029B"(CLOCK=OUTH, UD=GND, BD=VCC, PE=RST, CI=COH, J1=GND, J2=GND, J3=GND, J4=GND, Q1=H4, Q2=H5, Q3=H6, Q4=H7)"TI CD4008B"(A1=R0, A2=R1, A3=R2, A4=R3, B1=H0, B2=H1, B3=H2, B4=H3, CI=GND, S1=Q0, S2=Q1, S3=Q2, S4=Q3, CO=CQ)"TI CD4008B"(A1=R4, A2=R5, A3=R6, A4=R7, B1=H4, B2=H5, B3=H6, B4=H7, CI=CQ, S1=Q4, S2=Q5, S3=Q6, S4=Q7)display shQ{busSource=Q}at(shQ, B, 760, 30)text tQ{text="buffer before Herbie"}at(tQ, B, 760, 14)¿No te sale? Algo no funciona →