Skip to content

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.

Notifications You must be signed in to change notification settings

MimHosseini/Embedded-Open-Source-FOC-Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Embedded-FOC-Library

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.

Embedded FOC Library

License Platform

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).

image

πŸš€ Features

  • 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.

πŸ›  Implementation Details

Sliding Mode Observer (SMO)

The sensorless algorithm is based on state-of-the-art research papers:

  1. Contributions to Discrete-Time Sliding Mode Observers for Permanent Magnet Synchronous Motor Drive Systems (IEEE).
  2. A High-Speed Sliding-Mode Observer for the Sensorless Speed Control of a PMSM (IEEE).

Mathematical Optimization

The library uses float types and is optimized for ARM CMSIS-DSP compatible environments. It prioritizes execution speed while maintaining high numerical precision.

πŸ“‚ Project Structure

  • foc.c / foc.h: Core algorithms and transforms.
  • main.c: Example integration with STM32 HAL.

🏁 Getting Started

  1. Include foc.h in your project.
  2. 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);

⚠️ Requirements

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

www.esfdrive.ir

πŸ“„ License This project is licensed under the MIT License

About

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.

Topics

Resources

Stars

Watchers

Forks