Skip to the content
4 layers100 × 100 mmDeneme2, the printed circuit board in 3D

A completely from-scratch, bare-metal implementation of Field-Oriented Control (FOC) tailored for ultra-low inductance (3 µH) drone motors (e.g., A2212).

Size
100 × 100 mm
Copper layers
4
Thickness
1.6 mm
Parts
118
Nets
126
Pads
412
Tracks, vias
653, 217
Pours
31
Routed
Yes
KiCad
KiCad 9.0 (file 20241229)
Created
2 May 2026
Updated
2 May 2026

Overview

Deneme2 is an open-source printed circuit board by Gokasimov, from the Gokasimov/STM32-FOC-Control repository on GitHub, published under the MIT licence. It is a 4-layer board of 100 × 100 mm with 118 parts on 126 nets, routed with 653 tracks and 217 vias.

It is built around the STM32G431RBT6, TLV9062ID and IR2110S-MNS, with the AS5047D, MP1482DS-LF-Z and SS14 among its other parts. Its parts include 50 resistors, 43 capacitors, 10 ICs, 6 transistors and 5 connectors. It belongs with the robots and motor control boards and the STM32 boards of this library.

Main components

6

README

readme.md

AntigravityFOC: Bare-Metal CORDIC-Accelerated Motor Controller

C MCU Control Loop Rate

A completely from-scratch, bare-metal implementation of Field-Oriented Control (FOC) tailored for ultra-low inductance (~3 µH) drone motors (e.g., A2212). Built on a custom-designed STM32G4 PCB, this project bypasses heavy abstraction layers (like HAL and ST MC SDK) to achieve microsecond-level execution times and maximum hardware utilization.

🚀 Key Engineering Achievements

  • Blistering 40 kHz Control Loop: Pushed the STM32G4 (150 MHz) to a 25 µs execution window.
  • Extreme Execution Efficiency: Through bare-metal register manipulation, FPU caching, and eliminating heavy libraries (fmodf), the complete FOC ISR execution time was profiled and reduced from 2700 ticks to just 1055 ticks (~7 µs). The CPU remains 72% idle even at 40 kHz.
  • Ultra-Low Noise Sensing: Achieved an ADC noise floor of just 1.5 LSB standard deviation by utilizing 16x hardware oversampling and triggering the Injected ADC precisely at the TIM1 PWM valley (TRGO2).
  • CORDIC Hardware Acceleration: Offloaded heavy trigonometry (Clarke/Park transforms) to the on-chip CORDIC co-processor, calculating simultaneous Sine and Cosine in Q1.31 format in just 24 cycles.

🧠 System Architecture & Development Phases

1. Hardware Synchronization & Dead-Time

  • TIM1 Configuration: Center-Aligned Mode 2 at 40 kHz. Dead-time is finely tuned to 45 ticks (~300 ns), verified against the PJD80N06SA-AU MOSFET specifications to ensure zero shoot-through.
  • ADC Triggering: TIM1_CH5 generates a TRGO2 rising edge precisely at the PWM valley, ensuring phase currents are sampled when switching noise is mathematically zero.

2. Precision Current Sensing & VBUS Tracking

  • Symmetry & Offset: The custom shunt architecture (5 mΩ + TLV9062) yielded a near-perfect hardware symmetry with a phase difference of only 21 raw counts.
  • Dynamic VBUS Tracking: The system continuously monitors battery voltage and dynamically recalculates the Space Vector PWM (SVPWM) modulation limits in real-time.

3. High-Speed SPI & Angle Estimation

  • Bare-Metal SPI: The AS5047D magnetic encoder is read via bit-banged SPI for maximum speed (≤ 9.375 Mbps), parsing the 14-bit absolute angle.
  • Angle Extrapolation (Phase Delay Compensation): To combat the 5–8 µs calculation/ADC delay at high speeds (>5000 RPM), a predictive angle compensator ($\theta_{comp} = \theta_{measured} + \omega_{e} \times T_{delay}$) ensures the D-Q reference frame remains perfectly aligned.

4. Space Vector PWM (SVPWM)

  • Implemented a highly optimized Min-Max Zero-Sequence Injection algorithm. This centers the duty cycles, maximizes DC bus utilization, and generates a mathematically perfect sine wave across the motor phases without using lookup tables.

5. Cascaded Control Loop (Custom Anti-Windup PI)

Instead of relying on standard library PID functions, the inner and outer loops are driven by a custom-written discrete PI controller architecture.

  • Inner Current Loop (D-Q Axes): Targets a tight 3–5 kHz bandwidth to tame the massive $di/dt$ of the 3.08 µH motor. It features a custom Conditional Anti-Windup algorithm that smartly freezes the integrator only when the output is saturated in the direction of the error, allowing for instantaneous recovery from voltage limits.
  • Outer Speed Loop: Eliminated 40 kHz high-frequency quantization noise by developing a custom Angle Accumulator with a 400x downsampling ratio (updating at 10 ms). The result is a buttery-smooth speed estimation fed into the outer PI controller, featuring a first-order setpoint ramp to prevent sudden torque steps while driving the motor up to 12,000 RPM.

📊 Hardware & Telemetry Validation

To validate the math against physical reality, a custom non-blocking RAM logger was built to export high-speed telemetry without disrupting the 25 µs control loop. Detailed analysis is available in the /Results directory.

1. Outer Loop: Critically Damped Speed Response

The motor accelerates from 0 to 4000 RPM with an industrial-grade, critically damped profile. Zero overshoot, zero ringing.
(See: Results/Figure-3.png and Results/step_response.mp4)

2. Inner Loop: D-Q Current Stability

Maintaining $I_d = 0$ (Maximum Torque Per Ampere) while injecting the exact required $I_q$ (Torque) current to accelerate the rotor.
(See: Results/Figure-4.png)

3. Oscilloscope Proofs (SVPWM)

  • Phase-to-GND (Saddle Wave): Physical proof of the FPU computing the Min-Max Zero-Sequence injection. (See Results/Figure-1.jpeg)
  • Line-to-Line (Pure Sine): Proof that zero-sequence harmonics cancel out, delivering a pure sine wave to the stator. (See Results/Figure-2.jpeg)

📂 Project Structure

  • /Firmware - STM32CubeIDE project workspace containing the complete bare-metal C source code (/Core), CORDIC integration, and custom PI controllers.
  • /Hardware
    • /Kicad_Files - Source files for the custom PCB design.
    • Board.jpeg - Photo of the physical PCB prototype.
    • Board_3DView.jpg - 3D render of the PCB.
    • BOM_LIST.csv - Bill of Materials.
    • Schematic.pdf - PDF schematic of the motor drive and MCU.
  • /Results
    • Figure-X - Telemetry PNGs and Oscilloscope JPEGs verifying the control theory.
    • step_response.mp4 - Video of the motor achieving 4000 RPM seamlessly.
    • readme.md - In-depth breakdown of the telemetry and scope results.

📝 License

This project is open-source and available under the MIT License.

Parts

118
QtyValueFootprintReferences
160.1uFCapacitor_SMD:C_0805_2012MetricC3, C6, C10, C11, C15, C16, C23, C24, C25, C26, C34, C35, C36, C37, C38, C39
824kResistor_SMD:R_0805_2012MetricR3, R11, R23, R36, R37, R48, R49, R50
710kResistor_SMD:R_0805_2012MetricR5, R6, R9, R10, R15, R16, R29
610Resistor_SMD:R_0805_2012MetricR1, R2, R7, R8, R13, R14
61kResistor_SMD:R_0805_2012MetricR4, R12, R21, R22, R34, R35
61nFCapacitor_SMD:C_0805_2012MetricC30, C31, C32, C44, C45, C46
6SUD50N06Package_TO_SOT_SMD:TO-252-2Q1, Q2, Q3, Q4, Q5, Q6
51uFCapacitor_SMD:C_0805_2012MetricC1, C7, C12, C20, C21
4100nCapacitor_SMD:C_0805_2012MetricC40, C41, C42, C43
422KResistor_SMD:R_0805_2012MetricR40, R42, R44, R46
43.3KResistor_SMD:R_0805_2012MetricR41, R43, R45, R47
31nCapacitor_SMD:C_0805_2012MetricC8, C9, C13
322Resistor_SMD:R_0805_2012MetricR30, R31, R38
3270Resistor_SMD:R_0805_2012MetricR26, R27, R39
3470uCapacitor_THT:CP_Radial_D10.0mm_P5.00mmC2, C4, C5
35mResistor_SMD:R_Shunt_Vishay_WSK2512_6332Metric_T1.19mmR19, R28, R33
3Conn_01x01_PinConnector_Wire:SolderWire-2sqmm_1x01_D2mm_OD3.9mmJ2, J3, J4
3IR2110SPackage_SO:SOIC-16W_7.5x10.3mm_P1.27mmU1, U2, U3
3SS14Diode_SMD:D_SMAD1, D2, D3
3TLV9062Package_SO:SOIC-8_3.9x4.9mm_P1.27mmU4, U9, U10
210KResistor_SMD:R_0805_2012MetricR25, R32
222uCapacitor_SMD:C_0805_2012MetricC28, C29
10.1uCapacitor_SMD:C_0805_2012MetricC19
1100kResistor_SMD:R_0805_2012MetricR17
110nCapacitor_SMD:C_0805_2012MetricC14
110uCapacitor_SMD:C_0805_2012MetricC22
110uInductor_SMD:L_7.3x7.3_H3.5L1
112kResistor_SMD:R_0805_2012MetricR20
126.1kResistor_SMD:R_0805_2012MetricR24
13.3nCapacitor_SMD:C_0805_2012MetricC27
15.6kResistor_SMD:R_0805_2012MetricR18
1AS5047DPackage_SO:TSSOP-14_4.4x5mm_P0.65mmU6
1Conn_01x02_PinConnector_AMASS:AMASS_XT60-M_1x02_P7.20mm_VerticalJ1
1Conn_01x04_PinConnector_PinHeader_2.54mm:PinHeader_1x04_P2.54mm_VerticalJ6
1LM7812_TO220Package_TO_SOT_THT:TO-220-3_VerticalU8
1MP1482DS-LF-ZPackage_SO:SOIC-8_3.9x4.9mm_P1.27mmU7
1STM32G431RBT6Package_QFP:LQFP-64_10x10mm_P0.5mmU5

Similar boards

  • 2 layers85.3 × 50.3 mmBeef bridge, the printed circuit board in 3D

    Beef bridge

    anuejn/beef_bridge

    An IGBT-half-bridge-board

    36 parts1
  • 2 layers96.5 × 81.3 mmHalf bridge, the printed circuit board in 3D

    Half bridge

    asciiio/Stm32_HalfBridge

    74 parts
  • 2 layers110.3 × 110.3 mmH Bridge PCB, the printed circuit board in 3D

    H Bridge PCB

    reinto1234/H_Bridge_PCB

    The project consists of two main components: 1. HBridgePCBDesign — KiCad PCB layout and schematic. 2. HBridgePCBCode — Firmware for the ESP32 controller.

    124 parts
  • 8 layers163.5 × 123.5 mmYeti, the printed circuit board in 3D

    Yeti

    PionixPublic/reference-hardware

    BelayBox reference hardware

    278 parts70CERN-OHL-P-2.0
  • 8 layers123.5 × 58 mmBLDC MC V1.0, the printed circuit board in 3D

    BLDC MC V1.0

    AhmedAbo-Eita/BLDC_Motor_Driver

    BLDC Motor Driver hardware and firmware project including power stage, gate driver, protection circuits, and control firmware for sensor-based and/or sensorless BLDC motors.

    234 parts1
  • 4 layers100 × 100 mmFOC driver, the printed circuit board in 3D

    FOC driver

    Froggy111/foosball-bot

    228 parts1
  • 2 layers79 × 60 mmTFT RF 1.0, the printed circuit board in 3D

    TFT RF 1.0

    GrzegorzewskiSzymon/STM32_TFT_RF

    64 parts

Questions

How big is the Deneme2 PCB?

It measures 100 × 100 mm and has 4 copper layers, 1.6 mm thick.

What parts does the Deneme2 use?

118 parts, built around the STM32G431RBT6, TLV9062ID, IR2110S-MNS and AS5047D. 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 Deneme2 KiCad files?

From the Gokasimov/STM32-FOC-Control repository on GitHub, at the commit this page was made from: the board is Hardware/Kicad_Files/deneme2.kicad_pcb and its schematic Hardware/Kicad_Files/CurrentSensor.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Deneme2 design in my own project?

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