{
  "version": 2,
  "name": "Conveyor Counters: CTU, CTD and CTUD Parts Buffer",
  "exported": "2026-11-09T00:00:00.000Z",
  "notes": "Conveyor scene example. The belt shuttles the box between the load end (X3, left) and the drop-off end (X4, right); every arrival at X4 delivers one part to a buffer. X5 = Part Removed and X6 = Reset Counts are clicked in the simulator I/O panel (the scene does not use them). CT1 CTU counts parts delivered (batch of 10). CT2 builds the buffer count the two-instruction way: CTU on X4 plus CTD on X5, same address. CT3 builds the same count with one CTUD (CD = X5). The conveyor holds at the load end when the batch is done (CT1) or the buffer is full (CT3, 3 parts). Counters keep their counts through STOP and RUN; only RES (X6) clears them.",
  "program": [
    {"id": 1, "rn": 0,
     "comment": "CONVEYOR RUN SEAL-IN — Start latches C1. Stop (X2) is N.C., so it is ON until pressed",
     "elements": [
       {"id": 101, "kind": "parallel", "branches": [
         [{"id": 102, "kind": "contact", "type": "XIC", "addr": "X1"}],
         [{"id": 103, "kind": "contact", "type": "XIC", "addr": "C1"}]
       ]},
       {"id": 104, "kind": "contact", "type": "XIC", "addr": "X2"},
       {"id": 105, "kind": "output", "type": "OTE", "addr": "C1"}
     ]},
    {"id": 2, "rn": 1,
     "comment": "REVERSE AT DROP-OFF — box reaches the right sensor (X4): latch reverse",
     "elements": [
       {"id": 106, "kind": "contact", "type": "XIC", "addr": "C1"},
       {"id": 107, "kind": "contact", "type": "XIC", "addr": "X4"},
       {"id": 108, "kind": "output", "type": "OTL", "addr": "C2"}
     ]},
    {"id": 3, "rn": 2,
     "comment": "FORWARD AT LOAD — box back at the left sensor (X3): unlatch reverse",
     "elements": [
       {"id": 109, "kind": "contact", "type": "XIC", "addr": "C1"},
       {"id": 110, "kind": "contact", "type": "XIC", "addr": "X3"},
       {"id": 111, "kind": "output", "type": "OTU", "addr": "C2"}
     ]},
    {"id": 4, "rn": 3,
     "comment": "CTU PARTS DELIVERED — +1 on every arrival at the drop-off (rising edge of X4). DN at 10 = batch done",
     "elements": [
       {"id": 112, "kind": "contact", "type": "XIC", "addr": "X4"},
       {"id": 113, "kind": "block", "type": "CTU", "addr": "CT1", "pre": 10}
     ]},
    {"id": 5, "rn": 4,
     "comment": "BUFFER, TWO INSTRUCTIONS (1 of 2) — CTU adds a part on every arrival at the drop-off",
     "elements": [
       {"id": 114, "kind": "contact", "type": "XIC", "addr": "X4"},
       {"id": 115, "kind": "block", "type": "CTU", "addr": "CT2", "pre": 3}
     ]},
    {"id": 6, "rn": 5,
     "comment": "BUFFER, TWO INSTRUCTIONS (2 of 2) — CTD on the SAME address takes one off when a part is removed (X5)",
     "elements": [
       {"id": 116, "kind": "contact", "type": "XIC", "addr": "X5"},
       {"id": 117, "kind": "block", "type": "CTD", "addr": "CT2", "pre": 3}
     ]},
    {"id": 7, "rn": 6,
     "comment": "BUFFER, ONE INSTRUCTION — CTUD counts up on X4 and down on X5. DN = 3 or more = buffer full",
     "elements": [
       {"id": 118, "kind": "contact", "type": "XIC", "addr": "X4"},
       {"id": 119, "kind": "block", "type": "CTUD", "addr": "CT3", "cd": "X5", "pre": 3}
     ]},
    {"id": 8, "rn": 7,
     "comment": "HOLD AT LOAD — box at the load end AND (batch done OR buffer full): do not send another part",
     "elements": [
       {"id": 120, "kind": "contact", "type": "XIC", "addr": "X3"},
       {"id": 121, "kind": "parallel", "branches": [
         [{"id": 122, "kind": "contact", "type": "XIC", "addr": "CT1"}],
         [{"id": 123, "kind": "contact", "type": "XIC", "addr": "CT3"}]
       ]},
       {"id": 124, "kind": "output", "type": "OTE", "addr": "C3"}
     ]},
    {"id": 9, "rn": 8,
     "comment": "MOTOR RUN — runs while sealed in and not holding at the load end",
     "elements": [
       {"id": 125, "kind": "contact", "type": "XIC", "addr": "C1"},
       {"id": 126, "kind": "contact", "type": "XIO", "addr": "C3"},
       {"id": 127, "kind": "output", "type": "OTE", "addr": "Y1"}
     ]},
    {"id": 10, "rn": 9,
     "comment": "DIRECTION — Y2 ON = reverse (towards the load end)",
     "elements": [
       {"id": 128, "kind": "contact", "type": "XIC", "addr": "C2"},
       {"id": 129, "kind": "output", "type": "OTE", "addr": "Y2"}
     ]},
    {"id": 11, "rn": 10,
     "comment": "RESET COUNTS (1 of 3) — counters keep their count through STOP and RUN. Only RES clears them",
     "elements": [
       {"id": 130, "kind": "contact", "type": "XIC", "addr": "X6"},
       {"id": 131, "kind": "block", "type": "RES", "addr": "CT1", "pre": 0}
     ]},
    {"id": 12, "rn": 11,
     "comment": "RESET COUNTS (2 of 3)",
     "elements": [
       {"id": 132, "kind": "contact", "type": "XIC", "addr": "X6"},
       {"id": 133, "kind": "block", "type": "RES", "addr": "CT2", "pre": 0}
     ]},
    {"id": 13, "rn": 12,
     "comment": "RESET COUNTS (3 of 3)",
     "elements": [
       {"id": 134, "kind": "contact", "type": "XIC", "addr": "X6"},
       {"id": 135, "kind": "block", "type": "RES", "addr": "CT3", "pre": 0}
     ]}
  ],
  "comments": {
    "X1": "Start PB",
    "X2": "Stop PB (N.C.)",
    "X3": "Left Sensor (Load)",
    "X4": "Right Sensor (Drop-off)",
    "X5": "Part Removed",
    "X6": "Reset Counts",
    "C1": "Conveyor Run",
    "C2": "Reverse Latch",
    "C3": "Hold at Load",
    "CT1": "Parts Delivered",
    "CT1/ACC": "Parts Delivered",
    "CT2": "Buffer (CTU+CTD)",
    "CT2/ACC": "Buffer (CTU+CTD)",
    "CT3": "Buffer (CTUD)",
    "CT3/ACC": "Buffer (CTUD)",
    "Y1": "Motor Run",
    "Y2": "Direction (ON = Rev)"
  }
}
