← All projects

2026 · M.Eng. Thesis · Solo project

MyFOC — Field-Oriented Control from Scratch

A complete FOC motor-control library for three-phase BLDC/PMSM motors, written from first principles in C/C++ — no SimpleFOC, no vendor libraries — and applied to an adaptive arm-rehabilitation device.

Complete MyFOC setup: gimbal motor with 3D-printed pendulum arm clamped to the desk, wired to an Arduino UNO and the DRV8302 three-phase inverter board
The complete setup — GM4108 gimbal motor with 3D-printed mount and handle, Arduino UNO, and the DRV8302 three-phase inverter.

Overview

Field-oriented control is usually the domain of 32-bit MCUs and vendor toolchains. MyFOC implements the full stack on an 8-bit ATmega328P (Arduino UNO): forward and inverse Clarke/Park transforms, space-vector PWM with min–max common-mode injection, register-level 31.4 kHz phase-correct PWM on Timer1/Timer2, and ISR-based 4× quadrature decoding — all written from scratch so every equation in the thesis maps to a line of code.

On top of the core loop sit cascaded velocity and position controllers with anti-windup PID, an optional inner d/q current loop with cross-axis decoupling feed-forward, and an impedance/admittance mode that turns the motor into a programmable spring–damper — the basis of the rehabilitation application, where resistance adapts to the patient's effort.

Highlights

System wiring diagram: Arduino UNO connected to DRV8302 driver, power supply, BLDC motor and quadrature encoder
System architecture — Arduino UNO, DRV8302 three-phase inverter, GM4108 motor, AMT103 encoder.

Seminar presentation

My M.Eng. seminar presentation on MyFOC (University of Victoria).
C/C++ ATmega328P / AVR FOC · SVPWM DRV8302 Quadrature encoder Impedance control System ID

Code & downloads

MyFOC lives in its own repository as an installable Arduino library, complete with examples, documentation, and the raw validation data.