7.10. Motor Control Modes
 Openloop Volts/Hz speed control with sinusoidal commutation
 Speed and position control with fieldoriented current control (FOC), sinusoidal commutation with quadrature encoder or resolver feedback.
 Sensorless speed control with fieldoriented current control using a slidingmode speed and position observer using current feedback
 Speed control with trapezoidal commutation using Hall sensor feedback
Open Loop
FOC with Position Sensor Feedback
The design supports FOC sensor control where the motor position feeds back to form a closed loop with position and speed PI control. The design senses the motor position by incremental (quadrature) encoders.
Highspeed FOC with Position Sensor Feedback
The highspeed FOC sensor mode closely resembles the standard FOC with position sensor feedback mode, but operates at 64 kHz instead of 16 or 32 kHz. In this mode, the design performs the FOC calculation only with the FOC DSP Builder IP. Phase currents U and W are directly connected to the sigmadelta ADC interface. The output space vector modulation PWM values are directly connected to the sixchannel PWM interface.
The ADC interface operates at 64 kHz and is synchronized with the PWM to eliminate FET switching noise from the power board.
The figure shows the highspeed FOC connection. In the diagram, bold lines represent the Avalon interface, single lines indicate the direct interface, and blue lines indicate one item triggers the next. ISR uses interface IP and algorithm acceleration IPs for control and diagnostics. The ISR calls Avalon memorymapped interfaces
PWM counter values reaching PWM_TRIGGER_UP and PWM_TRIGGER_DOWN initiate ADC conversion for feedbackcurrent readings. When the ADC reading stabilizes, the latch_en signal is set to high. The avs_irq signal activates each ISR service routine, determined by the irq_counter and latch_en. The irq_counter value ensures sufficient time for each ISR service routine and is automatically calculated in the software based on the FOC running speed.
Signal Name (RTL)  Signal Location 

latch_en irq_counter 
ip/ssg_emb_sd_adc/ssg_emb_sd_adc.v and ip/ssg_emb_sd_adc/ssg_emb_sd_adc_diff.v 
avs_irq irq_ack 
Ip/ssg_emb_sd_adc/ssg_emb_sd_adc.v 
Signal Name (Software)  Description 

adc_irq_ack  Set adc_irq_ack to 1 to acknowledge the interrupt request received. Set adc_irq_ack to 0 to turn on the system to handle interrupt requests. Functions are in doc_adc.c and used in motor_task.c 
FOC Sensorless
The design supports FOC sensorless control in which the design samples and uses both the motor phase voltages and currents as the feedback to the control loop.
The phase voltage calc block derives signals V_{α} and V_{β}, scaled and normalized with respect to the DC bus voltage (V_{dclink}). The DC bus voltage may drop during quick acceleration or rise during regeneration. If you do not expect the bus voltage to change much (e.g. large bus capacitance), you may use V_{α} and V_{β} generated from the inverse Clarke transform. The software function Phase_Volt_Calc_f() implements the phase voltage calculations using floatingpoint arithmetic.
The design integrates the speed estimator with the sliding mode observer (SMO) to allow a second order observer to calculate both estimated angle and estimated speed together. In FOC sensorless mode, the motor starts initially in open loop with a requested speed and switches to sensorless mode after a preset time to allow the SMO to settle. The software function SMO_Calc_f() implements the SMO calculations using floatingpoint arithmetic.
Sliding Mode Observer Theory
The observer, based on the electrical model, estimates the rotating backEMF vector. The rotor position determines the direction of the backEMF, which enables estimation of position. At constant speed, backEMF components are sinusoidal in quadrature, as are error signals. Considering voltage V and current I in one motor phase with resistance Rs, inductance Ls. Net applied voltage V is at the motor terminal, and the centre of the motor is at 0 V.
Solving the differential equation for i, assuming a constant v applied over sample time T, initial current i, and current at the end of T _{i + 1}, gives:
Normalizing by some V _{max} and I _{max} to create variables that are nondimensional and always <1, gives:
Aparm is nondimensional, represents the electrical system dynamics. Ls/Rs is the electrical time constant, Ts is the discrete sample time. Aparm should be close to 1 if the sample time is much faster than the motor time constant.
Bparm uses V_{max}/(I_{max}*R_{s}) so is also nondimensional. (1Aparm) is small.
Aparm and Bparm are constant and are calculated once during initialization of the software.
Angle Tracking Observer Theory
The angle tracking observer (part of SMO_Calc_f()) takes the estimated backEMF vector as input and outputs an estimated rotor position (phi_SMO). The backEMF estimate may be noisy so the observer filters it and converts it to position. The design provides two methods:
 #if (TRACKER_ENABLE == 0), arctan method: A first order filter with gain Lpf_Gain is applied to both alpha and beta components of the backEMF before using arctan to convert them to phi_SMO. The advantage is simplicity, but velocity must be estimated separately. The design does not use this method as the speed estimation may introduce lag.
 Angle observer method: The design combines the backEMF estimates with the last phi_SMO to calculate AObsError, which is proportional to speed*sin(actualestimate). Assuming small errors and constant speed, AobsError=K*(θ_{Elec}  phi_SMO). Phi_SMO has units of fraction of 1rev (0..1 for 0..2π rad).
The backEMF operates in the qdirection,, which is at rightangles to the ddirection (θelec_rad). The components of the backEMF in the fixed alpha and beta directions are:
 vBemfAlpha_V = dθmech_dt_rad_s*Ke_Vs_rad*sin(θelec_rad)
 vBemfBeta_V = dθmech_dt_rad_s*Ke_Vs_rad*cos(θelec_rad)
 AobsError is the backEMF in the estimated d direction (phi_SMO), which is zero if phi_SMO is equal to θelec_rad
 AObsError = vBemfAlpha_V*cos(phi_SMO)vBemfBeta_V*sin(phi_SMO)
Substituting the Bemf equations into the AObsError equation:
AObsError = dθmech_dt_rad_s*Ke_Vs_rad*( sin(θelec_rad)*cos(phi_SMO)cos(θelec_rad)*sin(phi_SMO) )
= dθmech_dt_rad_s*Ke_Vs_rad*sin(θelec_rad  phi_SMO)
Hence, if the BemfAlpha and BemfBeta values are correct, AObsError measures the angle estimation error (θelec_rad  phi_SMO).
For small error angles and at constant speed, assume AObsError = K*(θelec  phi_SMO)
AObsError = K(θ_{k} φ_{k})
The software creates a secondorder filter from θ_{elec} to phi_SMO. Filter natural frequency Ω and damping coefficient ζ are design parameters tuned for the Tamagawa motors in the Tandem MotionPower 48 V motor kit. The normalized scaling makes them suitable for other motors too with possible retuning. Carefully tune this nonlinear observer because incorrect position estimates can make the FoC algorithm oscillate or become unstable by causing positive feedback.
SMO Parameters
The design derives various SMO parameters from the motor parameters for each motor type, such as resistance and inductance. Other SMO parameters, and default values, are:
Parameter  Description 

Lpf_Gain = 0.10  Arctan method of angle calculation only. The final two stages of the SMO are a lowpass filter on each component of the estimated BEMF followed by an inverse tangent (arctan observer). The output of the inverse tangent is the estimated angle. The parameter Lpf_Gain sets the cutoff frequency of the lowpass filter. Lpf_Gain = 2*pi*fc*Ts where: Ts is the sample period and fc is the desired cutoff frequency. 
damping_coefficient = 1.4 
These are both parameters of the angle tracking observer, which takes in both unfiltered components of the estimated BEMF, extracts the angle and filters in one module. The angle tracking observer has no speed dependent phase lag, unlike the arctan observer. Setting natural_frequency too low can result in instability in the speed estimation. 
natural_frequency = 600 

Hys_Gain = 0.8 
This parameter sets the sliding mode gain on the current observer. This observer is responsible for estimating the BEMF signals that it ultimately feeds into the angle tracking observer. To adjust this parameter, run the motor and view the estimated angle waveform. If it looks like an undistorted triangle no adjustment should be necessary. If the triangle looks distorted, while running at constant speed, adjust this parameter to clean it up. 
Trapezoidal
The design supports trapezoidal control of BLDC motors using Hall sensor feedback on the Tandem MotionPower 48 V Board. The software supports Duty Mode and Torque Mode, but the demonstration GUI only uses Velocity Mode. The software reconstructs the motor current from the individual phase current readings using the Hall encoder state to determine which phase current is relevant.