A lightweight, modular C library for Field Oriented Control (FOC) of PMSM and BLDC motors. Featuring Clarke/Park transforms, PI controllers, Space Vector Modulation (SVM), and Sliding Mode Observer (SMO) for sensorless applications.
A professional, high-performance C library for implementing Field Oriented Control (FOC) on microcontrollers. This library is designed to be modular, easy to integrate, and optimized for MCUs with Floating Point Units (FPU).
- Mathematical Transforms:
- Optimized Clarke & Park Transforms.
- Inverse Park Transform for voltage synthesis.
- Control & Modulation:
- PID/PI Controller with Anti-Windup (Clamping method).
- Space Vector Modulation (SVM) for efficient DC bus utilization.
- Sensorless Estimation:
- Sliding Mode Observer (SMO) for position and speed estimation.
- Hardware Agnostic: Written in standard C, easily portable to STM32, ESP32, or TI C2000.
The sensorless algorithm is based on state-of-the-art research papers:
- Contributions to Discrete-Time Sliding Mode Observers for Permanent Magnet Synchronous Motor Drive Systems (IEEE).
- A High-Speed Sliding-Mode Observer for the Sensorless Speed Control of a PMSM (IEEE).
The library uses float types and is optimized for ARM CMSIS-DSP compatible environments. It prioritizes execution speed while maintaining high numerical precision.
foc.c/foc.h: Core algorithms and transforms.main.c: Example integration with STM32 HAL.
- Include
foc.hin your project. - Initialize the structures using the provided default macros:
CLARKE_TYPEDEF clarke = CLARKE_DEFAULT; PI_TYPEDEF pi_q = PI_DEFAULT;
3.Call the function pointers within your PWM or ADC interrupt:
clarke.clarke_fcn_ptr(&clarke);
Microcontroller with FPU (Floating Point Unit) is highly recommended.
If using low-end MCUs, consider converting to Fixed-Point arithmetic.
π€ Author
Mohammad Hosseini
Embedded Systems & Motor Control Specialist
π License This project is licensed under the MIT License