Files
R8Forge/hardware/mechanics.md
T
dsh 1e7acc018e hardware: the 74LS machine gets a period bill of materials, and a mechanics plan
Two things: the TTL build is now the main target (Tang Nano looks too modern), and
the packer learned the format that makes the TTL build simple.

Format: r8forge_tape_pack --eprom writes one byte per instruction with the opcode
in the low three bits.  Then ip is the EPROM address and D2..D0 are the opcode --
no shift register, no 16 bit window, no decoder.  It wastes five bits per
instruction, and a 27C512 is exactly 64K, which is the historical instruction
budget: the 8 bit calculator (51378) and the flagship (43676) both fit.  Both
formats live in the same .r8t trailer now (format byte 1 = packed, 2 = one byte
per instruction), decode dispatches on it, and the test runs both and requires
the same output and step count.

Carrier: 74LS DIPs on a green board, 27C512 in a socket with its quartz window,
6116 SRAM, 74LS299 for the rotate, 6850 ACIA for serial, 74LS47 and four seven
segment displays on the panel, 1 MHz can oscillator.  About 31 to 40 chips, 400
to 700 CNY, a few weeks.  The FPGA stays as a bench-only stepping stone.

hardware/mechanics.md: where mechanics actually pays.  The program must stay
electronic (130 metres of paper tape for the calculator), and 512 relays for the
data ring are out, but the pointer is worth it -- > and < are 71 to 73 percent of
all steps, so a 64 position ratchet or uniselector makes the machine physically
walk the ring.  Also listed: an electromagnetic step counter (10 to 20 Hz, so
only in single step mode, with a clutch for free running), a paper tape punch or
plotter for output, a tape/card reader or plain keypad for input, and a hand crank
as the clock.  The rule that keeps this safe: mechanics only ever sit on sensor
and actuator pins and never in the logic path, and the handshake just stops the
sequencer while something moves -- since nothing in the ISA can observe time,
slower is not different.  A relay-only machine is priced honestly too: 60 to 120
relays, 10 to 50 Hz, hello in 10 to 40 seconds, the calculator in four hours, so
that one is an exhibit.

Also fixed: the synthesised macro fallback file name now carries a per-run token.
When the system temp directory is not writable every r8asm falls back to the same
working directory, so parallel ctest runs could write and import the same file --
which showed up as a random one-test failure in 0.39 seconds and nothing else.
2026-11-20 16:35:02 +08:00

7.1 KiB
Raw Blame History

多加机械:哪些地方能真的动起来

软件已经证明"语义里看不见时间",硬件 RTL 也对上了,所以现在可以放心把机械件当传感器/ 执行器加进去 —— 它们慢、有惯量、会磨损,但不参与逻辑,所以不会改变机器语义。 这条是这份文档能成立的前提。

1. 先划清界限:什么是机械做不到的

部分 能机械吗 为什么
程序纸带(51 378 条) ✗ 2.54 mm 孔距下 130 m;0.2 mm 光学带也要 10 m,而且读头精度不现实。必须电子(27C512 EPROM)
数据环(64 格 × 8 bit) 勉强 512 个继电器/磁芯 ✗ 不可能手做;留电子(6116)
dp 指针 ✓✓ 64 个位置、走一步退一步 —— 电话交换机的步进器(uniselector) 就是为这个生的
步数 ✓ 电磁计数器,每步"咔"一声
输入 / 输出 ✓✓ 纸带/卡片读入、纸带打孔/绘图仪输出、真键盘
时钟 ✓ 手摇曲柄、凸轮节拍器
逻辑(译码/微序列) ✓ 但慢 继电器能跑,但 ~10 Hz:hello(417 步)42 s ✓,计算器(166 k 步)4.6 小时 ✗

结论:机械应该加在 指针、计数、I/O、时钟 上,而不是程序存储和逻辑上。

2. 机械件的清单(按"每块钱换来的手感"排序)

2.1 dp = 64 位棘轮步进器 ★★★

这是最值钱的一项:>/< 占全部步数的 71~73%(tape_run --profile 实测),也就是说这 台机器大部分时间在移动指针。把它做成机械的,机器就真的在"咔哒咔哒"地走格子。

方案 件 价格 说明
电话步进器(uniselector) 二手拆机 ¥50~200 64 个位置、棘轮 + 电磁驱动、自带归位触点(home)✓;步进器按脉冲前进,反向用一个"倒转"线圈或第二组电刷
步进电机 + 棘轮/日内瓦机构 28BYJ-48 + 3D 打印件 ¥30 便宜、好控制(ULN2003 四相),反向容易;位置用光电码盘读回
旋转电磁铁 + 棘爪 旋转电磁铁 ¥40 单步式,最像原件,但反向要另设计
机械计数轮 + 光电索引 旧电表/里程表 ¥20 只能显示,不能驱动 ✗ 当"读数窗"用

位置读回:步进器用触点组(64 位格雷码盘,6 位),或光电码盘 + 比较器;读回值就是 dp 的 6 位地址,送进 6116 ✓。home 触点顺便做复位 ✓。

2.2 步数 = 电磁计数器 ★★

五位电磁计数器(¥2040,每来一个脉冲加一,带手动清零)。**但它的动作频率上限只有 1020 Hz** ✗:连续跑 166 k 步会变成一堆废铁。所以:

  • 单步/演示档:每按一次 STEP,计数器"咔"一下,ip、dp、当前格全在面板上 ✓;
  • 连续档:计数器脱开(机械上用一个离合器或干脆断开驱动线圈),改看电子计数 ✓。

这个"两档"设计本身就是老机器的味道(计算器/电表都这么干)。

2.3 输出 = 纸带打孔机 / 绘图仪 ★★★

每条 . 打一行孔(8 位),结果就是一条可以贴墙的纸带 ✓。

方案 做法 难度
纸带打孔 8 个微型电磁铁 + 冲模 + 步进送带(1 mm 进给) 中高(要机加工冲模)
绘图仪 旧 X-Y 绘图仪(¥200~500)或两台步进电机 + 笔架,把数字"画"出来 中(代码量在 MCU 里)
电传打字机 ASR-33 之类(已很贵) 低(接口就是 20 mA 电流环)

绘图仪那条最有性价比:字符集只要 0~9 和几个符号,画出来比打孔好看得多。

2.4 输入 = 卡片/纸带读入器 ★★

方案 做法 难度
80 列卡片 光电对管阵列(80 路太多,读 12 行就够)+ 步进送卡 中高
纸带读入 8 路红外对管 + 步进送带(和打孔机共用机构)✓ 中
真键盘 1970 年代键盘 + 二极管编码矩阵 低(最省事)
拨码开关 8 位拨码 + "送一个字符"按钮 极低(先做这个)

2.5 时钟 = 手摇 / 凸轮 ★★

  • 手摇曲柄:摇一圈 = 一个时钟脉冲 = 一条指令。面板上能直接"手算"一条 ROT-8 程序 ✓ 最有仪式感,也最适合讲解。
  • 凸轮节拍器:小电机 + 凸轮 + 微动开关,1~10 Hz 的"慢动作"档。
  • 连续档仍用晶振(1 MHz 罐头晶振)。

3. 接线原则(保证机械不破坏语义)

  1. 机械件只挂在传感器的输出和执行器的输入上:dp 步进器 ↔ 6 位地址、计数器 ↔ 时钟脉冲、打孔机 ↔ OUT 脉冲、读入器 ↔ INP 数据。逻辑永远在 74LS/EPROM 里跑。
  2. 机械动作慢于逻辑时,用握手(一个"到位"触点):> 发出一路脉冲后等回位, 状态机在这段时间不前进 —— 因为语义看不见时间,这只是变慢,不是变语义 ✓。
  3. 掉电时机械件会停在某处:dp 步进器有 home 触点,复位时归零 ✓;数据在 6116 里会丢 ✗ —— 加一个**手动"清内存"**按钮,和当年的小计算机一样。
  4. 全部 5 V,电磁铁/步进电机用 ULN2003 或继电器隔离,别把反向电动势灌进 TTL ✓。

4. 分阶段(机械版)

做什么 验收 工作量
N0 6132 电子版跑通(现在的 RTL / 面包板) 已有的 rtl_sim 那一套 已完成(仿真)
N1 机械 dp:步进电机 + 码盘,替换 6 位计数器 单步跑 hello,指针一步一步走,OUT 不变 一个周末
N2 单步档 + 电磁步数计数器 每步"咔"一声,计数与 steps 一致 一天
N3 纸带打孔 / 绘图仪输出 hello 打出可读的纸带/纸上字 一周
N4 纸带/卡片输入 从纸带喂 12 34 + .,计算器照常算 一周
N5 手摇曲柄时钟 摇一圈走一条指令 一天

5. 继电器整机(另一条路,只适合展览)

如果想让逻辑本身也是机械的:8 条指令的译码 + 64 格存储 + 循环栈,约 60~120 个继电器 (每个 812 mA,全部吸合约 1 A @ 5 V ✗ 要用 12 V 版本省电)。速度 1050 Hz:

  • hello(417 步)≈ 10~40 s ✓ 完全能看;
  • full_add(95 步)≈ 2~10 s ✓;
  • 计算器 ✗ 4 小时以上,只适合"让它跑着,明天来看"。

所以继电器机的定位是展品:面板上写着"这就是 ROT-8,它的逻辑在继电器里",跑 hello 和 full_add,旁边放一张说明为什么算不了计算器(程序太长、步数太多)。

6. 下一步

  • N1(机械 dp) 是性价比最高的一步,而且它不依赖别的机械件 —— 先把步进电机 + 码盘 接上去,看指针走格子。
  • 需要的话我可以先写一份 N1 的接线表(步进电机四相 → ULN2003 → 74LS 计数器/比较器 → 6116 地址;码盘 6 位 → 74LS244 缓冲 → 地址总线),以及 MCU/CPLD 中间那一小层的固件思路。