[[!img rpi_pmsm_motor_control-graphs1.png size="300x" align=right alt="Simulink connected to RPi running PMSM control model"]] Raspberry Pi is often used for education and many hobbyists tasks but it is not equipped with hardware peripherals required for a quite complex vector electric motor control task. This project sumplements bare Raspberry Pi board by two other boards to implement complete educational BLDC/PMSM motor control system. One board uses small Microsemi IGL00 FPGA to implement missing peripherals and the second board implements 3-phase power stage with current sensing, ADC and galvanic isolation which can be used in this project or even connected to Altera DE2 education kits.

Three-pases PMSM Control Basics

The differences between Voltages connected to the three stator windings terminals cause current flow which forms rotating magnetic field. The direction and magnitude of this field drive permanent magnet rotor which is to align with the direction of the magnetic field vector. North pole is attracted to the south and vice versa. For constant speed and torque, the waveforms of the phase Voltages (the same for currents) are sinusoidal with an equidistant phase shift of 120 deg. The three phases system is in some respect redundant, in the case of Voltages (uA, uB, uC) only differences count, i.e. one can be fixed to zero. A sum of the three currents (iA, iB, iC) has to be zero by the Kirchhoff's current law. As a consequence, only two independent quantities/scalars are needed to describe the currents or Voltages which are in the fact vector in the 2D space.The polar coordinates system can be used but a rectangular system of alpha, beta components is equivalent and easier for transformations computation. [[!img pxmc-pmsm-block.png size="500x" align=right alt="Basic PMSM control setup diagram from PXMC library documentation"]] This transformation of the three phase system to the two orthogonal components vector is named according to its inventor Clark transformation. The waveforms in this 2D system are sine and cosine for steady speed state. Because realization of a controller in this altering components system is not feasible, another transformation was invented which convert the quantities to the coordinates fixed to the revolving rotor. A base formed by direct (D) component aligned to North, South pole direction of the rotor and orthogonal quadrature (Q) has been introduced by Robert H. Park and the transformation is named according to him. The control in the D-Q coordinates is (almost) independent of actual rotor position and (in simplified outlook) separates reactive current (iD) from the active current (iQ) resulting in torque affecting rotor movement. The simplified diagram of PMSM motor control ins included for ilustration (source PXMC library documentation).

Hardware

The RPi (and its BCM2835 SoC) is equipped with only single accessible PWM output and no peripherals suitable for incremental rotary encoder (IRC) signal processing are found on the board. Analog to digital converters are missing as well. The two extension boards with required peripherals and power stage have been designed and produced at PiKRON company. The first one includes Field Programmable Gate Array (FPGA) IGLOO AGL125-VQ100 produced by Microsemi company. The design of logic programmed into FPGA has been implemented by Martin Prudek in a frame of his bachelor theses. The FPGA design includes:

Bachelor thesis of Martin Prudek: Brushless motor control with Raspberry Pi board and Linux,, 2015
Available online in PDF format
The FPGA design of peripherals for the RPi expansion board https://rtime.felk.cvut.cz/gitweb/fpga/rpi-motor-control.git
PMSM Control Simulink Model including PRi Hardware and SPI Communication Blocks
https://github.com/ppisa/rpi-rt-control
The model and bclocks C sources are included in subdirectory "simulink", model name "rpi_pmsm_motor_control.slx".
Fully preemptive kernel sources for RPi (kernel-3.12.28-rt40+)
https://github.com/ppisa/linux-rpi
GitHub repository with branch rpi-3.18.y-aufs-rt-ppisa containing Linux kernel sources with Steven Rostedt's stable preempt_rt (patch-3.18.16-rt13) and with Junjiro R. Okajima's aufs3.18.x 20160215 patches applied.
Simulink Embedded Coder target for Linux
http://rtime.felk.cvut.cz/gitweb/ert_linux.git
Repository with core templates for Linux hosted, Linux cross architecture targetted Simulink code generation templates and configuration.
Auxiliary utilities for Raspberry Pi
https://github.com/ppisa/rpi-utils
The repository includes RAM based root overlay support to protect SDcard against wearing and tearing and keep root filesystem intact when experiments are download and run on system or even crash it.