Professional Documents
Culture Documents
Generalplus Technology Inc. reserves the right to change this documentation without prior notice.
Information provided by Generalplus Technology Inc. is believed to be accurate and reliable.
However, no responsibility is assumed by Generalplus Technology Inc. for errors, omissions or any
loss of profit resulting from the use of information contained in this documentation. In addition,
Generalplus products are not authorized for use as critical components in life support
devices/systems or aviation devices/systems, where a malfunction or failure of the product may
reasonably be expected to result in significant injury to the user, without the express written
approval of Generalplus.
Generalplus Technology
No.19, Industry E. Rd. IV, Hsinchu Science Park, Hsinchu City, 30077, Taiwan, R.O.C.
Tel: 886-3-666-2118
Fax: 886-3-666-2117
www.generalplus.com
REVISION HISTORY
TABLE OF CONTENT
Q1 Q3 Q5 Winding U
Q0 Q2 Winding V
Q4
Winding W
Figure 1.2 is the relationship of PMSM Hall Signal and Back EMF. The driving timing generally
corresponds to counter EMF.
Hall U
Bemf U
Hall V
Bemf V
Hall W
Bemf W
Hall
5 1 3 2 6 4 5 1
State
Phase back EMF of PMSM
signals
id and iq after coordinate transform. Two direct signals, Vd and Vq , will be output
through the controller, and then be inverted to get 3-phase sine wave voltages Va , Vb and Vc .
Finally, the voltages go through SVPWM and become six inverter PWM signals which can be used to
drive the motor.
ia ib ic 0
i ia
i (ia 2 ib ) / 3
id i cos i sin
iq i sin i cos
2.4. PI Controller
PI controller has a simple and easy-to-use design. FOC uses two PI controllers, which control motor
magnetic flux id and motor torque iq respectively. Figure 2.4 is the block diagram of PI controller,
and it shows the Proportional (P) and the Integral (I). Proportional (P) is signal error multiplies Kp
gain. It can make the signal error as close to 0 as possible but not convergence. There will be little
steady-state error. Integral (I) is the integral result of signal error multiplying Ki gain. The
accumulated error signal is multiplied by an Integral (I) gain factor and becomes the Integral (I)
output term of the PI controller. PI controller is the sum of Proportional (P) and Integral (I) output.
Kc*Excess can be added to PI controller in order to limit the integral windup.
Err = Ref - FB
Up = Kp * Err
Ui = Ui + Ki * Err + Kc * Excess
U = Up + Ui
IF ( U > OutMax)
Out = OutMax
ELSE IF ( U < OutMin)
Out = OutMin
ELSE
Out = U
Excess = U – OUT
V Vd cos Vq sin
V Vd sin Vq cos
Va V
Vb (V 3 V ) / 2
Vc (V 3 V ) / 2
If user needs a round rotating magnetic field, please use linear time combination as shown in Figure
2.8. U x and U x 60 are the two basic space vectors that are adjacent to the output vector U out .
U out is the linear time combination of U x and U x 60 , which equals the vector addition of U x
times t1 / TPWM and U x 60 times t 2 / TPWM . t1 and t 2 are the function time of U x and
U x 60 ; TPWM is the function time of U out . As the method mentioned above, in the next TPWM
period, the linear time combination of U x and U x 60 is still applied but the function time t1 and
t 2 are different from the last time. Therefore, if TPWM lasts for long enough, several hours for
example, the trail of the voltage space vector will be approximately a circular.
U out can be shown as the vector addition of U x times t1 / TPWM and U x 60 times t 2 / TPWM :
t1 t2
U out Ux U x60
TPWM TPWM
With the formula above and trigonometric functions, user will know that:
t1
Ux
TPWM U out
sin(60 ) sin120
t2
U x60
TPWM U out
sin sin120
With the two formulas, user will get the following results:
2U out
t1 TPWM sin(60 )
3U x
2U out
t2 TPWM sin
3U x60
When user knows the 2-phase adjacent basic space vectors U x and U x 60 , t1 and t 2 can be
confirmed by the formulas above. If the inverter outputs zero vector, the motor stator flux linkage
will not rotate. With this feature, it’s able to insert zero vector t 0 between TPWM and make
TPWM t1 t2 t0 . By doing so, user can adjust the angular frequency, the frequency can thus be
switched, and the motor torque ripple will be reduced.
PWM Period t1 t 2
tc
2
tb t c t1
t a tb t 2
if(Va>0) Sector = 1;
if(Vb>0) Sector += 2;
if(Vc>0) Sector += 4;
With the combination of Sector and t a , t b , t c , user can get the 3-phase PWM cycle value, as
shown in Table 2.2.
Sector 1 2 3 4 5 6
PWM_A tb ta ta tc tb tc
PWM_B ta tc tb tb tc ta
PWM_C tc tb tc ta ta tb
In Figure 2.10, if PWM switches to interval 2, MOS Q0, Q2 and Q4 are OFF and Q1, Q3 and Q5 are ON.
Since the motor is inductance, the motor current will not change immediately, which means it will
still be input from phase A and be output by phase B and C. User can convert the phase current at
interval 2.
3. GPM32F011xb Introduction
eCCU 6CLK
PWMCLK ………….. Formula (1)
eCCU 6 _ TMR _ CK _ SRC * eCCU 6 _ TMR _ PLOADS
When triangle wave is applied as carrier wave, PWM frequency is determined by Formula (2) below.
eCCU 6CLK
PWMCLK ……….. Formula (2)
eCCU 6 _ TMR _ CK _ SRC * eCCU 6 _ TMR _ PLOADS * 2
TMR_PLOADS
CCPm
CCPn
Time
eCCU6_PWMm
Time
eCCU6_PWMn
Time
TMR_PLOADS
CCPm
Time
eCCU6_PWMm
Time
eCCU6_PWMm+1
Time
TMR_PLOADS
CCPm
CCPn
Time
eCCU6_PWMm
Time
eCCU6_PWMn
Time
According to user’s needs, it’s able to configure the appropriate dead time to avoid upper and lower
MOS being turned on at the same time during the process of switching. If the value of
eCCU6_PWM_DTIMEx is not 0, dead time mode will be triggered, and the dead time is
DTR
T . If eCCU6_PWM_DTIMEx = 0, there won’t be any dead time.
eCCU 6 xCLK
TMR_PLOADS
CCPm
Time
eCCU6_PWMm
Time
DTIME_0 DTIME_1
eCCU6_PWMm+1
Time
To avoid high-side and low-side being turned on at the same time, the controller will configure the
high-side and low-side as complementary, which means the high-side will be turned on at high level,
the low-side will be turned on at low level, and vice versa. For various controller design,
GPM32F011xB provides register eCCU6_PWM_CTRL0 [21:16] for user to configure the polarity
setting of PWM output. With the configuration of eCCU6_PWM_CTRL0, it’s able to apply a
well-developed program application when user uses a different controller.
While using single shunt to sample 3-phase current, user has to shift PWM. GPM32F011xB provides
register eCCU6_PWM_CTRL0 [24] to configure PWM offset function. For PWM duty, not only register
eCCU6_CCPm but also eCCU6_CCPn has to be configured, as shown in Figure 3.5, and PWM will then
be shifted.
eCCU6_PLOADS
CCPm
CCPn
Time
eCCU6_PWMm
Time
eCCU6_PWMm+1
Time
The PWM of eCCU6 might happen due to OVC external trigger, and PWM may be turned off
immediately. It’s enabled by setting eCCU6_OVC_CTRL[9] as 1. Or user can set OVC as the trigger
source of the built-in comparator in register eCCU6_OVC_CTRL [13:12]. By doing so, the mechanism
of turning off PWM can also be triggered, and OVC interrupt will be issued as well.
For each channel, the sample & hold time can be configured respectively in ADCx_SMPx [31:0]. The
shortest configurable time is 1T (the suggested time is 10T), and the highest conversion frequency of
each data is shown as follows:
SYSCLK 92MHz
1.314MHz
ADCx _ CLK _ SEL * (SH _ time Conv _ time) 5 * (1 13)
ADC_START
ADC_CLK
ADC_RDY
DATA ADC_DATA
■ ADC Interrupt:
Injected and Regular interrupt is enabled by ADCx_INTE[11:8] and ADCx_INTE[0]. When ADC
conversion is completed, ADC transfer ready interrupt will be generated. Check the interrupt is
generated by Injected or Regular in ADCx_INTF[8:11] and ADCx_INTF[0], and writing 1 to
ADCx_INTFC[8:11] and ADCx_INTFC[0] will clear the flag. The converted data can be read in
ADCx_REG_DATA and ADCx_INJx_DATA.
Clock
DIV_STR
SFT_DIR “1”
SFT_CNT 0x00
DIVIDEND 0x08
DIVISOR 0x03
DIV_BUSY
DIV_INTF
QUOTIENT 0x02
REMAINDER 0x02
Q Format is to multiply a floating point with decimal by several times, make the floating point an
integer first and then continue the calculation. The sample program uses Q15 format as an example.
For a piece of 32bit data, the lowest 15bit is decimal, the highest 16th bit is integer, and the highest
bit is plus-minus sign. The range of the value is -65536<x<65535.999.
To transform a floating point to Q15 format, please multiply the data by 2^15. For example,
0.333*2^15=0x2A9F, the calculation of 0.333 will be present as 0x2A9F. Multiplying one Q15 format
by another Q15 format equals Q30. To obtain Q15 with the same format, user has to right-shift Q30
for 15bit. For Q Format calculation, please note that:
1. Fixed Point Addition/Subtraction: The data has to be transformed into the same Q format.
2. Fixed Point Multiplication: After user multiplies two identical Q formats, the bit of Q format has to
be right-shifted to generate the same format. The following example is Q15 multiplication of the
program: #define _IQmpy(A,B) ((long)A * (long)B)>>15.
Main Loop
eCCU6 Interrupt
OVC Interrupt
(PWM)
Reset
Init.c
OPA_Init();
ACMP_Init();
GPIO_Init();
Initial Chip DMA_Init();
ADC_Init();
eCCU6_PWM_Init();
POSIF0_HALL_Init();
Initial Variables
Main Loop
CAPTV=0 CPATV=Timer
65535
HALL_U
T_HALL
When the system just being started up or the rotational speed is fairly low, the HALL cycle cannot be
calculated accurately. In this situation, user can know the six angles from HALL signal, and the six
output states can be judged from the six angles.
ADC0->REG_SEQ0=ADC_REG_SEQ0_CH11;
ADC0->CTRL1 |= ADC_REG_EN | ADC_REG_CH_NUM1;
for(ADC0Sum=0,k=0; k<32; k++)
{
ADC0->CTRL0 |=ADC_SFT_STR;
while((ADC0->INTF & ADC_INTF_REG) != ADC_INTF_REG);
ADC0->INTFC = ADC_INTFC_REG;
ADC0Sum += ADC0->REG_DATA;
}
Ia_Offset = ADC0Sum>>5;
According to PWM switch state, when the 3 low-sides are on, ADC sample will be triggered to
measure the current of the two data, and the sample code is shown as follows. After ADC conversion
is completed, the measured current is the phase current. ADC0->INJ0_DATA is the ADC converted
data, and it’s in 16bit format. The result of ADC sample data minusing the offset value is Q15 format
data.
void foc(FOC*v)
{
■ CLARKE Coordinate Transform:
v->I_Alpha = v->I_As;
v->I_Beta = (_IQmpy(v->I_Bs,K_IQ1divsqrt3) << 1) + (_IQmpy(v->I_As,K_IQ1divsqrt3));
■ PARK Coordinate Transform:
v->I_Ds = (_IQmpy(v->I_Alpha,v->Cosine)) + (_IQmpy(v->I_Beta,v->Sine));
v->I_Qs = (_IQmpy(v->I_Beta,v->Cosine)) - (_IQmpy(v->I_Alpha,v->Sine));
■ Q Axis PI Control:
v->I_QsErr = v->I_QsRef - v->I_Qs;
v->V_QsUp = _IQmpy(v->I_QsKp,v->I_QsErr);
break;
case 2:
v->t1 = v->Vb;
v->t2 = -v->Va;
v->Ta = (K_IQ1 - v->t1 - v->t2)>>1;
v->Tc = v->Ta + v->t1;
v->Tb = v->Tc + v->t2;
break;
case 3:
v->t1 = -v->Vc;
v->t2 = v->Va;
v->Ta = (K_IQ1 - v->t1 - v->t2)>>1;
v->Tb = v->Ta + v->t1;
v->Tc = v->Tb + v->t2;
break;
case 4:
v->t1 = -v->Va;
v->t2 = v->Vc;
v->Tc = (K_IQ1 - v->t1 - v->t2)>>1;
v->Tb = v->Tc + v->t1;
v->Ta = v->Tb + v->t2;
break;
case 5:
v->t1 = v->Va;
v->t2 = -v->Vb;
v->Tb = (K_IQ1 - v->t1 - v->t2)>>1;
v->Tc = v->Tb + v->t1;
v->Ta = v->Tc + v->t2;
break;
case 6:
v->t1 = -v->Vb;
v->t2 = -v->Vc;
v->Tc = (K_IQ1 - v->t1 - v->t2)>>1;
v->Ta = v->Tc + v->t1;
v->Tb = v->Ta + v->t2;
break;
}
}
I_As pu
I_Bs pu
pu Ta
Sine pu
FOC pu Tb
Cosine pu pu Tc
I_QsRef pu
I_DsRef pu
The Library variable is operated in Q15 format. All the variables used by the Library form a struct FOC,
and a variable name has to be declared when user is going to use it. Variables in the struct are listed
as Table 4.1. Variable struct definition is in foc_v01.h file, and it includes the configurations of
controller parameters and so on.
_iq V_QsUp;
_iq V_QsUi;
_iq V_QsOutMax;
_iq V_QsOutMin;
_iq V_QsOut;
_iq I_DsRef;
_iq I_DsErr;
_iq I_DsKp;
_iq I_DsKi;
_iq V_DsUp;
_iq V_DsUi;
_iq V_DsOutMax;
_iq V_DsOutMin;
_iq V_DsOut;
_iq V_Alpha;
_iq V_Beta;
_iq Va;
_iq Vb;
_iq Vc;
_iq t1;
_iq t2;
_iq Ta;
_iq Tb;
_iq Tc;
_iq V_QsPreOut;
_iq V_DsPreOut;
_iq V_QsSatErr;
_iq V_DsSatErr;
_iq I_QsKc;
_iq I_DsKc;
unsigned char Sector;
unsigned char Closeloop;
}FOC;
void foc(FOC *v);
While using FOC Library, after the variables, 2-phase current (I_As and I_Bs), Sine, Cosine and DQ axis
current reference values (I_QsRef and I_DsRef), are input, user will get output 3-phase PWM duty
cycle Ta, Tb and Tc.
foc1.Cosine = Sine_Tab[cos_theta];
/************************FOC Library Calculation**************************/
foc(&foc1);
In developing process, if user doesn’t need PI control, please set the variable “Closeloop” as 0. The
program will make I_QsRef equal V_Qs and I_DsRef equal V_Ds. For developing experiment, please
refer to the following description of FOC library.
if(v->Closeloop == 0)
{
v->V_QsOut = v->I_QsRef;
v->V_DsOut = v->I_DsRef;
}
OVC IRQ
System
shoutdown
END