Skip to the content
2 layers62.5 × 27.7 mmDC Motor Speed Controller, the printed circuit board in 3D

DC Motor Speed Controller

zlyadvocate/kicadfileparse-

C++ high performance independent kicad file parser

Size
62.5 × 27.7 mm
Copper layers
2
Thickness
1.6 mm
Parts
21
Nets
11
Pads
42
Tracks, vias
64, 0
Pours
1
Routed
Yes
KiCad
KiCad 9.0 (file 20241229)
Created
21 May 2026
Updated
21 May 2026

Overview

DC Motor Speed Controller is an open-source printed circuit board by zlyadvocate, from the zlyadvocate/kicadfileparse- repository on GitHub, published under the AGPL-3.0 licence. It is a 2-layer board of 62.5 × 27.7 mm with 21 parts on 11 nets, routed with 64 tracks and 0 vias.

It is built around the NE555P and TIP122. Its parts include 4 diodes, 3 capacitors, 3 resistors, 2 connectors and 1 IC. It belongs with the robots and motor control boards of this library.

Main components

2

README

readme.md

KiCad S-Expression 解析器项目总结

一、项目背景

KiCad 使用 S-Expression 格式存储 PCB、原理图和封装库文件。原始 C++ 解析器存在性能瓶颈,84.6 MB 的 PCB 文件解析需要约 5-6 秒,序列化需要约 9 秒。

二、优化历程(14 轮迭代)

轮次优化内容代码改动效果
1Float 解析 fast_float (150 处)150 行Parse ↓ 大幅
2Footprint/Pad/Zone 首字符 switch~80 行Parse ↓ 大幅
3Track/Via/Arc 首字符 switch~50 行Parse ↓ 小幅
4Property 首字符 switch~30 行Parse ↓ 小幅
5string_view 悬挂引用 bug 修复28 处修复 pintype→intype 错误
6FastSerializeVisitor 指针直接写入~50 行Serialize ↓ 大幅
7Zone::locked 字段缺失5 行修复 CM5_MINIMA_3 解析错误
8reserve/resize bug 修复10 行修复 microwave 输出损坏
9Token 引用返回 (const Token&)~20 行Parse ↓ ~7%
10Pad/Property string 拷贝优化~30 行小幅降低内存分配
11批量去引号工具函数~20 行代码简化
12Integer 解析 fast_float (152 处)152 行Parse ↓ ~1-3%
13Token vector 预分配1 行Parse ↓ ~1-2%
14消除逐字符拼接 + 简化 skip_whitespace~40 行Parse ↓ ~28%

总计:约 650 行代码改动,14 轮迭代。


三、性能提升(jetson-agx-thor 84.6 MB,10 次平均)

阶段优化前优化后提升幅度
Parse~5.5 s1.44 s↓ 74%
Serialize~9.0 s1.84 s↓ 80%
Total~14.5 s3.32 s↓ 77%

与竞品对比:

方案Parse 84MB说明
我们的优化后1.44 sC++,零 AST 热路径
KiCad 原生~1-2 sC++,高度优化
Python kicadfiles~10-30 sPython,解释执行
优化前~5-6 sC++,完整 AST

四、关键优化技术

4.1 消除 AST 构造(最大收益)

热路径(Board/Footprint/Pad/Zone/Track/Via/Arc)通过 parse_skip_name 直接从 Token 流解析到结构体,零 AST 节点创建:

text
优化前: File → Tokenize → SExpr AST (100万节点) → from_sexpr → 结构体 → 丢弃 AST
优化后: File → Tokenize → parse_skip_name → 结构体

4.2 首字符 switch 分流

将 parse_skip_name 中的 20-40 层 if-else 链优化为首字符 switch:

cpp
switch (name[0]) {
    case 'l': if (name == "layer") ... else if (name == "locked") ... break;
    case 'n': if (name == "net") ... else if (name == "name") ... break;
    ...
}

4.3 Tokenize 阶段优化

  • 消除逐字符拼接:Symbol/Integer/Float 使用 input_.substr() 一次性构造
  • 简化 skip_whitespace:直接字符比较替代 std::isspace()
  • Token vector 预分配:tokens_.reserve(input.size() / 12)

4.4 序列化优化

  • FastSerializeVisitor 指针直接写入:避免 output += string 的多次 realloc
  • 消除 std::to_string:使用 snprintf 直接格式化到 buffer

五、质量保障

指标结果
回归测试15699 OK, 0 FAIL, 2 SKIP
修复的 bug3 个严重 bug(string_view 悬挂引用、reserve/resize 损坏、Zone::locked 缺失)
新引入依赖fast_float(header-only,Apache 2.0)
代码风格统一 fast_float 解析,统一首字符 switch 模式

六、代码结构概览

组件文件说明
Parsersexpr.h/cpp词法分析 + AST 解析
核心类型base_types.h/cppAtXY, Layer, Stroke, Font, Effects 等 50+ 类型
PCB 布局board_layout.h/cppBoard, Track, Via, ArcTrack
封装库footprint_library.h/cppFootprint, Pad, Model
铺铜系统zone_system.h/cppZone, ZoneFill, Keepout, Hatch
图形元素primitive_graphics.h/cppArc, Circle, Line, Polygon
高级图形advanced_graphics.h/cppGrArc, GrLine, GrTextBox, Dimension
焊盘/钻孔pad_and_drill.h/cppDrill, Pad, Teardrops

七、未完成的优化方向

方向预估收益难度说明
剩余 120+ 个 from_sexpr 迁移到 parse_skip_name20-30%高主要服务 SCH/SYM 文件
Token 使用 string_view15-25%中需要修改 Token 结构体
SIMD skip_whitespace (StringZilla)2-4%低引入外部依赖

八、总结

投入:650 行代码改动,14 轮迭代

产出:

  • Parse 性能提升 4 倍(5.5s → 1.44s)
  • Serialize 性能提升 5 倍(9s → 1.84s)
  • 总耗时降低 77%(14.5s → 3.32s)
  • 修复 3 个严重 bug
  • 接近 KiCad 原生加载速度

核心经验:

  1. 消除不必要的中间数据结构(AST)是最大收益来源
  2. 首字符 switch 分流是将 O(n) 字符串比较优化为 O(1) 的有效手段
  3. 消除逐字符操作(str += char)改为批量操作(substr)可带来 20%+ 提升
  4. 预分配内存(vector reserve)是低成本高收益的优化

Parts

21
QtyValueFootprintReferences
31N4007Diode_THT:D_DO-41_SOD81_P10.16mm_HorizontalD1, D2, D3
2100nFCapacitor_THT:C_Disc_D4.7mm_W2.5mm_P5.00mmC1, C2
21KResistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P7.62mm_HorizontalR1, R2
2Screw_Terminal_01x02TerminalBlock_Phoenix:TerminalBlock_Phoenix_MKDS-1,5-2_1x02_P5.00mm_HorizontalJ1, J2
1
11000uFCapacitor_THT:CP_Radial_D10.0mm_P5.00mmC3
1100KPotentiometer_THT:Potentiometer_Alps_RK163_Single_HorizontalRV1
12.2KResistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P7.62mm_HorizontalR3
1LEDLED_THT:LED_D5.0mmD4
1LOGOLOGOG***
1NE555PPackage_DIP:DIP-8_W7.62mmU1
1TIP122Package_TO_SOT_THT:TO-220-3_VerticalQ1

The 17 most common of 21 parts.

More from zlyadvocate/kicadfileparse-

5
  • 2 layers45.2 × 36.2 mmTransformerless Power Supply, the printed circuit board in 3D

    Transformerless Power Supply

    zlyadvocate/kicadfileparse-

    C++ high performance independent kicad file parser

    20 partsAGPL-3.0
  • 2 layers38.5 × 25.5 mmMạch đuổi muỗi, the printed circuit board in 3D

    Mạch đuổi muỗi

    zlyadvocate/kicadfileparse-

    C++ high performance independent kicad file parser

    16 partsAGPL-3.0
  • 2 layers34.8 × 30 mmADC Converter, the printed circuit board in 3D

    ADC Converter

    zlyadvocate/kicadfileparse-

    C++ high performance independent kicad file parser

    12 partsAGPL-3.0
  • 2 layers32.1 × 31.9 mmWater Alarm, the printed circuit board in 3D

    Water Alarm

    zlyadvocate/kicadfileparse-

    C++ high performance independent kicad file parser

    11 partsAGPL-3.0

Similar boards

  • 2 layers68 × 50.5 mmFanspeed, the printed circuit board in 3D

    Fanspeed

    Aniket95-code/Fan-Speed-Controller-NE555-PCB-design

    A simple, low-cost DC fan speed controller built around the classic NE555 timer IC operating in astable mode. Fan speed is adjusted by varying the PWM duty cycle via a potentiometer, while a TIP122 Darlington transistor…

    19 parts2
  • 2 layersDC motor speed controller, the printed circuit board in 3D

    DC motor speed controller

    arijit-arijit/pcb_design

    my journey in learning to design PCBs from scratch through tutorials and projects

    19 parts1
  • 2 layers65.3 × 33.8 mmDC Motor Speed Controller, the printed circuit board in 3D

    DC Motor Speed Controller

    adityajoshi2008/555-Timer-PWM-DC-Motor-Speed-Controller

    **555 timer-based PWM DC motor speed controller designed and developed in KiCAD for practical motor speed control.

    20 parts
  • 2 layers167.5 × 124 mmMINORAVG, the printed circuit board in 3D

    MINORAVG

    apekg-blip/PWM-based-dc-motor-speed-controller

    Built an analog DC motor speed controller using an NE555 timer IC and LM3914 LED bar graph for duty-cycle visualization. Designed the circuit schematic in KiCad, gaining experience in PWM and analog motor control

    60 parts
  • 2 layers58.3 × 35 mmDC Motor Speed Controller, the printed circuit board in 3D

    DC Motor Speed Controller

    Hirusha785/DC-Motor-Speed-Controller-PCB

    ⚡ NE555 PWM DC motor speed controller PCB designed in KiCad, featuring adjustable speed control, TIP122 driver stage, flyback protection, screw terminals, and 3D PCB renders.

    21 parts
  • 2 layers62.7 × 28.9 mmDC moter speed controller, the printed circuit board in 3D

    DC moter speed controller

    Mahender0408/Embedded-Systems-Projects

    Embedded Systems, IoT and PCB Design Projects

    19 parts
  • 2 layers57 × 32.5 mmDC MOTOR SPEED CONTROLER USING TIMER IC, the printed circuit board in 3D

    DC MOTOR SPEED CONTROLER USING TIMER IC

    MuhammadAbuzarCUI/DC-Motor-Speed-Controller-Using-555-Timer-IC-PCB-Designed-in-KiCad

    PCB design of a DC motor speed controller using the 555 timer IC to generate a PWM signal for speed control. Includes circuit schematic and PCB layout for motor speed regulation by adjusting the PWM duty cycle.

    15 parts
  • 2 layers50.4 × 33.3 mmDC motor speed controller, the printed circuit board in 3D

    DC motor speed controller

    Noraiz963/DC-Motor-Controller

    A 555-timer-based DC motor speed controller designed in KiCad — uses a variable-duty-cycle PWM signal driven through a power transistor to control motor speed with a single potentiometer.

    21 parts

Questions

How big is the DC Motor Speed Controller PCB?

It measures 62.5 × 27.7 mm and has 2 copper layers, 1.6 mm thick.

What parts does the DC Motor Speed Controller use?

21 parts, built around the NE555P and TIP122. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the DC Motor Speed Controller KiCad files?

From the zlyadvocate/kicadfileparse- repository on GitHub, at the commit this page was made from: the board is testfile/pcbsec/DC Motor Speed Controller.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the DC Motor Speed Controller design in my own project?

Its repository publishes it under the AGPL-3.0 licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).