Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel3
include
outlinetrue
indent
exclude
typelist
class
printablefalse

FOC Architecture

What is FOC?

Field-Oriented Control (FOC), also known as vector control, is a technique used to control Permanent Magnet Synchronous Motor (PMSM) and Brushless-DC Motor (BLDC). FOC provides good control capability over the full torque and speed ranges. The FOC implementation requires the transformation of stator currents from the stationary reference frame to the rotor flux reference frame (also known as the d-q reference frame).

...

More detailed information about FOC can be found at the https://www.mathworks.com/solutions/electrification/field-oriented-control.html or https://www.pmdcorp.com/resources/type/articles/get/field-oriented-control-foc-a-deep-dive-article.

FOC Block Diagram

In Figure 1, the block diagram of the FOC is seen in detail. The Clarke transform converts the time domain components of a three-phase system (in abc frame) to two components in an orthogonal stationary frame (αβ). The Park transform converts the two components in the αβ frame to an orthogonal rotating reference frame (dq). Implementing these two transforms in a consecutive manner simplifies computations by converting AC current and voltage waveform into DC signals. Thanks to the DC magnitudes obtained by these transformations, we obtain the PI current control (to Id and Iq vectors) facility and this allows us to perform torque control.

...

Figure 1 - Block Diagram of Field-Oriented Control

Software Details

This chapter describes how the software is structured and how to configure it according to the requirements.

Folder structure

While the layers are in separate folders by design, the components of that layer are separated as *.c, *.h pair. The folder structure of the FOC project is shown in Figure 2.

...

The FOC, MCL, and HAL components are initialized into the main.c file from lower layers to upper layers (HAL → MCL → CORE). Desired API function is used through Handles, which is obtained after FOC initialization. The MATH library can be accessed by all layers. The public folder specifies the header files that are open to the user. The Public folder contains the user-accessible header files.

Program Structure

The FOC application consists of four layers. The “Hardware Abstraction Layer“ (HAL) provides 6 components to communicate with the hardware. The “Timer” is used to create the main application task timer of the FOC application and is designed with the flexibility to adapt to future requirements. The “Analog-to-Digital Converter“ (ADC) provides information from the board sensors (Input voltage, phase voltages, phase current, SinCos Resolver, Board Potentiometer, etc.). The “Motion Pulse-Width Modulation“ (MPWM) serves as the configured PWM for the motor. The “Gate Driver“ provides the control of the driver chip used the drive the motor. The “Quadrature Encoder Interface“ (QEI) is used to estimate the rotor position. The “Hall Sensors“ captures information from the GPIOs that are connected to the Hall-Effect sensors (built into the motor), therefore indicating the current state of the rotor. In other words, the main purpose of the HAL layer is to provide feedback information to the higher layers and to transmit the control request it receives from there to the motor. And while doing this, it is to provide an abstraction with hardware.

...

The components of the relevant layers, their functionality, and connections can be seen in the block diagram in Figure 3.

Hardware Abstraction Layer (HAL)

The “Hardware Abstraction Layer“ (HAL) contains 6 components to communicate with the hardware. The HAL layer uses motor control-related peripherals embedded in the netX90 IC. More detailed information about these peripherals can be obtained from NEW netMOTIONand netX 90 in Motion. For even more detailed information, see section 5.14 from https://hilscher.atlassian.net/l/cp/bAdPTfB1.

Timer

It provides the main motion application task timer event of the FOC. It is designed with the flexibility to adapt to future requirements.

ADC(Analog-to-Digital Converter)

It provides information from the netX90-MC board sensors (Temperature, Reference voltages, …), motor position feedbacks (Hall sensor sectors, Resolver, …), board voltages (DC bus voltage,…), and Gate driver feedbacks (Measured phase currents, measured phase voltages, …). In Table 1, the signals connected to the MADC matrix of the netX90-MC Rev. 3 board are shown. Green cells indicate signals used in this project are described in Table 2.

...

Table 2 - ADC-sampled signals used by the FOC application.

Gate Driver

It provides a Gate Driver control interface. The Gate Driver used in our netX90-MC Rev. 3 board is Texas Instruments DRV8323RSRGZR, 6 to 60V Three-Phase Smart Gate Driver. This driver also drives Texas Instruments' 60-V Half-Bridge Power Block Mosfets named CSD88599Q5DC (1 for each motor phase). More detailed information can be get from DRV832x 6 to 60-V Three-Phase Smart Gate Driver and CSD88599Q5DC 60-V Half-Bridge NexFET™ Power Block. The Gate Driver communicates with netX90 via the SPI channel. The Gate Driver component contains important functions such as fault detection, enabling/disabling the gate driver, coast stop, and brake mode. Especially thanks to fault detection, the burning of the motor windings can be prevented in cases such as over-current conditions.

MPWM (Motion Pulse-Width Modulation)

The MPWM component is used to modulate the 3-phase PWM signal required for motor control. Thanks to the “Event Counter Zero (ECZ)“, it generates events so that measurements, transformations, and PI controls are made and new SVPWM duty cycle values are adjusted. Event Counter Zero (ECZ) is the reduced frequency of “Beginning of Period (BOP)” events variant. If the field evt_cnt_top of register mpwm_cfg is set to a value N, an ECZ event will be sent every N+1 period. Ayrica MPWM can be synchronized to hardware-assisted cyclic network events. For detailed information, see section 5.14.3 from https://hilscher.atlassian.net/l/cp/bAdPTfB1.

QEI (Quadrature Encoder Interface)

The QEI component provides information from the Quadrature Encoder, which is mounted on the motor. Method 4 was used as the speed estimation method (see section 5.14.4.11 from https://hilscher.atlassian.net/l/cp/bAdPTfB1). It supports working with ENC0(QEI 5V TTL) and ENC1(RS422) encoder sources. The NXHX-DH adapter module serves to connect digital transmitters as TTL or RS422 (see section 3.4 from https://hilscher.atlassian.net/l/cp/15PQ1Qu1). Also, this component supports the encoder direction inversion functionality. For detailed information, see section 5.14.4 from https://hilscher.atlassian.net/l/cp/bAdPTfB1.

Hall Sensor

The Hall Sensor component provides information from the Hall Sensors, which are integrated into the motor. The Rotor position can be known by the currently active Hall Sensor. Hall sensor inputs are connected to GPIOs and according to these GPIO statuses, it can be easily determined in which hall sector the rotor is.

Motor Control Layer (MCL)

The “Motor Control Layer“ (MCL) contains 4 components.

Motion

The “Motion“ component provides basic motion functionality. Thanks to the HAL Timer component, the motion task event is created and called Timer Callback. The period of this timer callback is 1 ms, that is, a timer event occurs every 1 ms. The processes that are handled when the timer event occurs are described below.

...

Table 3 - MCL Motion Control State Machine’s state definitions

FOC Control

The “FOC Control“ component takes care of the vector part of the FOC application. It allows the motor to be driven with closed-looped(current vector control) and open-looped(voltage vector control). With the closed-looped control, it is ensured that the maximum torque value is reached by making the Id and Iq vectors orthogonal by the current PI controllers (Figure 1). In open-looped control, on the other hand, the vd and vq vectors are directly determined and given to the Inverse Park Transform block to control the motor, and maximum torque cannot be guaranteed. It is used in our application during calibration. Above, we talked about the MPWM ECZ event while explaining the MPWM component. The ECZ counter value is 2 in your application. That is, 1 ECZ event will occur in every 2 BOP events and the MPWM Event Callback will be handled. The functions handled (Figure 6) each time the MPWM event callback is invoked are described below.

...

Table 6 - MCL Foc Control current offset bias calculation state machine’s state definitions

Calibration

The purpose of the MCL Calibration component is to make the correct position estimation. To do this, it associates the position information from the feedback device (Encoder, Resolver, etc.) related to each motor hall sensor sector for both rotation directions(CW and CCW). Then it is validated whether the position values determined in the 6 Hall Sensor sector are within certain limits in both directions. If all is well, the values obtained in both directions in each sector are averaged and these values are recorded to be used in correct position estimation. The corresponding Calibration state machine is shown in Figure 10 and the behavior of the states is explained in detail in Table 7. MCL Calibration State Machine is implemented in the Mcl_CalCyclicRoutine(…) function in the “Components\Mcl\Sources\Mcl_Cal.c”.

...

Table 7 - MCL Calibration state machine’s state definitions

PSE (Position & Speed Estimation)

The PSE component transforms the data it receives from the relevant feedback devices(Encoder, Resolver, Hall Sensor from HAL layer) into meaningful and provides speed and position information for FOC control. Currently, only Encoder (with QEI interface) and Hall Sensors provide speed and position information. However, in the future, different encoder interfaces and Resolver(SinCos) will be supported.

MCL Specific Configurations

The MCL_CFG_PRM_T structure contains some MCL-specific parameters. It provides the possibility to change configuration based on MCL and is initialized in “Components\Mcl\Includes\Public\Mcl.h”. Normally these parameters are not supposed to be modified because they are tuned for the current demo application which is not expected to be changed once configured properly. Related parameters are shown in Table 8.

...

Table 8 - MCL-specific configurations

FOC API Layer (CORE)

The “Foc Api Layer“ provides an interface for the user to control the FOC application. The functions mentioned below can be accessed from the “Targets\Common\Include\Foc_Api.h” file.

Initialize FOC layer

Code Block
FOC_H                                      /* FOC handle*/
Foc_Init(FOC_INIT_PRM_T* ptFocInitPrm);    /* FOC initalization parameters */

...

Info

The FOC_INIT_PRM_T type will be explained in more detail in the Target section.

Deinitialize FOC layer

Code Block
uint32_t                   /* Hilscher status code */
Foc_DeInit(FOC_H hFoc);    /* FOC handle */ 

...

Info

Hilscher status codes are defined into the Hil_Results.h file.

Set Motor Speed

Code Block
uint32_t                                    /* Hilscher status code */
Foc_SetMotorSpeed(      FOC_H   hFoc,       /* FOC handle */
                  const int32_t lSpeed);    /* Motor speed request[RPM]
                                               Positive values - CW direction
                                               Negative values - CCW direction */

Sets the motor speed in RPM. The set speed is processed by the speed controller if the motor is operating.

Get Motor Speed

Code Block
uint32_t                                      /* Hilscher Status Code */
Foc_GetMotorSpeed(FOC_H          hFoc,        /* FOC Handle */
                  int32_t* const plSpeed);    /* Actual Motor Speed[RPM]
                                                 Positive values - CW direction
                                                 Negative values - CCW direction */

Gets the actual motor speed in RPM. The get speed is estimated through the encoder by default. If desired, the hall sensor can also be used for speed estimation, although it is not recommended. Resolver support will be available in the future as well.

Set Operation Mode

Code Block
uint32_t                                             /* Hilscher Status Code */                
Foc_SetOperationMode(      FOC_H          hFoc,      /* FOC Handle */
                     const CTRL_OP_MODE_E eMode);    /* Operation modes */

...

Table 9 - FOC Operation modes

Get Operation Mode

Code Block
uint32_t                                                        /* Hilscher Status Code */
Foc_GetOperationMode(FOC_H                          hFoc,       /* FOC Handle */
                     MCL_MOTION_CTRL_STATE_E* const peMode);    /* Motion control state machine's states */

Gets the motion control state machine's state. Since the function ”Set operation mode” manipulates the motion control state machine, the enum type “MCL_MOTION_CTRL_STATE_E“ shows the current operation mode. Related motion control state machine’s state descriptions can be found in Table 3.

Mathematical Library(MATH)

Contains all the transform and calculation functions of the FOC. It is accessible from all layers. In Figure 3, the functions included in the MATH library are shown. At the same time, hardware-related files are located here. The Targets folder structure is shown in Figure 2. The McBoardHwConfig.h file in the Common folder contains the definitions(voltage divider resistors, shunt resistors, etc.) associated with the netX90-MC board used by FOC. Thus, new values can be configured easily after a new revision.

Targets

It is the place where all layers of the FOC component are initialized, configured, started, etc.

...

The “Targets\NXHX90-MC\Sources\main.c” file is where all the initialization, configuration, and motor demo functionality resides. Only parameters that can be changed by the user, in any case, will be mentioned here.

Board configuration

The MCL_MC_BOARD_CFG_PRM_T structure contains some board-specific parameters. It provides the possibility to change configuration based on hardware changes and is initialized in “Targets\NXHX90-MC\Sources\main.c”. Normally these parameters are not supposed to be modified because they are tuned for the current NXHX90-MC board which is not expected to be changed once configured properly. Related parameters are shown in Table 10.

...

Table 10 - Board configuration parameters

Motor-specific Configuration

The Motor-specific parameters are typically found in the Manufacturer's specification for the motor. In the PROFIdrive example, this configuration is found in the structure. Related parameters are shown in Table 11.

...

Table 11 - Motor-specific configuration parameters

FOC Demo

There are two demo modes:

...

The desired demo mode is activated from the “Targets\wscript” file with manipulation of the __USE_DEMO_POTENTIOMETER parameter.

Compilation and Flashing

https://hilscher.atlassian.net/l/cp/Lz8DLZjU

Abbreviations

Abbreviation

Description

FOC

Field-Oriented Control

HAL

Hardware Abstraction Layer

ADC

Analog-to-Digital Converter

MPWM

Motion Pulse-Width Modulation

RPM

Revolutions per minute

MTPA

Maximum Torque per Ampere

MTPV

Maximum Torque per Voltage

PI

Proportional Integral

PMDC

Permanent Magnet Direct Current

BLDC

Brushless Direct Current

QEI

Quadrature Encoder Interface

MCL

Motor Control Layer

API

Application Programming Interface

CW

Clockwise

CCW

Counter-Clockwise

ECZ

Event Counter Zero

BOP

Beginning of Period

DIR

Direction

MC

Motor Control

Hi-Z

High Impedance

NTC

Negative Temperature Coefficient

MECH

Mechanical

ELEC

Electrical

GPIO

General-Purpose Input/Output

SVM

Space Vector Modulation

GDU

Gate Driver Unit

PSE

Position and Speed Estimation

MENC

Motion Encoder