S32M276 - Hall sensor based 6-step BLDC motor control

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32M276 - Hall sensor based 6-step BLDC motor control

S32M276 - Hall sensor based 6-step BLDC motor control

Note:

The example was designed on:


C-project based example is a part of:

  • S32M27XEVB-SW application SW for S32M27xEVB (this 6-step application has been the part of the appliction SW from revision 1.1) 

    Application software contains: 

    • S32M27xEVB_BLDC_6Step_Hall - Low-level drivers of RTD and S32 Design Studio Configuration Tools (S32CT) are used to demonstrate a BLDC 6-step Hall application.
  • S32M276SFFRD_MC_SW  application SW for S32M276SFFRD (this 6-step application has been the part of the appliction SW from revision 1.1) 

    Application software contains: 

    • S32M276SFFRD_BLDC_6Step_Hall - Low-level drivers of RTD and S32 Design Studio Configuration Tools (S32CT) are used to demonstrate a BLDC 6-step Hall application.

Contents

1. Introduction

2. System concept

3. Hall sensor-based BLDC control

3.1. Overview of the brushless DC motor

3.2. Output voltage actuation and complementary unipolar PWM modulation technique

3.3. Position estimation based on Hall sensors

3.4 States of the BLDC control based on Hall sensors

4. Software implementation on the S32M276

4.1. S32M276 – Key modules for BLDC 6-step control

4.2. S32M276 Device initialization

4.2.1. Pins

4.2.2. AE fault interrupt

4.2.3. Clock configuration

4.2.4. Pwm and triggers - eMIOS

4.2.5. TRGMUX

4.2.6. PWM and commutation - LCU

4.2.7. eMIOS ICU

4.2.8. PIT

4.2.9. Analogue data capturing 

4.2.10.Communication and Application Extension (AE) configuration


4.3. Software architecture

4.3.1. Introduction

4.3.2. Application data flow overview

4.3.3. State Machine 

4.3.4  Application timing and interrupts

4.3.5  Speed evaluation, motor current limitation and control

4.3.6. AMMCLIB Integration

5. FreeMASTER and MCAT user interface

6. Conclusion

7. References

1. Introduction

This article describes the design of a 3-phase Brushless DC (BLDC) motor control drive using S32M276 NXP integrated solution.

Following are the supported features:

  • 3-phase BLDC speed control based on Six-step commutation control
  • Shaft position obtained by Hall sensors
  • DC-bus current and DC-bus voltage sensing
  • Motor speed determined by hall sensors
  • Application control user interface using FreeMASTER debugging tool
  • Motor Control Application Tuning (MCAT) tool
jump to top

2. System concept

The system is designed to drive a 3-phase BLDC motor. The application meets the following performance specifications:

  • Targeted at the S32M76xEVB-C064/L064 and S32MSFFRD Evaluation Boards (refer to dedicated user manual for EVBs available at www.nxp.com) See section References for more information.
  • Control technique incorporating:
    • Six-step commutation control of 3-phase brushless DC motor with hall sensors
    • Rotor position is obtained by hall sensors
    • Closed-loop speed control with action period 1ms
    • Bi-directional rotation
    • Motor current limitation
    • Alignment and start-up
    • 50μs current sampling period
  • Automotive Math and Motor Control Library (AMMCLIB) – Speed control loop built on blocks of precompiled SW library (see section References)
  • FreeMASTER software control interface (motor start/stop, speed setup)
  • FreeMASTER software monitor
  • FreeMASTER embedded Motor Control Application Tuning (MCAT) tool (motor parameters, speed loop)
  • FreeMASTER software MCAT graphical control page (required speed, actual motor speed, start/stop status, DC-Bus voltage level, DC-Bus current, system status)
  • FreeMASTER software scope (observes actual and desired speeds, DC-Bus voltage and DC-Bus current)
  • FreeMASTER software high-speed recorder (six-step commutation control quantities)
  • DC-Bus over-voltage and under-voltage, over-current, overload and start-up fail protection.
jump to top

3. Hall sensor-based BLDC control

3.1. Overview of the brushless DC motor

The description of fundamental brushless DC motor principles, overview of electronic commutation control and speed/torque control of BLDC motor can be found in NXP application note AN12435: 3-phase Sensorless BLDC Motor Control Kit with S32K144, chapters 3.1., 3.1.1., 3.1.2.

jump to top

3.2. Output voltage actuation and complementary unipolar PWM
modulation technique

The 3-phase voltage source inverter is shown on page 7 of S32M27xEVB schematics, see References. It uses single DC-bus shunt resistor (represented as R134 and R135 in parallel). DC-bus current which flows through the shunt resistor produces a voltage drop which is interfaced to the AD converter of microcontroller through the integrated Digital Programmable Gain Amplifier (DPGA) integrated inside S32M276 . The description of the PWM technique used for BLDC motor control, is available in NXP application note AN12435: 3-phase Sensorless BLDC Motor Control Kit with S32K144, chapter 3.2. The Hall sensors are connected to terminal header J200.
(In case of S32M276SFFRD, please refer to the boardmanuals and schematis, see  References)

jump to top

3.3. Position estimation based on Hall sensor

The position estimation based on Hall sensor is a simple and cost-effective way to control the commutation of BLDC motor. In BLDC motors, there are three Hall sensors mounted around the rotor or stator periphery, shifted 120° apart from each other. When the rotor magnet crosses one of the sensor, sensor generates high or low logic signal depending on the magnet polarity. As rotor magnets cross all three sensors, these sensors give out position angle from 0° to 360° every 60°.

To get optimal torque and efficiency conditions in Six-step commutation control, switching sequence of the phases energizing has to produce stator magnetic flux with 120° - 60° in relation to rotor magnetic flux, Figure 1. The picture depicts the situation when rotor enters first commutation sector “Sector 0”. This moment is indicated by Hall sensor logic “110”. In this sector, phase C is connected to positive polarity of the DC bus voltage, phase B is connected to negative polarity of the DC bus voltage and phase A is unpowered. This phases energizing creates stator magnetic flux which is 120° ahead to rotor magnetic flux. Torque is produced and angle between stator flux and rotor flux decreases from 120° to 60° as rotor moves towards the next commutation sector “Sector 2”. This process is then repeated for each commutation sector.

Figure1.PNG

  Figure 1. Speed control with current limitation

 

 The shown Hall sensor states for the particular sectors are applicable to Sunrise motor 42BLY3A78-24110 and may differ for other motor type. The resulting switching states for the mentioned motor are as per the following table, where NC denotes the not connected motor phase, LS means low side transistor and HS means high side transistor:

Table 1. Switching table.

Direction Hall A Hall B Hall C Phase A Phase B Phase C
ccw 1 1 0 NC LS ON HS PWM
ccw 1 0 0 LS ON NC HS PWM
ccw 1 0 1 LS ON HS PWM NC
ccw 0 0 1 NC HS PWM LS ON
ccw 0 1 1 HS PWM NC LS ON
ccw 0 1 0 HS PWM LS ON NC
cw 1 1 0 NC HS PWM LS on
cw 0 1 0 LS ON HS PWM NC
cw 0 1 1 LS ON NC HS PWM
cw 0 0 1 NC LS ON HS PWM
cw 1 0 1 HS PWM LS ON NC
cw 1 0 0 HS PWM NC LS ON

 

Note: The rotation direction is valid for the aforementioned Sunrise motor and may be reversed in case of other motor.

3.4. States of the BLDC control based on Hall sensors

In order to start and run the BLDC motor, the control algorithm has to go through the following states:

  • Initialization
  • Calibration
  • Alignment (initial position setting)
  • Run

3.4.1. Initialization

Initialization of variables relevant for motor control is performed in this state.

3.4.2. Calibration

In this state the DC current measurement calibration takes place.

3.4.3. Alignment

Before starting, the motor is aligned to the middle of commutation sector 0. During the alignment state, all three phases are powered in order to get the best performance behavior in either direction of shaft rotation. Phase C is connected to the positive DC bus voltage and phases A and B are grounded. The alignment time depends on the mechanical constant of the motor, including load, and also on the applied motor current.

3.4.4. Run

The block diagram of the run state is represented by Figure 2. The motor speed is estimated based on Hall events. The difference between the demanded and estimated speeds is fed into the speed PI controller. The output of the speed PI controller is proportional to the voltage to be applied to the BLDC motor. The motor current is measured and filtered and used as feedback into the current controller. The output of the current PI controller limits the output of the speed PI controller. The limitation of the speed PI controller output protects the motor current from exceeding the maximal allowed motor current.

Figure2.PNG

 Figure 2. Speed control with current limitation

jump to top

4. Software implementation on S32M276 

 

4.1. S32M276 – Key modules for BLDC 6-step control

The S32M276 is an integrated solution which comprises MCU and Application Extension part (AE). The AE includes modules such as Gate Driver Unit (GDU) and Digital Programmable Gain Amplifier (DPGA) which allow for using S32M276 in motor control applications with minimum of external components. The MCU part includes modules such as the Enhanced Modular IO Subsystem (eMIOS), Logic Control Unit (LCU), Trigger
MUX (TRGMUX), Body Cross-triggering Unit (BCTU) and Analogue-to-Digital Converter (ADC) suitable for real-time control applications, in particular, motor control applications. These modules are directly interconnected and can be configured to meet various motor control application requirements. Figure 3 shows a module
interconnection for a typical BLDC 6-step application working in Hall sensor-based mode using single shunt current sensing. The modules are described in further chapters and the detailed description can be found in the S32M27x Series Reference Manual (see section References).

jump to top

4.1.1. Module interconnection

As mentioned earlier, S32M27x consists of two parts: MCU and AE which are connected together via die-to-die (D2D) connections.

The SPI interface (part of D2D) serves for parameter settings and status monitoring of AE and the rest of D2D interface is used for motor control loop (e.g.: DC bus current reading).
The AE comprises modules vital for motor control such as Gate Driver Unit (GDU) and Digital Programmable Gain Amplifier (DPGA) which allow for using S32M276 in motor control applications with minimum of external components.
The GDU drives the power MOSFETs. The GDU is interconnected with the outputs of LCU via D2D connections.
The shunt resistor voltage drop signal (proportional to DC Bus current) is conditioned by the integrated DPGA which output is connected to the ADC via D2D connection.
DC Bus voltage is conditioned via integrated voltage dividers which outputs are connected to the ADC via D2D connection.

The MCU die modules involved in output actuation, data acquisition and synchronization of actuation and acquisition are called Control Loop. This control loop consists of the eMIOS, LCU, TRGMUX, BCTU and ADC modules. The control loop is a modular concept and is very flexible in operation and can support static, dynamic or asynchronous timing. eMIOS plays a role of the real time timer/counter. Within the control loop it is responsible for generation of basic PWM signal (period, duty cycle), generation of the trigger for analogue data capturing in the precise moment or measuring the time between commutation events. LCU enriches this modular concept with advanced features. In PWM generation it is responsible for creation of PWM complementary pairs, dead time insertion, decoding of HALL pattern and execution of a commutation table (role of the phases based on the sector) and disabling/enabling PWM outputs. BCTU and ADC modules are responsible for analog data capturing. BCTU answers question “what is going to be measured?” by a predefined list of ADC channels. The ADC answers question “How it is going to be measured?” by setting a conversion resolution, sampling duration etc.

eMIOS timer uses the concept of time-bases for signal synchronization. There are 5 channels (CH0, CH8, CH16, CH22 and CH23) which can act as the time-base what means that the other channels can see value of their counter through the bus.
CH0, CH8, CH16 can create local time-bases for 7 following channels and CH22 and CH23 can create a global time-bases for any channel. In the example eMIOS0 is used for PWM and triggers. CH1 is responsible for PWM. CH3 is responsible for triggering of the BCTU. CH3 triggers consecutive measurement of DC-bus voltage and the DC-bus current sample.

eMIOS0 and LCU are connected through TRGMUX unit which is responsible for a configurable signal interconnection within the microcontroller. The eMIOS0 channel CH1 creates basic PWM signal, and it is formed using flexible Output Pulse Width Modulation Buffered (OPWMB) mode where two compare registers (A, B) are used to control rising and falling edge independently.
LCU OUT0-OUT3, OUT8-9 create complementary PWM pairs to control MOSFETs. Besides PWM signals there is LCU input serving as direction input controlled by SW override feature and LCU inputs serving as sector inputs connected to HALL pins using TRGMUX.
The LCU uses look-up tables, output polarity control to perform commutation based on current state of the HALL signals and to create complementary PWM pattern for active phase. Configurable digital filters are used to insert deadtime to the final complementary signals for transistors.
Moreover, LCU creates speed signal by applying XOR on the HALL signals for rotor speed measurement.
Same as in PWM signal generation, OPWMB mode is used for generation of trigger signal. Channels are linked with PWM time base CH0. Time-bases CH0 operates in Modulus Counter Buffered (MCB) up counting mode, where period is set by register A.

eMIOS trigger channel is connected internally to BCTU (input channel BCTU_EMIOS_0_3) through eMIOS channel flag. In this example flag is generated on compare with register B. BCTU handles flag clearing. BCTU can control both ADCs, so list of single or parallel conversions can be invoked. In this example BCTU_EMIOS_0_3 triggers a list of single conversion of ADC0 (channel S8 to obtain DC-link current and channel S18 to obtain DC-bus voltage). Result can be stored into BCTU result register, BCTU FIFO and they are also visible in original ADC result registers or can be transferred by DMA.

eMIOS1 CH1 is used as an input capture timer to measure commutation time. CH1 operates in single action input capture (SAIC) mode where it captures value of the running timebase eMIOS1 CH23 counter to register A on the edge of the speed signal (which is brought from LCU to eMIOS using TRGMUX) for speed calculation.

Detailed description can be found in the S32M27x Series Reference Manual (see section References).

Figure3.PNG

  

   Figure 3. S32M276 modules interconnection.

jump to top

4.1.2. Module involvement in digital BLDC control loop

This section will discuss timing and modules synchronization to accomplish BLDC 6-step control on the S32M276 and the internal hardware features.

The timing diagram of the automatic synchronization between PWM and ADC in the BLDC application is shown in Figure 4.

Figure4.PNGFigure4b.PNGFigure 4. Time Diagram of PWM and ADC Synchronization and notifications.

eMios is the main component in the peripheral chain which defines precision timing. CH0 is used as time-bases for PWM and for trigger signals generation. Time-base counter is configured to up counting mode and wrapping value is defined by register A. In this example, PWM frequency and sampling frequency is 20 kHz.
eMios PWM and trigger channels can see time-base counter through the internal bus and perform compare action with registers A, B and change the channels output and generate flag on compare event. Registers A and B are double buffered and updated on reload of selected time-base. LCU using LUTs (look up tables) creates complementary PWM pairs of active phase and grounds and disconnect other phases depending on sector and direction (Phase A OUT2 and OUT3 are depicted in the diagram for simplicity).
Sector is detected automatically from current state of the HALL inputs and LCU also creates speed signal output as XOR of the HALL signals. LCU Digital filters are capable to delay edges of the LUT output and to insert the dead time. When commutation event occurs (one of the HALL signals changes its state) LCU performs commutation and eMIOS1 CH1 captures time stamp of the speed time base eMIOS1 CH23 for the speed calculation.
PWM duty cycle is calculated dynamically in periodic interrupt routine (PIT1 timer).
DC-bus current and the DC-bus voltage measurement is triggered in the middle of the PWM cycle (CH3 flag on compare B) as a list of single conversions.  When end of list event occurs, notification function is called to perform analogue data processing.   

There are three notification functions (Call from peripheral ISR is ensured by RTD) in the example. PitNotif is called periodically with 1ms period to calculate speed control algorithm and to update duty cycle. BctuListNotif is also called periodically (when all analogue quantities are measured) with the same period as PWM 50us. When commutation event occurs, eMIOS1 CH1 takes a time stamp. After 7 consecutive time stamps eMIOS1GptNotify function is called and speed is calculated. eMIOS1GptNotify is asynchronous interrupt depending on rotor speed.

Note: example also contains AE fault notification handler. This is called when AE interrupt pin (PTD3) falling edge is detected.

jump to top

4.2. S32M276 Device initialization

To simplify and accelerate application development, embedded part of the BLDC 6-step motor control application has been created using S32M276 Real Time Drivers (RTD). S32M276 can be configured either by means of S32 Configuration Tools (CT) - using GUI S32CTLocation.PNG

Peripherals are initialized at beginning of the main() function. For each S32M276 module, there is a specific configuration function that uses S32M276 RTD APIs and configuration structures generated by RTD graphical tools to configure the MCU. 

Detailed RTD documentation can be found in folder created with S32 Design Studio installation (see References).

jump to top

4.2.1. Pins

Pins input/output functionality and pins electrical configuration is generated by “PINs tool” and configuration is applied by calling Siul2_Port_Ip_Init API.

 Figure5.PNG

 Figure 5. Pin configuration in Pins tool.

jump to top

4.2.2. AE fault interrupt

PTD3 pin is used to capture interrupt from AE and input capture functionality is configured by Siul2_Icu_Ip driver. AE_INT_Handler is then the callback function used in the SW example for AE fault interrupt processing.

 Figure6.PNG

  Figure 6. Configuration of input capture for AE fault detection.

jump to top

4.2.3. Clock configuration

This clock configuration can be setup by S32CT Clocks tool which offers visual graphical user interface (GUI) to change the settings. Clock settings are applied by calling Clock_Ip_Init() function, where generated configuration by Clocks tool is an argument.

To run the core of the S32M276 at maximum frequency 120MHz, S32M276 is supplied externally by 16 MHz crystal in case of S32M27xEVB (in case of S32M276SFFRD the crystal frequency is 24 MHz). This needs to be reflected in the settings of Cloks tool. This clock
source supplies Phase-lock-loop (PLL) which its output is adjusted by dividers to 120 MHz frequency. PLL output PHI0 is then used to supply the core CORE_CLK. All real-time control peripherals are supplied by CORE_CLK, what eliminates unwanted wait states on the bus when peripherals are controlled by core during runtime. 

jump to top

4.2.4. Pwm and triggers - eMIOS

 

eMIOS timer settings for PWM generation and trigger generation are covered by Emios_Mcl_Ip and Emios_Pwm drivers.

Emios_Mcl_Ip driver is responsible for the time-base configuration. PWM time-base is up counting which is selected by item Master Bus Mode Type and wrapping value is defined by Default period item which is the value for register A (see timing diagram). eMios time-bases are initialized by calling Emios_Pwm_Ip_InitChannel  and
 Emios_Mcl_Ip_Init(), they are started synchronously by calling Emios_Mcl_Ip_ConfigureGlobalTimebase.

Emios_Mcl_Ip and Emios_Pwm drivers cover the same eMIOS peripheral instance, so PWM exclusive access is allowed. PWM and trigger channels are configured by calling Emios_Pwm_Ip_InitChannel where important settings in configuration tool are Mode select to select OPWMB mode where B stands for buffered. This mode allows double buffered update of compare registers A and B on time-base reload.
Time-base for the channel is selected by Counter Bus field where BCDE means local time-base and PwmEmiosBusRef is a reference to time-base settings.
The initial duty cycle is defined by Phase Shift (which is value for reg A) and Duty cycle (where value for register B is Duty cycle + Phase Shift).
For the update of new values  Emios_Pwm_Ip_UpdateUCRegA and Emios_Pwm_Ip_UpdateUCRegB are called. Emios_Mcl_Ip_ComparatorTransferDisable disables update of A and B registers, and new vales can be set. Emios_Mcl_Ip_ComparatorTransferEnable again enables update, and new values are propagated synchronously on the nearest time-base reload event.
See the BLDC 6-Step SW example for reference.

 Figure7.PNG

 

   Figure 7. Configuration of PWM and BCTU triggers.

jump to top

4.2.5. TRGMUX

 TRGMUX is responsible for interconnection of microcontroller internal signals. Hardware Group defines group of TRGMUX outputs (from TRGMUX to peripheral). Hardware Output defines the output from TRGMUX to peripheral, and Hardware Input defines input from peripheral to TRGMUX. All possibilities for TRGMUX connection can be found in S32M27x reference manual, see References.

Hint: Pins with TRGMUX out functionality are useful for debugging/visualization of internal signals.

Figure8.PNG

     Figure 8. TRGMUX configuration for Pwm, Hall and test/debug signals.

jump to top

4.2.6. PWM and commutation - LCU

The whole LCU0 instance is used for commutation control.  Logic Cells LC0 and LC2 are responsible for generation of PWM signal for MOSFETs based on PWM signal from eMIOS and selected voltage vector - switching combination of the MOSFETs. The vector defines which phase is grounded which phase is not connected (both MOSFETs are turned off) and which phase is controlled by PWM, see Table 1 in chapter 3.3.
Logic Cell LC1 converts speed direction and current HALL state (representing position sector) to desired vector. Direction input is using SW override feature and can be set by software.

Figure9.PNG

     Figure 9. LCU 0 usage and LUT for LCU0_LC1 for Hall processing.

Every Logic Cell is equipped with 4 inputs and 4 outputs. Outputs of the Look Up Table - LUT (true table) define the output state of all combinations of inputs where combination “0000” represents LSB and combination “1111” represents MSB of LUT register value. For LC1, inputs I0-I2 are Hall signals and input I3 is speed direction. There are six possible sectors 0-5. Other values (6,7) shouldn’t appear on input so zero vector is defined for them. So, Hall signals are converted to vector and speed signal is created by XOR function.

Inputs of Logic Cells LC0 and LC2 are representing the selected vector (I0-I2) and PWM signal I3. LC0 generates outputs for MOSFETs of Phase A and Phase C and LC2 generates MOSFETs outputs for the Phase B. There are six active vectors (1-6) zero vector (0) and vector for alignment (V7). During alignment process, vector inputs are set to SW override mode and align vector is selected by SW. After alignment process, vector inputs are again controlled by LC0 and LC2. Outputs from Look Up Tables of LC0 and LC2 are adjusted by digital filters to form the final signal for MOSFETs with inserted dead time.   

Figure10.PNG

 Figure 10. LCU0_LC0 and LCU0_LC2 LUTs vs the desired voltage vector.

LCU is configured by LCU_Ip driver. Configuration is applied by calling Lcu_Ip_Init. The most important parts of the configuration can be found in Lcu Logic Input tab for LCU inputs configuration and in Lcu Logic Output tab for LCU outputs configuration. The key items for Output configuration are Output LUT Control to configure the logic of the output Look Up Table, LUT Rise Filter and LUT Fall Filter to delay the edges of the LUT output. LCU channels are enabled/disabled by calling Lcu_Ip_SetSyncOutputEnable. SW override of the LCU inputs is controlled by Lcu_Ip_SetSyncInputSwOverrideEnable and values for the inputs are set by Lcu_Ip_SetSyncInputSwOverrideValue. More detailed information about working with LUT can be found in AN14482: 3-phase Sensorless PMSM Motor Control with S32M276, chapter 4.2.3.3 LCU and in the S32M27x Reference Manual (see section References).

 Figure11.PNG

 
Figure 11. LCU settings in S32CT.

jump to top

4.2.7. eMIOS ICU

eMIOS1 CH1 operates in SAIC mode and is used to capture the time stamp of the HALL time base eMIOS1 Ch23 on the edge of the speed signal (preprocessed by LCU by applying XOR on Hall sensor signals). The first important setting is in Emios_Mcl_Ip driver clock divider value = 192, which scales the clock to 625KHz to cover longer commutation periods. Important settings can be found in tabs IcuChannels and IcueMIOS. The settings are applied by calling Emios_Icu_Ip_Init. Capturing is started by calling Emios_Icu_Ip_StartTimestamp and notification is enabled by Emios_Icu_Ip_EnableNotification, see the BLDC 6-step SW example for details.  Notification function eMIOS1IcuNotify is called after 7 captured edges so the time per one mechanical revolution can be calculated. The final mechanical speed is calculated in Pit1Notif where speed control calculations are performed.

Figure12.PNG

     Figure 12. eMIOS ICU settings.

jump to top

4.2.8. PIT 

PIT timer is used to generate 1KHz periodic interrupt routine where speed control algorithm is executed. PIT is started by calling Pit_Ip_StartChannel where the period is defined by the third argument in PIT ticks.

Figure13.PNG

      Figure 13. LPIT settings.

jump to top

4.2.9. Analogue data capturing 

Adc_Sar_Ip driver is responsible for configuration of ADCs. ADC1 instance is used for motor control measurements and is controlled by BCTU (ADC Ctu mode: Control mode). The configuration is focused on how the conversion is performed. The important parameters are Conversion resolution, Data alignment, voltage reference, Sampling duration etc. The settings are applied by calling Adc_Sar_Ip_Init and calibration is executed by calling  Adc_Sar_Ip_DoCalibration.

Figure14.PNG

 

      Figure 14. ADC configuration.

BCTU settings are covered by Bctu_Ip driver. Trigger configuration Channel BCTU_EMIOS_0_3 (Trigger source item) is configured as the trigger of the list of single conversions of ADC1. List operation is set by Defines the BCTU ADC command list operational mode and selected ADC instance is defined by Adc Target Mask (2-bit information where bit0 – ADC0, bit1 – ADC1). Predefined list contains 2 items (DC-link current and DC-link voltage) where end of the list is defined by Last channel checkbox in Bctu LIST Items. List starts conversion of ADC1 S8 (DC-link current) and when it is finished list continues with ADC1 channel S28 (DC-link voltage). After the conversion of the last item, the list stars from the beginning and waits for the trigger from eMIOS.

Data are stored into FIFO1 as it is configured in Data destination item. When all 2 measured quantities are stored into the FIFO, Watermark value is exceeded, and Watermark notification is called. BCTU configuration is applied by Bctu_Ip_Init. Bctu_Ip_GetFifoCount and    Bctu_Ip_GetFifoResult are called for read the result from the FIFO.
Figure15.PNG

Figure 15. BCTU configuration. 

jump to top

4.2.10. Communication and Application Extension (AE) configuration

Configuration of communication and AE is described in NXP application note AN14482: 3-phase Sensorless PMSM Motor Control with S32M276. Identical AE configuration is used also for this SW example.

jump to top

4.3. Software architecture

Figure 16 presents the conceptual system block diagram of the BLDC Six-step control technique working in Hall sensor-based mode.

The application is optimized for S32M276 motor control peripherals to achieve the least possible core involvement in state variable acquisition and output action application. The motor control peripherals (ADC, BCTU, eMIOS, LCU) are internally linked together to work independently from the core, and to achieve deterministic sampling of analog quantities and precise commutation of the stator field. The software part of the application consists of different blocks which are described below. The entire application behavior is controlled from a PC through the FreeMASTER run-time debugging tool.

The inputs of the control loop are the measured voltages and current on the power stage: the DC bus current, and DC bus voltage. 

From a control perspective, the block diagram can be divided into two logical parts:

  • Commutation control, where the signals from Hall sensors are used to determine the actual position of the shaft. According to the identified position, the next commutation event can be prepared. This happens automatically by means of LCU without CPU processing.
  • Speed/torque control, where the required shaft velocity is compared to the actual measured speed and regulated by the PI controller. The output of the speed PI controller is the duty cycle. The duty cycle is limited by the current PI controller and assigned to the PWM.

Figure16.PNG

Figure 16. System block diagram.

4.3.1. Introduction

This section describes the software design of the Hall sensor-based BLDC Six Step Control framework application. The application overview and description of software implementation are provided. The aim of this chapter is to help in understanding of the designed software.

4.3.2. Application data flow overview

The application software has two main states: the alignment state and the run state. In the run state, the BLDC motor is fully controlled in a closed-loop mode. After the initialization of the peripheral modules has completed, the software enters the alignment state. In alignment state, the rotor position is stabilized into a known position in order to create the same start-up torque in both directions of rotation. This is achieved by applying a PWM signal to phase A. Phases B and C are assigned with a duty cycle equal to zero; that is, they are connected to the negative pole of the DC bus. The value of the duty cycle on phase A depends on the motor inertia and load applied on the shaft. Such a technique aligns the shaft into position between phase A and B, which is perpendicular to both start-up flux vectors generated by the stator winding and therefore ensures the same start-up torque in both directions of rotation. The duration of the alignment state depends on the motor’s electrical and mechanical constants, the applied current (meaning duty cycle), and the mechanical load.

When the alignment time-out expires, the application software moves to start state, which in case of Hall-based example is only a one-pass state (on the contrary to sensorless application where open loop startup takes place.

Then the state changes to the run state, where the commutation process based on the Hall sensor signals takes place, and the control enters the closed-loop mode.

jump to top

4.3.3. State Machine 

The application state machine is implemented using a one-dimensional array of pointers to state functions, called AppStateMachine[]. The index of the array specifies the pointer to the related application state function. The application state machine consists of the following seven states selected using the index variable appState value.

Possible state transitions are shown in Figure 17.

The application states are listed in the following table:

Table 2. Application states

AppState

Application state

Description

0

INIT

The INIT state provides the initial configuration of the PWM duty cycle and initialization of DC bus current offset calibration. The state machine then transitions to the STOP state.

1

CALIB

The CALIB state provides the DC bus current calibration. The state machine then transitions to ALIGNMENT state.

2

ALIGNMENT

In the ALIGNMENT state, the alignment vector is applied to the stator to set the rotor to the defined position. The duration of the alignment state and the duty cycle applied during the state are defined by the ALIGN_DURATION and ALIGN_VOLTAGE macro values accessible in the BLDC appconfig.h header file. The state machine then transitions to the START state.

3

START

Only a one-pass state in Hall-based application

4

RUN

In the RUN state, the BLDC motor is controlled in the closed-loop . Speed control and current limitation are performed as described in 4.3.5, “Speed evaluation, motor current limitation and control”. The transition to the INIT state is done by setting the appSwitchState variable to 0.

5

STOP

In the STOP state, the motor is stopped and prepared to start running. Transition to the ALIGNMENT state is performed once the appSwitchState variable is set to 1 and the freewheeling counter expires.

6

FAULT

The fault detection function is executed in the main endless loop, detecting DC bus undervoltage, DC bus overvoltage, DC bus overcurrent, and AE faults. Once any of the faults are detected, the state machine automatically transitions to the FAULT state. The PWM outputs are set to the safe state. To exit the FAULT state, all fault sources must be removed and the faultSwitchClear variable has to be set to 1 to clear the fault latch. The state machine then automatically transitions to the INIT state.

 

Figure19.png

Figure 17. Application state machine

jump to top
 

4.3.5. Speed evaluation, motor current limitation and control

The speed controller is executed in a timer interrupt every 1 ms. The actual speed is calculated from all of the last six commutation periods, and this is stored as the actual speed. The required speed is fed into the ramp function controlling the motor speed slope. The difference between the speed ramp function output and actual speed defines the speed error.

In the closed-loop mode, the actual speed error is fed into the PI controller function. Inputs to the PI controller function include the speed error and the PI controller’s parameters such as the proportional and integral gain constants. The output of the PI controller is the duty cycle, which is scaled to the PWM resolution.

At the end of the speed control function, the duty cycle is loaded into the eMIOS compare registers of eMIOS0_CH1.

The current limit controller is located in the same 1 ms timer interrupt (.../src/main.c/Pit1Notif() ) as the speed controller because the inputs and outputs of both controllers are linked together.

When the actual speed has been calculated, the current limit PI controller can be called by feeding it with the difference between the actual current and the maximum allowed current of the motor. The output of the PI controller is scaled to the number proportional to the PWM period. After the current PI controller has calculated its duty cycle, both duty cycle output values are compared to each other.

If the speed PI controller duty cycle output is higher than the current limit PI controller output, then the speed PI Controller duty cycle output value is limited to the output value of the current limit PI controller. Otherwise, the speed PI duty cycle output will be taken as the duty cycle update value. At the end, the integral portion values of both the PI controllers need to be synchronized to avoid one of the controllers increasing its internal value as far as the upper limit. If the duty cycle was limited to the current PI duty cycle output, then the integral portion of the current PI controller will be copied into the integral portion of the speed controller, and vice versa. 

4.3.6. AMMCLIB Integration


The integration of AMMCLIB is done in the manner identical to the one described in NXP application note  AN12435: 3-phase Sensorless BLDC Motor Control Kit with S32K144.

jump to top

5. FreeMASTER and MCAT user interface

The FreeMASTER debugging tool is used to control the application and monitor variables during run time. 
FreeMASTER and MCAT interface enables online application tuning and control. 

MCAT (Motor Control Application Tuning) is a graphical tool dedicated to motor control developers and the operators of modern electrical drives. The main feature of proposed approach is automatic calculation and real-time tuning of selected control structure parameters. Connecting and tuning new electric drive setup becomes easier because the MCAT tool offers a possibility to split the control structure and consequently to control the motor at various levels of cascade control structure.

FreeMASTER and MCAT user interface are described in NXP application note  AN12435: 3-phase Sensorless BLDC Motor Control Kit with S32K144.

jump to top

6. Conclusion

The design described shows the simplicity and efficiency in using the S32M276 microcontroller for Hall sensor-based BLDC motor control and introduces it as an appropriate candidate for various low-cost applications in the automotive area. MCAT tool provides interactive online tool which makes the BLDC drive application tuning friendly and intuitive.

jump to top

7. References

S32 Design Studio IDE for S32 Platform
Real-Time Drivers (RTD)
FreeMASTER Run-Time Debugging Tool
Automotive Math and Motor Control Library
S32M27x Reference Manual
S32M2xx Data Sheet
S32M27x PMSM/BLDC Motor Control Evaluation Boards
S32M276SFFRD Reference Design Board for Automotive Motor Control
BLDC PMSM low voltage motor control accessory kit
• Rashid, M. H. Power Electronics Handbook, 2nd Edition. Academic Press
Motor Control Application Tuning (MCAT) Tool

jump to top
No ratings
Version history
Last update:
‎02-07-2025 02:55 AM
Updated by: