Home

Sensored PMSM field-oriented control software library

image

Contents

1. UM0312 Getting started with the library Linear variation of PID constants according to mechanical speed When the linear coefficient computation is enabled in speed closed loop see Figure 40 on page 73 the following set points must be fed with appropriate values coefficient computation is disabled by default in the library Refer to Section 5 2 2 Adjusting the speed regulation loop Ki Kp and Kd vs the motor frequency on page 72 define Freq Min Linear curve for speed control loop minimum frequency set point number 1 define Ki Fmin Linear curve for speed control loop integral coefficient gain set point number 1 define Kp Fmin Linear curve for speed control loop proportional coefficient gain set point number 1 define Kd Fmin Linear curve for speed control loop derivative coefficient gain set point number 1 define F 1 Linear curve for speed control loop intermediate frequency set point number 2 define Ki F 1 Linear curve for speed control loop integral coefficient gain set point number 2 define 1 Linear curve for speed control loop proportional coefficient gain set point number 2 define Kd F 1 Linear curve for speed control loop derivative coefficient gain set point number 2 define F 2 Linear curve for speed control loop intermediate frequency set point number 3 define Ki F 2 Linear curve for speed control loop integral coefficient
2. 66 PID general equation sus srsrisriunriansins uny Erua rES eee 70 Time domain to discrete PID lt 5 71 Speed regulation sampling time adjustment 75x TBtimer c 71 UM0312 List of figures Figure 40 Linear curve for coefficient 73 Figure 41 Speed regulation loop call in 75 _ 1 74 Figure 42 Torque flux control loop block 74 Figure 43 Speed control loop block diagram 75 Figure 44 Example of function call generating a MISRA rule 45 76 Figure 45 AD conversions for three shunt topology stator currents reading and PMSM FOC algorithm execution when REP RATE 3 79 Figure 46 FAD conversions for three shunt topology stator current readings and PMSM FOC algorithm execution when REP RATE21 sseeee e 80 r 9 84 Getting started with tools UM0312 1 1 1 2 10 84 Getting started with tools To develop an application for a PM sensored motor using the PMSM software library you must set up a complete development environment as described in the following sections A PC running Windows 2000 SP4 or Windows XP SP2 is necessar
3. 39 Case 1 Duty cycle applied to Phase A low side switch is larger than DT TN 2TS 40 Case 2 DT TN TS lt Phase A duty cycle lt DT TN 2TS 42 Case 3 Phase A pulse width lt 5 44 4 2 5 75x svpwm ICS module leen 48 SVPWM TtCSIDHIE l0 beta ended Perd se eh Eua DE x Rey Petes 48 SVPWM IcsCurrentReadingCalibration 49 SVPWM IcsGetPhaseCurrentValues 49 SVPWM IcsCalcDutyCycles 50 4 2 6 Isolated current sensor topology current sampling and general purpose GP A D conversions integration 50 4 2 7 MC Clarke Park h module 51 eius 52 Re eee as ee 6 Ps 53 REV Park ek Merk Bw Re SS ws geht 53 Rev Park Circle Limitation cesse 54 4 2 8 Detailed explanation about reference frame transformations 54 4 2 9 Circle limitation 56 Example max modulation index 95 58 4 2 10 75x_encoder c module 59 4 84 r UMO312 Contents ENC Init 59 ENC GetPosition 59 EN
4. 36 PWM frequency vs maximum duty cycle 47 MISRA compliance of PMSM library 77 System performance when using 750 81 Document revision history 2 94 4294 RR 83 7 84 List of figures UM0312 List of figures Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 Figure 6 Figure 7 Figure 8 Figure 9 Figure 10 Figure 11 Figure 12 Figure 13 Figure 14 Figure 15 Figure 16 Figure 17 Figure 18 Figure 19 Figure 20 Figure 21 Figure 22 Figure 23 Figure 24 Figure 25 Figure 26 Figure 27 Figure 28 Figure 29 Figure 30 Figure 31 Figure 32 Figure 33 Figure 34 Figure 35 Figure 36 Figure 37 Figure 38 Figure 39 8 84 JTAG interface for debugging and 10 Library structure for PMSM software library version 1 0 11 Linker file 14 FOC drive placed ina speed loop 15 PMSM FOC esiisa onei a ga aa tte nee 16 Alignment procedure 0 0 000 cece eee 18 Creating a new file 23 Adding a file to the workspace
5. Low side Phase A dA HN Current feedback of MR Phase B ee Current feedback of 270 start ils T Phase C e Sampling end On the contrary if ADutya p gt DT Ty Ts as shown in the red circle in Figure 24 Phase C conversion is performed between Phase B low side switch on and Phase A high side switch off see Figure 25 Figure 24 DT Ty Ts lt Low side Phase A duty cycle lt DT Ty 2Ts Ty Tpma and ADuty p gt DT Ty Ts 100 90 80 70 60 50 40 3096 2096 10 0 60 0 30 PhaseA Phase Phase r 43 84 Motor control library routines UM0312 Figure 25 DT Ty Ts lt Low side Phase A duty cycle lt DT Ty 2Ts T4 Tpma and ADuty _B gt DT Ty Ts 1 Low side Phase HighsiePhaseA M Low side Phase B D Current feedback of Current feedback of pr Phase C e Sampling end Case 3 Phase A pulse width DT TN TS In this case the duty cycle applied to Phase A is so short that no current sampling can be performed in between the two low side commutations Then if the difference of duty cycles between Phase B and A is long enough to allow two A D conversions to be performed between Phase B low side switch on and Phase A high side switch off the strategy shown in Figure 27 is used Figure 26 Low side duty cycle Phase lt DT Ty Ts a
6. 0 0 60 120 180 240 300 360 Phase A Phase Phase C Sector 1 Sector 2 Sector 3 Sector 4 Sector 5 Sector 6 35 84 Motor control library routines UM0312 With the following definitions for U T V U T V pera and X U _ U U 2 z U m 2 literature demonstrates that the space vector sector is identified by the conditions shown in Table 2 Table 2 Sector identification Y lt 0 Y gt 0 Z lt 0 Z gt 0 2 lt 0 2 gt 0 lt 0 lt 0 lt 0 X gt 0 Sector V IV The duration of the positive pulse widths for the PWM applied on Phase A B and C are respectively computed by the following relationships Sector IV T X Z Z te t Sector Il V T Y Z uc t t Z t t Y 36 84 UM0312 Motor control library routines 4 2 3 Sector III VI _T X Y NC E t t X t t Y Where T is the PWM period Now considering that the PWM pattern is center aligned and that the phase voltages must be centered to 50 of duty cycle it follows that the values to be loaded into the PWM output compare registers are given respectively by Sector IV fnit 4 2 TimePhB TimePhA Z TimePhC TimePhB X Sector Il V Tipe fee 4 2 TimePhB TimePhA Z TimePhC TimePhA Y Sector 11 TimePhA TE hTimePhB TimePhC X TimePhC TimePhA
7. aaa za GP Conversion Chain GP Conversion Chain y PWM Registers Update 4 2 7 MC Clarke Park h module This module is designed to perform transformations of electric quantities between frames of reference that rotate at different speeds Based on the arbitrary reference frame theory the module provides three functions named after two pioneers of electric machine analysis E Clarke and R H Park These functions implement three variable changes that are required to carry out field oriented control FOC e those required to carry out field oriented control FOC Clarke transforms stator currents to a stationary orthogonal reference frame named qd frame see Figure 32 e then from that arrangement Park transforms currents to a frame that rotates at an arbitrary speed which in PMSM FOC drive is synchronous with the rotor flux Reverse Park transformation brings back stator voltages from a rotating qd frame to a stationary one Ti 51 84 Motor control library routines UM0312 Figure 32 Clarke Park and Reverse Park transformations Clarke Park gt Va q Vg d Clarke Synopsis Curr Components Clarke Curr Components Curr Input Description This function transforms stator currents ias ips which are directed along axes each displaced by 120 degrees into currents i and ig in a stationary reference frame q d axes are directed along paths orthogonal to eac
8. define Id Iq DIFFERENTIAL TERM ENABLED To be uncommented when derivative terms for torque and flux control loop regulation PID are enabled uncommented by default define SPEED DIFFERENTIAL TERM ENABLED To be uncommented when the derivative term for speed control loop regulation PID is enabled uncommented by default Once these settings have been done only the required blocks will be linked in the project this means that you do not need to exclude any C source files from the build Caution When using shunt resistors for current measurement ensure that the REP RATE parameter in MC Control Param h is set properly see Section 2 2 4 and Section A 2 Selecting PWM frequency for 3 shunt resistor configuration on page 80 for details 2 2 2 Permanent magnet motor parameters MC PMSM motor param h file The MC PMSM motor param h header file holds motor parameters which are essential to properly operate the vector drive It provides the compiler with the number of pole pairs of the motor and with the alignment settings see Figure 6 The following parameters must be defined in all cases define POLE PAIR NUM Specify here the number of pole pairs of your motor For the SHINANO PM Sensored motor provided with the starter kit the default value is 2 e define T ALIGNMENT Define here the time in ms for the rotor alignment e define ALIGNMENT Define here the maximum current value at the end of the rotor a
9. UM0312 Y User manual STR750 Sensored PMSM field oriented control software library V1 0 Introduction The STR750 microcontroller comes with a dedicated set of peripherals designed for field oriented control FOC of both permanent magnet DC AC motors PMDC PMAC also called BLDC and AC induction motors It is delivered with two software libraries that allow you to develop applications to control these motors m The PMSM software library m The AC induction motor software library The complete library source files are delivered with the STR750 MCKIT and are also available for free on the ST website www stmcu com in the Support section Check this site for the latest version of the library This user manual describes the PMSM software library required to control a permanent magnet synchronous motor with an encoder and a sinewave drive open or closed loop The AC induction motor software library designed to control an AC induction motor in sinewave mode with sensors is described in the UM0324 User Manual The PMSM software library is composed of several C modules compatible with the IAR EWARM toolchain The functions are grouped into several families making this library an easy way to go through any PM sensored motor project development Used in conjunction with the STR750 MCKIT starter kit evaluation can be achieved in a very short time because the software library spares you the trouble of studying the MCU in detail Overal
10. 37 Vv 3 31V V Phase B S Phase C 4 e Sampling 1 e i Current feedback of Zw al Tai end Phase C nJ After the commutation of the Phase low side switch a blanking window equal to Ty is applied before starting conversion of phase C then at the end of the first conversion it is necessary to wait a period before starting the phase B conversion 41 84 Motor control library routines UM0312 42 84 Case 2 DT TN TS lt Phase A duty cycle lt DT TN 2TS TH TDMA In this case only one of the two conversions can be performed between the two Phase A low side commutations The other conversion is then synchronized depending on the difference of duty cycles between Phase B and A ADuty p In particular if ADutya p lt DT Ty Ts as shown in the red circle in Figure 22 the sampling of Phase C cannot be performed between Phase B low side switching on and Phase A high side switching off see Figure 23 Therefore Phase C current sampling is performed before Phase B high side commutation Figure 22 DT Ty Ts Low side Phase A duty cycle lt DT Ty 2Ts Ty Tpma and ADuty p lt DT Ty Ts 100 90 80 70 60 50 40 30 20 10 0 0 30 60 Phase A PhaseB Phase C UM0312 Motor control library routines Figure 23 DT Ty Ts lt Low side Phase A duty cycle lt DT Ty 2Ts T4 Tpma and ADuty p lt DT TytTs
11. No license express or implied by estoppel or otherwise to any intellectual property rights is granted under this document If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION OR INFRINGEMENT OF ANY PATENT COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE ST PRODUCTS ARE NOT RECOMMENDED AUTHORIZED OR WARRANTED FOR USE IN MILITARY AIR CRAFT SPACE LIFE SAVING OR LIFE SUSTAINING APPLICATIONS NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY DEATH OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE ST PRODUCTS WHICH ARE NOT SPECIFIED AS AUTOMOTIVE GRADE MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK Resale of ST products with provisions different from the statements and or technical featu
12. Figure 13 Encoder output signals counter operation forward jitter backward jitter forward Lx MS nu pm SE SURE 8 rsen eei EE E ENSE ea COUNTER up down up SEP LETT 1 91 In addition rotor angular velocity can be easily calculated as time derivative of angular position To set up the PMSM software library for use with an incremental encoder simply modify the MC encoder param h header files according to the indications given in Section 2 2 3 on page 18 However some extra care should be taken concerning what is considered to be the positive rolling direction Because of this and because of how the encoder output signals are wired to the microcontroller input pins it is possible to have a sign discrepancy between the real rolling direction and the direction that is read To avoid this kind of reading error you can apply the following procedure 1 You can correct it by simply swapping and rewiring the encoder output signals 2 If this isn t practical you can modify a software setting instead in the 75x encoder c file replace the code line TIM InitStructure TIM ICiPolarity IC1Polarity Rising with InitStructure TIM ICiPolarity IC1Polarity Falling 29 84 Running the demo program UM0312 3 5 3 6 Caution 30 84
13. Y Current sampling in three shunt topology and general purpose A D conversions The three currents l4 12 and 13 flowing through a three phase system follow the mathematical relation 14 lo 1g 0 For this reason to reconstruct the currents flowing through a generic three phase load it is sufficient to sample only two out of the three currents while the third one can be computed by using the above relation The flexibility of the STR750 A D converter trigger makes it possible to synchronize the two A D conversions needed for reconstructing the current flowing through the three phase AC induction motor at any given time along the PWM period To do this the control algorithm must have a full control of the A D converter peripheral 37 84 Motor control library routines UM0312 38 84 Furthermore you have the possibility to add any A D conversions required for your application hereafter referred to as general purpose conversions This section describes how this is achieved First of all the SVPwM_3Shunt Init function performs the synchronization between PWM and TIMO peripherals Figure 17 shows the two peripheral counters when REP_RATE 1 then the A D converter peripheral is configured so that it is triggered by the TIMO OC2 signal Figure 17 PWM and TIMO synchronization REP RATE 1 Synchronized start This way when the value of
14. e Resolution 1 2CF The equation below converts a fractional quantity q to fixed point representation n n floor q 22 common way to express the choice that has been made is the QI QF notation 81 84 Additional information UM0312 A 4 A 5 82 84 So if a variable is stored in q3 5 format it means that 3 bits are reserved for the magnitude 5 bits for the resolution the expressible range is from 4 to 3 96875 the resolution is 0 03125 the bit weighting is bit n 7 6 5 4 3 2 1 0 vue 4 2 3 we m we ine 132 This software library uses the PU Per Unit system to express current values They are always referred to a base quantity that is the maximum measurable current Imax which for the proposed hardware can be estimated approximately at Imax 0 6 Rehuynt 50 the per unit current value is obtained by dividing the physical value by that base 5 1 PU max In this way ip is always in the range from 1 to 1 Therefore the 41 15 format which ranges from 1 to 0 999969482421875 with a resolution of 0 000030517578125 is perfectly suitable taking care of the overflow value 1 1 21 and thus extensively used Thus the complete transformation equation from SI units is MAX ou fo Additional or up to date technical literature More information can be found on the ST website www stmcu com More specifically the latest doc
15. 23 Key function 5 0 24 e State Machines uk Re Reed ERs on soe oce 25 Closed loop start up 5 27 ICS hardware 28 Encoder output signals counter 29 DBGC bit in PWM control register from STR750 reference 30 Vo and VB stator voltage components 35 SVPWM phase voltage waveforms 35 PWM and TIMO synchronization _ 1 38 Three shunt topology current sampling and GP A D conversions integration BEP aa hee erem RUIN sad bad ap d de oe td 39 Inverter leg and shunt resistor 5 39 Low side switches gate signals low modulation 41 Low side Phase A duty cycle gt DT TN 2TS 41 DT TN TS lt Low side Phase A duty cycle DT TN 2TS TH TDMA and ADutyA B lt DT TN4 TS po seran cipek 42 DT TN TS lt Low side Phase A duty cycle lt 2 5 and ADU tyA B D T4 TNG S i audere d
16. ENC_Get_Speed Synopsis Description Input Output Functions called Caution ENC Get Average Speed Synopsis Description Input Output Functions called Note Caution s16 ENC Get Speed void This function returns the rotor speed in Hz The value returned is given with 0 1Hz resolution which means that 1234 is equal to 123 4 Hz None Signed 16 bits None This routine returns the mechanical frequency of the rotor To find the electrical speed use the following conversion electrical frequency number of pole pairs mechanical frequency s16 ENC Get Average Speed void This function returns the average rotor speed in Hz The value returned is given with 0 1Hz resolution which means that 1234 is equal to 123 4 Hz None Signed 16 bits ENC Get Speed The averaging is done with the values stored in Speed Buffer The size of this buffer is set through the SPEED BUFFER SIZE statement which must be equal to a power of 2 to allow the use of the shift operation for divisions This routine returns the mechanical frequency of the rotor To find the electrical speed use the following conversion electrical frequency mechanical frequency number of pole pairs TIMx UP IRQHandler interrupt routine Synopsis Description Functions called Caution See also void TIMx UP IRQHandler void This is the encoder timer TIMER 0 1 or 2 update routine An interruption is generated whenever an ove
17. Once you have selected the required PWM switching frequency you should uncomment the Max Modulation Index definition corresponding to the selected PWM frequency as shown in Chapter 2 2 4 Drive control parameters Control Param h file on page 18 For information on selecting the PWM switching frequency you will find advice in Section A 2 on page 80 To determine the max modulation index corresponding to the PWM switching frequency refer to Table 3 on page 47 The following section provides an example of how the limitation is performed by the firmware 57 84 Motor control library routines UM0312 Example max modulation index of 95 For a MMI of 95 the Max module value is 95 S16_MAX 31128 as per the MAX MODULE value stored in MC Clarke Park h The Figure 35 shows the firmware implementation working principle minimizing the CPU load look up table access and shift operation for division The table circle limit table stores a maximum of 81 values generated from the circle limitation xls file located in the Design tools folder Access is as follows Figure 35 Example with Iq 32000 Id 5000 Module 142 Id greater than MaxModule 311282 _ ey 512 x 32768 Iq Ig x circle limit tapfe 62 5 INDEX 32768 Id Id x circle limit ta amp le 62 START INDEX 32768 i Defined in MC_Clarke_Park h Return new Iq and Id values Note that
18. The STR750 FOC Firmware Libraries v1 0 folder contains the firmware libraries for running both PMSM and AC induction three phase sensored motors The Stdlib folder contains the standard library for the STR750 It provides standard routines for the configuration of the STR750 peripherals This library is described in the STR75x Software Library User Manual UM0218 The Include folder contains all the standard library header files function prototypes global variables compiler directives The Source folder contains all library C source files and dedicated routines for the control of a permanent magnet motor with an encoder These functions are described in this manual in Section 4 Motor control library routines on page 31 The IAR folder contains the configuration file for the IAR C toolchain kickstart evaluation or standard edition 11 84 Getting started with tools UM0312 1 3 3 1 4 1 4 1 12 84 Starting the IAR toolchain When you have installed the toolchain you can open the workspace directly from the dedicated folder by double clicking on the PMSM Sensored eww file The file location is FOC_PMSM_SR_v1 0 Sensored eww Customizing the workspace for your STR75x device The library described in this manual was written for the STR750FVT2 However it works equally successfully with all the products in the STR75x family Using a STR750 sales type different from the STR750FVT2 may require
19. When using two ICS for stator current reading you must ensure that the sensors output voltage range is compatible with the STR750 supply voltage Connecting the two ICS sensors to the motor and to STR750 In order for the implemented PMSM FOC algorithm to work properly it is necessary to ensure that the software implementation of the 75x svpwm ICS module and the hardware connections of the two ICS are consistent As illustrated in Figure 12 the two ICS must act as transducers on motor phase currents coming out of the inverter legs driven by STR750 PWM signals PWM1 Phase A and PWMe Phase B In particular the current coming out of inverter Phase A must be read by an ICS whose output has to be sent to the analog channel specified by the PHASE A CHANNEL parameter in MC ics prm h Likewise the current coming out 27 84 Running the demo program UM0312 3 3 2 28 84 of inverter Phase B must be read by the other ICS and its output has to be sent to the analog channel specified by the PHASE CHANNEL parameter in MC_pwm_ics_prm h About the positive current direction convention a positive half wave on PHASE X CHANNEL is expected corresponding to a positive half wave on the current coming out of the related inverter leg see direction of in Figure 12 Figure 12 ICS hardware connections Phase A Phase B V To PHASE A CHANNEL To PHASE B CHANNEL Selecting PHASE A CHANNEL and PHASE B CHANNEL
20. internal external flash or RAM based project 12 1 4 2 Extended linker file setting 13 2 Getting started with the library 15 2 1 FOC drive quick introduction 15 2 2 Pre checks and library configuration 16 2 2 1 Library configuration file 75 _ 16 2 2 2 Permanent magnet motor parameters MC_PMSM_motor_param h jS cm 17 2 2 8 Encoder parameters MC ENCODER param hfile 18 2 2 4 Drive control parameters MC Control Param hfile 18 Maximum modulation index 19 Power device control 19 Flux and torque PID regulators sampling rate 19 Speed regulation loop frequency 19 Speed controller setpoint and PID constants initial values 20 Torque and flux controller setpoints and PID constants 20 Linear variation of PID constants according to mechanical speed 21 2 3 Running your own motor 22 2 4 Closed loop operation and PID settings 22 2 5 How to define and add a module 22 3 Running the demo program 24 3 1 LCD display
21. 15 format as members of the variable Volt Input which is a structure of type Volt Components Stator voltages v and vg in q1 15 format as members of a structure of type Volt Components None mul q15 415 q31 53 84 Motor control library routines UM0312 Rev_Park Circle Limitation 4 2 8 54 84 Synopsis Description Input Returns Caution Functions called void RevPark_Circle_Limitation void After the two new values Vg and VQ of the stator voltage producing flux and torque components of the stator current have been independently computed by flux and torque PIDs it is necessary to saturate the magnitude of the resulting vector equal to Va V passing before them to the SVPWM block The purpose of this routine is to perform the saturation Refer to Section 4 2 9 Circle limitation on page 56 for more detailed information None None The limitation of the stator voltage vector must be done in accordance with the PWM frequency as shown in Table 3 PWM frequency vs maximum duty cycle on page 47 None Detailed explanation about reference frame transformations By making a change of variables that refers stator and rotor quantities to a frame of reference rotating at any angular velocity it is possible to reduce the complexity of the system electrical equations This strategy is often referred to as the Reference Frame theory 1 Supposing fax fbx fox are three phase instantaneous qu
22. Default settings for PHASE CHANNEL and PHASE B CHANNEL are respectively ADC_CHANNEL11 and ADC_CHANNEL10 You can change the default settings if the hardware requires it by editing the ics prm h file However there are a few rules to follow when selecting the new ADC channels e You must initialize the proper GPIOs as analog inputs an example for channel 8 is given below ADC Channel 8 pin configuration GPIO InitStructure GPIO Mode GPIO Mode AIN GPIO InitStructure GPIO Pin GPIO Pin 29 GPIO Init GPIO0 amp GPIO InitStructure You must select two contiguous channels for example CHANNEL8 and ADC_CHANNEL9 and the one with the highest number must be associated with PHASE A CHANNEL for example PHASE A CHANNEL gt CHANNELS PHASE B CHANNEL ADC CHANNELB UM0312 Running the demo program 3 4 Managing the incremental encoder Quadrature incremental encoders are widely used to read the rotor position of electric machines As the name implies incremental encoders actually read angular displacements with respect to an initial position if that position is known then rotor absolute angle is known too Quadrature encoders have two output signals represented in Figure 13 as and TI2 With these and with the STR750 standard timer in encoder interface mode it is possible to get information about rolling direction
23. Fault messages This section provides a list of possible fault message that can be displayed on the LCD when using the software library together with the STR750MC KIT e Over Current An Emergency Stop was detected on the PWM peripheral dedicated pin If using STR750 MCKIT it could mean that either the hardware over temperature protection or the hardware over current protection were triggered Refer to the STR750 MCKIT User Manual for details e Over Heating An over temperature was detected on the dedicated analog channel the digital threshold NTC THRESHOLD and the relative hysteresis NTC HYSTERESIS are specified in the MC Misc c source file Refer to the STR750 MCKIT User Manual for details e Bus Over Voltage An over voltage was detected on the dedicated analog channel The digital threshold OVERVOLTAGE_THRESHOLD is specified in the MC Misc c source file Refer to the STR750 MCKIT User Manual for details e Bus Under Voltage The bus voltage is below 20V DC The threshold is specified in the MC Misc c source file UNDERVOLTAGE THRESHOLD parameter The corresponding FAULT flag is not cleared by firmware therefore the STR750 must be reset after the bus voltage has been switched on Note on debugging tools The third party JTAG interface should always be isolated from the application using the MB535 JTAG opto isolation board it provides protection for both the JTAG interface and
24. Get Electrical Angle void Description This function returns the electrical angle in signed 16 bit format This routine returns 0 for 0 degrees 32768 S16 MIN for 180 degrees 432767 S16 MAX for 180 degrees Input None Output Signed 16 bits Functions called None 174 59 84 Motor control library routines UM0312 ENC Get Mechanical Angle Synopsis 516 ENC Get Electrical Angle void Description This function returns the mechanical angle in signed 16 bit format This routine returns 0 for 0 degrees 32768 S16 MIN for 180 degrees 432767 516 MAX for 180 degrees Input None Output Signed 16 bits Functions called None Caution Link between Electrical Mechanical frequency RPM Electrical frequency number of pair poles x mechanical frequency RPM speed 60 x Mechanical frequency RPM revolutions per minute example electrical frequency 100 Hz motor with 8 pair poles 100Hz electrical lt gt 100 8 12 5Hz mechanical lt gt 12 5 x 60 750 RPM ENC_ResetEncoder Synopsis void ENC_resetEncoder void Description This function resets the encoder timer hardware register value to zero Functions called ResetCounter See also STR750 datasheet synchronizable standard timer ENC Clear Speed Buffer Synopsis void ENC Clear Speed Buffer void Description This function resets the buffer used for speed averaging Functions called None 60 84 UM0312 Motor control library routines
25. Param h file see Section 2 2 4 page 18 Figure 42 on page 74 shows the PID block diagram Chapter 5 PID regulator implementation and tuning on page 70 67 84 Motor control library routines UM0312 PID Speed_Regulator Synopsis Description Input Output Functions called Note See also PID Reset Integral terms Synopsis Description 516 Speed regulator PID SpeedTYPEDEF PID Speed 516 speed The purpose of this function is to compute the proportional integral and derivative terms if enabled see SPEED DIFFERENTIAL TERM ENABLED in section 2 2 1 on page 16 for the speed regulation PID SpeedTYPDEF see MC type h for structure declaration signed 16 bits signed 16 bits None Default values for the PID speed regulation are declared and can be modified in the MC Control Param h file see Section 2 2 4 on page 18 Figure 43 on page 75 shows the PID block diagram Chapter 5 PID regulator implementation and tuning on page 70 void PID Reset Integral terms void The purpose of this function is to reset all the integral terms of the torque flux and speed PID regulators PID Speed Coefficients update Synopsis Description Functions called Note void PID Speed coefficients update s16 motor speed This function automatically computes the proportional integral and derivative gain for the speed PID regulator according to the actual motor speed The computation is done
26. containing your code in the toolchain workspace To do this simply right click in the workspace folder then choose the Add Files sub menu The new file is automatically added to the workspace and taken into account for the compilation of the whole project The procedure of adding the module to the project is very easy with the IAR Embedded Workbench as the makefile and linking command files are automatically generated When rebuilding the library the configuration files are updated accordingly Figure 8 Adding a file to the workspace IAR Embedded Workbench IDE File Edit view Project Tools Window Help D gt gt 7 File Name Author E PMSensored Date First Issuec LL E i E cam poseription Files m 75x co Options I 75x en IDDDDDDDPPPPPPPPPI I E 5x History L 8 5x MC creati B 75x MC Feb 2 ok with 75 B 75x sv Bh 5x sv THE PRESENT SOFTU BEN DE 7 E MH E MC Ck Add main c I MC co emove Add Group ES MC Source Code Control 7779 2 ce m MC Source Code Control gt INFORMATION CONT ur Di m MC Standard include IE Br IL nclude 75x lib k 23 84 Running the demo program UM0312 3 24 84 Running the demo program This secti
27. define Ki Fmin 1000 Frequency min coefficient settings define Kp Fmin 2000 define Kd Fmin 3000 Settings for intermediate frequency 1 define F 1 50 5 Hz mechanical define Ki F 1 2000 Intermediate frequency 1 coefficient settings define Kp F 1 1000 define Kd F 1 2500 Settings for intermediate frequency 2 define F 2 200 20 Hz mechanical define Ki F 2 1000 Intermediate frequency 2 coefficient settings define Kp F 2 750 define Kd F 2 1200 Settings for max frequency define Freq Max 500 50 Hz mechanical define Ki Fmax 500 Frequency max coefficient settings define Kp Fmax 500 define Kd Fmax 500 UM0312 PID regulator implementation and tuning 5 3 Once the motor is running integer proportional and derivative coefficients are computed following a linear curve between F min and F_1 F_1 and F_2 F_2 and F max see Figure 40 Note that F_min F_1 F_2 F_max are mechanical frequencies with 0 1 Hz resolution for example F 1 1234 means F_1 123 4Hz Figure 40 Linear curve for coefficient computation Ki Kp Kd ib m cues uius cum ERES E ce Ki Fmax Kp Fmax Kd Fmax 1 Ki Fmin Kp Fmin Kd Fmin j Rotor mechanical F min F 1 F2 F max frequency Disabling the linear curve computation routine 75x it c module If you want to disable the linear curve computation you must comment ou
28. following a linear curve based on 4 set points See Section 5 2 2 on page 72 for more information None Default values for the four set points are declared and can be modified in the MC Control Param h file see Section 2 2 4 on page 18 PID Integral Speed update Synopsis Description 68 84 void PID Integral Speed update s32 value The purpose of this function is to load the speed integral term with a default value 1574 UM0312 Motor control library routines 4 3 4 3 1 4 3 2 4 3 3 4 3 4 4 3 5 4 3 6 Application layer The application layer is split into several modules mainly for the control of the keys LCD display temperature and bus voltage monitoring and main loop The following is a brief description of these modules main c module This module contains the initialization and the main control loop of the overall firmware MC Keys c module The purpose of the MC Keys c module is to centralize all information regarding the keyboard reading Any action on the keyboard is processed in the Keys process routine MC Display c module The purpose of the MC Display c module is to centralize all information regarding the LCD display management 75x LCD c module This module contains some dedicated routines for the control of the LCD embedded with the starter kit MC dac c module This module contains some dedicated routines for the control of an external digital to analog D
29. gain set point number 3 define Kp F 2 Linear curve for speed control loop proportional coefficient gain set point number 3 define Kd F 2 Linear curve for speed control loop derivative coefficient gain set point number 3 define Freq Max Linear curve for speed control loop maximum frequency set point number 4 define Ki Fmax Linear curve for speed control loop integral coefficient gain set point number 4 define Kp Fmax Linear curve for speed control loop proportional coefficient gain set point number 4 define Kd Fmax Linear curve for speed control loop derivative coefficient gain set point number 4 21 84 Getting started with the library UM0312 2 3 2 4 2 5 22 84 Running your own motor As a starting point the open loop mode should be used for the first trials fixed speed Ki Kp and Kd coefficients are applied Low current alignment values should be used also and then increased smoothly step by step Sufficient alignment time should be applied in order to avoid any oscillations while resetting the encoder timer at the end of the ramp see I ALIGNMENT and T ALIGNMENT settings in Section 2 2 2 Permanent magnet motor parameters PMSM motor param h file on page 17 Closed loop operation and PID settings To run a motor in standalone closed loop the first step should be to run the system with fixed PID speed parameters and modify them while the motor is running
30. in OPEN loop mode 25 3 2 LCD display in CLOSED loop mode 26 3 3 Setting up the system when using ICS 27 3 84 Contents UM0312 3 3 1 Connecting the two ICS sensors to the motor and to STR750 27 3 3 2 Selecting PHASE A CHANNEL and PHASE B CHANNEL 28 3 4 Managing the incremental encoder 29 3 5 Fault Messages 32e 0sPb222155sedXcue cari LS eS eee 30 3 6 Note on debugging tools 30 4 Motor control library routines 31 4 1 Library reference 31 4 2 Motor control software layer 31 4 2 1 75x svpwm 3shunt module 31 SVPWM 3Sh nt INTE a Rue nsn dde eed E e Sen 32 SVPWM 3ShuntCurrentReadingCalibration 33 SVPWM 3ShuntGetPhaseCurrentValues 33 SVPWM 3ShuntCalcDutyCycles 34 SVPWM 3ShuntGPADCConfig 34 4 2 2 Space vector PWM 35 4 2 3 Current sampling in three shunt topology and general purpose A D conversions 37 4 2 4 Tuning delay parameters and sampling stator currents in three shunt
31. max modulation index define MAX MODULATION 92 PER CENT 92 max modulation i gt gt index Power device control parameters define PWM FREQ PWM switching frequency The value must be expressed in Hz default 14000 14Khz define DEADTIME NS Define here in ns the dead time in order to avoid shoot through conditions Flux and torque PID regulators sampling rate define REP RATE Value to be fed into the repetition counter of the synchronizable PWM timer peripheral The value default 1 is 8 bit long and provides the period frequency for current sampling and regulation For more information refer to the STR750 Datasheet Synchronizable Standard Timer Repetition Counter Register section 2 PWM FREQ _ 1 Flux and torque PIDs sampling rate In fact because there is no reason for either executing the PMSM FOC algorithm without updating the stator currents values or for performing stator current conversions without running the PMSM FOC algorithm in the proposed implementation the stator current sampling frequency and the PMSM FOC algorithm execution rate coincide HEP RATE must be an odd number if currents are measured by shunt resistors see Section A 2 Selecting PWM frequency for 3 shunt resistor configuration on page 80 for details its value is 8 bit long Speed regulation loo
32. setpoint and PID constants see page 20 Torque and flux controller setpoints and PID constants see page 20 Linear variation of PID constants according to mechanical speed see page 21 UM0312 Getting started with the library Note Maximum modulation index The maximum modulation index for space vector PWM modulation guarantees a maximum limit to the PWM duty cycle output to the power stage in order to sample the current in the 3 phases correctly This value depends on both the PWM switching frequency and the time required to compute the PID control loop for torque and flux regulation Only one definition out of the 9 declared must be uncommented Refer to Section 4 2 9 Circle limitation on page 56 for explanations on maximum modulation index DEFINE ONLY ONE max modulation index in the following list define MAX MODULATION 100 PER CENT 100 max modulation index tdefine MAX MODU 99 PER CENT 99 max modulation index tdefine MAX 98 PER CENT 98 max modulation index tdefine MAX 97 PER CENT 97 max modulation index define MAX MODULATION 96 PER CENT 96 max modulation index tdefine MAX 95 PER CENT 95 max modulation index m m m J z define MAX MODU ION 94 PER CENT 94 max modulation index define MAX MODU 93 PER CENT 93
33. some modifications to the library according to the available features some of the I O ports are not present on low pin count packages Refer to the datasheet for details Depending on the memory size the workspace may have to be configured to suit your STR75x MCU Table 1 Device summary Features STR755FRx STR751FRx STR752FRx STR755FVx STR750FVx Flash Bank bytes 64K 128K 256K Flash Bank 1 bytes 16K RWW RAM bytes 16K Operating Temp 40 to 85 C 40 to 105 C see Table 41 UARTs 2 SSPs 1 IFC 2 UARTs 2 SSPs 1 I2C 3 timers 1 PWM timer timers 1 PWM timer 72 Common Peripherals 38 I Os 13 Wake up lines 11 A D Channels l Os 15 Wake up lines 16 A D Channels USB CAN peripherals None USB CAN None USB CAN Operating Voltage 3 3V or 5V 3 3V 3 3V or 5V T LQFP100 14x14 Packages x T LQFP64 10x10 H LFBGA64 H LFBGA100 Inkarm_xxx xcl file internal external flash or RAM based project The IAR config folder contains 3 files e Inkarm flash xcl e Inkarm smi xcl e Inkarm ram xcl These files are used as an extended command linker file and contain linker options Memory areas start address size and other parameters are declared here It also contains the value assigned to the stack size for each ARM operating mode for example USER or FIQ Refer to the ARM7TDMI S Technical Reference Manual for more information 1574 UM0312 Getting started with too
34. the PC connected to it During a breakpoint when using the JTAG interface for the firmware development the motor control cell clock circuitry should always be enabled if disabled a permanent DC current may flow in the motor because the PWM outputs are enabled which could cause permanent damage to the power stage and or motor A dedicated bit in the PwM CR control register the DBGC bit must be set to 1 see Figure 14 Figure 14 bit in PWM control register from STR750 reference manual Control Register CR Address Offset 00h Reset value 0000h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 CNT_ CNT DBASE DBGC MMS res CMS U D opm En Ger UFS nw nw nrw nw nw nw rw nw nw nw rw rw DBGC Debug Control Bit 10 SeeSection 9 5 3 Debug mode on page 186 for a detailed description The timer is stopped in debug mode 1 The timer continues working in debug mode UM0312 Motor control library routines 4 4 1 4 2 4 2 1 Motor control library routines Library reference Functions are described in the format given below Synopsis Lists the referenced include files and prototype declarations Description Describes the functions specifically with a brief explanation of how they are executed Input Gives the format and units Returns Gives the value returned by the function including when an input value is out of range or an error code is r
35. the IAR workspace is provided by default with the internal flash extended linker file Inkarm_flash xcl modify the workspace to use a different file 1 Open the IAR workspace by double clicking on the PMSM SR 1 0 IAR PMSM Sensored eww file 2 Go to the Project menu select Options then Linker and select the Config sub menu The dialog box shown in Figure 315 displayed 3 Inthe Linker command file section tick the Override default checkbox select the linker file you want to use and then click OK 13 84 Getting started with tools UM0312 14 84 Figure 3 Linker file selection Category General Options C C Compiler Assembler Custom Build Build Actions Debugger Simulator Angel IAR ROM monitor J Link J Trace LMI FTDI Macraigor RDI Third Party Driver Options for node 5 Sensored Extra Output define Diagnostics List Factory Settings Config Processing E 4 gt Linker command file ommand file configuration tool Override default program entry Entry label C Defined by app on Search paths one per line binary image File Symbol Segment Align es ees Cancel UM0312 Getting started with the library 2 2 1 Getting started with the library PMSM FOC drive quick introduction The PMSM software library is designed to achieve the high d
36. the TIMO counter matches the value contained in the OCR2 register the first A D conversion for current sampling is started Meanwhile a DMA transaction reloads the TIMO OCR2 register with the value corresponding to the delay required for the second current sampling conversion Moreover the end of this first A D conversion triggers another DMA transaction which sets the next channel to be converted in the ADC register CLR2 At the end of the second conversion the three phase load current has been updated and the PMSM FOC algorithm can then be executed in the A D End of Conversion Interrupt Service Routine EOC ISR In this routine the A D converter is also reconfigured so that it can perform the general purpose chain of conversions while the CPU executes the PMSM FOC algorithm The entire process is illustrated in Figure 18 After execution of the PMSM FOC algorithm the A D converter is configured to perform the next PWM period three phase current sensing delays and channels This allows to reduce the CPU load lower number of ADC ISR To specify the general purpose conversions to be performed you can select the first channel and the number of channels to be converted by editing the GP CONVERSIONS FIRST CHANNEL and GP CONVERSIONS NUMBER parameters respectively in the MC 3shunt prm h header file UM0312 Motor control library routines 4 2 4 Figure 18 Three shunt topology current sampling and G
37. 4 4kHz 98 96 15 2kHz 97 5 95 16kHz 97 94 16 7kHz 96 596 93 17 5kHz 96 92 Note The figures above were measured using the MB459 motor control board This evaluation platform is designed to support several motor driving topologies PMSM and AC induction and current reading strategies single and three shunt resistors Therefore the figures provided in Table 3 should be understood as a starting point and not as a best case 47 84 Motor control library routines UM0312 4 2 5 You can further increase the maximum applicable duty when using your own hardware system by editing the following definitions in the MC pwm 3shunt prm h header file define HOLD TIME 2 67usec 1 60MHz units define DMA TIME Ox2A 0 7usec define SAMPLING TIME 0x60 1 6usec define TNOISE 0x96 2 55usec define TRISE 0x96 2 6usec 75x svpwm ICS module Two important tasks are performed in the 75x svpwm ICS module Space vector pulse width modulation SVPWM e Ihree phase current reading when two isolated current sensors ICS are used In order to reconstruct the currents flowing through a three phase load with the required accuracy using two ICS it is necessary to properly synchronize A D conversions with the generated PWM signals Two tasks are included in a single software module SVPWM IcsInit 48 84 Synopsis void SVPWM_IcsInit void Description The purpo
38. AC device AD7303 MC misc c module This module contains some dedicated routines for monitoring the temperature of the power stage and the bus voltage 69 84 PID regulator implementation and tuning UM0312 5 5 1 Note 5 2 70 84 PID regulator implementation and tuning The regulators implemented for Torque Flux and Speed are actually Proportional Integral Derivative PID regulators see note below regarding the derivative term PID regulator theory and tuning methods are subjects which have been extensively discussed in technical literature Section 5 1 provides a basic reminder of the theory Theoretical background The purpose of such regulators is to maintain a level of torque flux or speed according to a desired target Figure 37 PID general equation torque f rotor position ll torque and flux regulation for maximum flux f rotor position p system efficiency 1 torque regulation for speed regulation J ofthe system torque f rotor speed Where Error sys Error of the system observed at time t T ErrOfsys _ Error of the system observed at time t T Tsampling x Error sys Kix YErrorsys Errors ErrOfsys 0 C A Derivative term can be disabled Equation 1 corresponds to a classical PID implementation where is the proportional coefficient integral coefficient Kis the differential coefficient As m
39. C Get Electrical Angle 59 ENC Get Mechanical Angle 60 ENC ResetEncoder 60 ENC Clear Speed Buffer 60 ENC Get Speed 61 ENC Get Average Speed 61 TIMx UP IROHandler interrupt routine 61 4 2 11 75x TBTimer cemodule 222 v had pated dhe ee ue ew 62 TB Timebase Timer Init 62 TB Wait 62 TB Set Delay 500us 62 TB Delay IsElapsed 63 TB Set DisplayDelay 500us 63 TB Set DebounceDelay 500us 63 TB DebounceDelay 1 63 TB IROHandler 64 42 12 75x It e Mod le il bebe he ERI Ee PURA ERR dor 65 PWM EM IROHandler 65 ADC IRQHandler 65 42 43 MC_PID_regulators c 66 PID Init 66 PID Flux Regulator 67 PID Torque Regulator 67 PID Speed Regulator 68 PID Reset Integral terms 68 PID Speed Coefficients update 68 PID Integral Speed update 68 4 3 Application 69 4 3 1 main module iti ci 4 ae vei Eie Ree ui ur 69 4 3 2 Me Keys c module E ea t a ae aw Re ede eg 69 4 3 3 MC Display module xd ER ed Ey 69 4 3 4 75x 69 4 3 5 MC dac c 69 4 3 6 MC misec Mod le wees end Rel Redes ead the deca eee EE 69 5 PID regulator implementation and tuning 70 5 1 Theoretical background 70 5 2 Regulation sampling time 70
40. P A D conversions integration REP_RATE 1 TIMO OC2 signal TIMO counter EOC Interrupt yt d A D 2nd TIMO OCR2 value Conversion conversion conversions ADMA 4st TIMO OCR2 value Tuning delay parameters and sampling stator currents in three shunt resistor topology Figure 19 shows one of the three inverter legs with the related shunt resistor Figure 19 Inverter leg and shunt resistor position To indirectly measure the phase current 1 it is possible to read the voltage V providing that the current flows through the shunt resistor R It is possible to demonstrate that whatever the direction of current l it always flows through the resistor R if transistor T2 is switched on and T1 is switched off This implies that in order to properly reconstruct the current flowing through one of the inverter legs it is necessary to properly synchronize the conversion start with the generated PWM signals This also means that current reading cannot be performed on a phase where the duty cycle applied to the low side transistor is either null or very short 39 84 Motor control library routines UM0312 Note 40 84 Fortunately as discussed in Section 4 2 3 to reconstruct the currents flowing through a generic three phase load it is sufficient to simultaneously sample only two out of three currents the third one being computed from the relation giv
41. TR750 standard library function call See Section 6 2 Limitations on page 76 MISRA rule 45 non compliance due to 75x svpwm ics c STR750 standard library function call See Section 6 2 Limitations on page 76 MISRA rule 45 non compliance due to 75x svpwm ics h STR750 standard library function call See Section 6 2 Limitations on page 76 MISRA rule 45 non compliance due to Main c STR750 standard library function call See Section 6 2 Limitations on page 76 MISRA rule 45 non compliance due to 75x encoder c STR750 standard library function call See Section 6 2 Limitations on page 76 75x encoder h Yes 77 84 MISRA compliance UM0312 78 84 Table 4 MISRA compliance of PMSM library files MISRA Module name Deviation compliant MISRA rule 45 non compliance due to 75x Xt c STR750 standard library function call See Section 6 2 Limitations on page 76 MISRA rule 45 non compliance due to 75x lcd c STR750 standard library function call See Section 6 2 Limitations on page 76 75x lcd h Yes MISRA rule 45 non compliance due to MC Keys c STR750 standard library function call See Section 6 2 Limitations on page 76 MC Keys h Yes MISRA rule 45 non compliance due to MC Misc c STR750 standard library function call See Section 6 2 Limitations on page 76 MC Misc h Yes MISRA rule 45 non compliance due to MC DAC c STR750 standard library funct
42. a tech Rec e Ll sc CREARE eke le 43 DT TN TS lt Low side Phase A duty cycle lt DT TN 2TS TH TDMA and ADutyA B gt DT TN TS 2 ers 43 DT TN TS lt Low side Phase duty cycle lt 2 5 and ADutyA B gt DT TN TS gt 44 Low side duty cycle Phase A DT TN TS and ADutyA B gt 2 5 44 Low side duty cycle Phase A lt DT TN TS and ADutyA B gt 2 5 45 Figure 31 Low side duty cycle Phase A lt DT TN TS and DT TRise TS lt ADutyA B lt 2 5 45 Low side duty cycle Phase A lt DT TN TS and DT TRise TS lt ADutyA B lt 2 5 46 Low side duty cycle Phase A DT TN TS and DutyA B DT TRise TS 47 Stator currents sampling and GP conversions in ICS configuration REP_RATE 1 51 Clarke Park and Reverse Park 52 Transformation from an abc stationary frame to a qd rotating frame 55 Circle limitation working principle 57 Example with Iq 32000 ld 2 5000 0 0 58 ADC interrupt request 5 51 0
43. antities directed along axis each displaced by 120 degrees where x can be replaced with s or r to treat stator or rotor quantities see Figure 33 supposing fqx fax fox are their transformations directed along paths orthogonal to each other the equations of transformation to a reference frame rotating at an arbitrary angular velocity can be expressed as cos cos 0 2 cos 0477 fo ja 2 fa 900 sin pe sin jest 3 3 3 Jos 1 1 1 Cot 2 2 2 where 0 is the angular displacement of the q d reference frame at the time of observation and 09 that displacement at t 0 see Figure 33 UM0312 Motor control library routines Figure 33 Transformation from an abc stationary frame to a qd rotating frame With Clark s transformation stator currents ias and ibs which are directed along axes each displaced by 120 degrees are resolved into currents i and i on a stationary qd reference frame Appropriate substitution into the general equations given above yields ly las lg V3 In Park s change of variables stator currents and ips which belong to a stationary qd reference frame are resolved to a rotor flux synchronous reference frame properly oriented so as to obtain ig and igs Consequently with this choice of reference thus 14 ij i cos t i sin 7 i sin 0 1 cos On the other hand reverse Park transformation takes back stator voltage v an
44. aram h header file Figure 45 shows current sampling triggering and PMSM FOC algorithm execution with respect to PWM period when REP RATE is set to 3 Figure 45 conversions for three shunt topology stator currents reading and PMSM FOC algorithm execution when REP RATE 3 PWM counter LA pc p A N A N EN rdi id Pa p PWM Period FOC algorithm execution execution TIMO counter S ibt 2hd ibt 2nd ADC aet CA FOC algorithm 1 l Note Because three shunt resistor topology requires low side switches to be on when performing current reading A D conversions the REP RATE parameter must be an odd number in this case ky 79 84 Additional information UM0312 A 2 Note 80 84 Considering that the raw FOC algorithm execution time is about 25 7us when in three shunt resistor stator current reading configuration the related contribution to CPU load can be computed as follows FPwM REPRATE 1 2 Few 6 RefreshRate 25 7x10 x 100 CPU oad x 25 7x10 100 Selecting PWM frequency for 3 shunt resistor configuration Beyond the well known trade off between acoustical noise and power dissipation consideration should be given to selecting the PWM switching frequency using the PMSM software library As
45. ark PID Torque Regulator PID Flux Regulator RevPark Circle Limitation Rev Park SVPWM_3ShuntCalcDutyCycles ENC_ResetEncoder SVPWM_3ShuntGPADCConfig SVPWM 3ShuntGetPhaseCurrentValues Isolated current sensors ICS configuration Clarke Park PID Torque Regulator PID Flux Regulator RevPark Circle Limitation Rev Park SVPWM IcsCalcDutyCycles ENC ResetEncoder SVPWM JlIcsGetPhaseCurrentValues Note This is an interrupt routine See also STR750 datasheet synchronizable PWM timer 174 65 84 Motor control library routines UM0312 Figure 36 ADC interrupt request processing End of alignment State RUN Reset encoder timer State START Ramp up increase Flux component _ ADC interrupt request State RUN Retrieve 3 phase current Clarke transformation Park transformation Torque regulation Flux regulation Circle limitation Reverse park transformation Space vector PWM generation No Return from interrupt 4 2 13 PID Init Synopsis Description Functions called Note 66 84 MC PID regulators c module void PID Init void The purpose of this function is to initialize the PID for torque flux and speed regulation For each one a set of default values are loaded target speed torque or flux proportional integral and derivative gains lower and upper limiting values for the output None Default va
46. c Close Workspace Author MCD Application Team Date First Issued xx xx xx Description i This file contains the software implementation for the Save Al TIM software library verification ee EFELELELELELELELLELELELELELELELEEFELELELELELELSEEFELELELSELSLSESELELELELELSLEAFALSE Page Setup History xx XX XX creation Feb 2 ok with 75 pwm c version 19 and 75x pwm h version 14 Recent Files hdd dd hdd Recent Workspaces THE PRESENT SOFIWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS Exit WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIM T armoa AS A RESULT SIMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT H BMC consth INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE B MC Contr CONTENT OF SUCH SOFIWARE AND OR THE USE MADE BY CUSTOMERS OF THE CODING B MC dach INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS BMCD ddiiiiidiiddddidididdiiididddididdd4A44444A4444ddd4ddddddddddddddddddidddddddidddddd44 ispl 18 Standard _ ___ ___ _ _ _ _ ___ _____ __ ____ I BMC enco esta BMC Glob include x lib n include stdio h BMC Keysh BMC Misch B MC PID r Include of other module interface headers t 2 Declare the new file
47. configuration The REP RATE value can only be an odd number 8 bit value e A multiple of half of the PWM switching period in isolated current sensor configuration The REP RATE value can be any number 8 bit value The torque flux regulation sampling time adjustment is defined as follows in the MC Control Param h file define REP RATE 1 N b Internal current loop is performed every REP RATE 1 2 PWM FREQ seconds REP RATE has to be an odd number in case of three shunt current reading this limitation doesn t apply to ICS Adjusting the speed regulation loop Ki Kp and Kd vs the motor frequency Depending on the motor frequency it might be necessary to use different values of and Kg These values have to be input in the code to feed the regulation loop algorithm A function performing linear interpolation between four set points PID Speed Coefficient update is provided as an example in the software library see MC PID regulators c and can be used in most cases as long as the coefficient values can be linearized If that is not possible a function with a larger number of set points or a look up table may be necessary To enter the four set points once the data are collected edit the Control param h file and fill in the field dedicated to the Ki Kp and Kd coefficient calculation as shown below Settings for min frequency define Freq Min 10 1 Hz mechanical
48. d vq belonging to a rotor flux synchronous rotating frame to a stationary reference frame so as to obtain va and vg Va 7 Sin O v cos O Vg v COSO v Sin 55 84 Motor control library routines UM0312 4 2 9 Note 56 84 Circle limitation As discussed above FOC allows to separately control the torque and the flux of a 3 phase permanent magnet motor After the two new values V and V of the stator voltage producing flux and torque components of the stator current have been independently computed by flux and torque PIDs it is necessary to saturate the magnitude of the resulting vector yV before passing them to the SVPWM block The saturation boundary is normally given by the value 516 MAX 32767 which produces the maximum output voltage magnitude corresponding to a duty cycle going from 096 to 100 Nevertheless when using three shunt resistor configuration and depending on PWM frequency it might be necessary to limit the maximum PWM duty cycle to guarantee the proper functioning of the stator currents reading block For this reason the saturation boundary could be a value slightly lower than 516 MAX depending on PWM switching frequency when using three shunt resistor configuration Table 3 on page 47 repeated below for convenience shows the maximum applicable modulation index as a function of PWM switching frequency when using the STR750 MCKIT PWM
49. discussed in Section 4 2 4 on page 39 depending on the PWM switching frequency a limitation on the maximum applicable duty cycle could occur if using three shunt resistor configuration for current reading Table 3 PWM frequency vs maximum duty cycle on page 47 summarizes the performance of the system when the software library is used in conjunction with the STR750 MCKIT hardware The MB459 board is an evaluation platform it is designed to support different motor driving topologies PMSM and AC induction and current reading strategies single and three shunt resistors Therefore the figures given in Table 3 on page 47 should be understood as a starting point and not as a best case Moreover to keep the synchronization between TIMO and PWM peripherals it is always necessary to finish executing the PMSM FOC algorithm before the next PWM period begins as shown in Figure 46 Figure 46 FAD conversions for three shunt topology stator current readings and PMSM FOC algorithm execution when REP RATE 1 PWM counter gt Je A d a 2 d j ie a d o e t Tl wa B EN rd PWM P riod FOC algorithm FOC algorithm execution executioni abt ist 20 TIMO counter ADC ADC ant abe E D 4 UM0312 Additional information Given t
50. e values the delay for the two current samplings are computed see Section 4 2 4 on page 39 Refer to Section 4 2 2 for information on the theoretical approach of SVPWM Input V and Vg Returns None Caution None Functions called None SVPWM 3ShuntGPADCConfig 34 84 Synopsis void SVPWM 3ShuntGPADCConfig void Description The purpose of this function is to configure the A D converter for general purpose conversions after conversions for current reading have been performed In particular this function starts a chain of regular conversions whose first channel is GP CONVERSIONS FIRST CHANNEL defined in MC pwm 3shunt prm h In addition the number of channels to be converted is set equal to GP CONVERSIONS NUMBER defined in MC_pwm_3shunt_prm h Input None Returns None Caution As mentioned in Section 4 2 2 the overall duration of the regular chain conversion must be lower than the duration of the PMSM FOC routines Clarke Park Reverse Park and SVPWM generation Functions called None UM0312 Motor control library routines 4 2 2 Space vector PWM implementation Figure 15 shows the stator voltage components Va and Vg while Figure 16 illustrates the corresponding PWM for each of the six space vector sectors Figure 15 V and Vj stator voltage components Vbeta Valfa Figure 16 SVPWM phase voltage waveforms 100 90 80 70 60 50 40 30 20 10
51. e regulation sampling time In theory the higher the sampling rate the better the regulation In practice you must keep in mind that The related CPU load will grow accordingly e Forspeed regulation there is absolutely no need to have a sampling time lower than the refresh rate of the speed information fed back by the external sensors this becomes especially true when all sensors are used while driving the motor at low to medium speed e Athigh speed in most cases system inertia is such that the system response is slow in these conditions there is no need to have a high sampling rate The speed regulation loop sampling time must be set in the 75x TBtimer c file Time Base timer interrupt routine Note that the sampling time is actually a multiple of the period of the Timebase timer interrupt update routine 500 uS by default This is an 8 bit value 255 max Figure 39 Speed regulation sampling time adjustment in 75x TBtimer c void TB IRQHandler void if DPID Speed Sampling Time 500us 0 bPID Speed Sampling Time 500us else bPID Speed Sampling Time 500 5 PID SPEED SAMPLING E 174 71 84 PID regulator implementation and tuning UM0312 5 2 2 72 84 For the torque and flux regulation loop sampling time the PID SPEED SAMPLING parameter must be set in the MC Control Param h file Note that the sampling time is e A multiple of the PWM switching period in three shunt
52. e the wTimebase 500us static variable Input Unsigned 16 bits Output None Functions called None 62 84 UM0312 Motor control library routines TB Delay IsElapsed Synopsis bool TB Delay IsElapsed void Description This function returns TRUE if wTimebase 500us variable has reached 0 else FALSE Input None Output Boolean TB Set DisplayDelay 500us Synopsis void TB Set DisplayDelay 500us u16 hDelay Description This function is used to update the wTimebase display 500us static variable Input Unsigned 16 bits Output None TB Set DebounceDelay 500us Synopsis void TB Set DebounceDelay 500us u16 hDelay Description This function is used to update the wKey debounce 500us static variable Input Unsigned 16 bits Output None TB DebounceDelay IsElapsed Synopsis bool DebounceDelay IsElapsed void Description This function returns TRUE if wKey debounce 500us variable has reached 0 else FALSE Input None Output Boolean 63 84 Motor control library routines UM0312 TB IRQHandler 64 84 Synopsis Description Input Output Functions called Note See also void TB IRQHandler void This is the Timebase timer interrupt routine This peripheral is configured to produce an interruption every 500us thus providing a general purpose timebase allowing the refresh of various variables used mainly as counters for example PID sampling time None None ENC Get Avera
53. e to the fact the STR750 standard library routines rely on base address pointer parameters e g pointer to a hardware register memory address that are then re casted as the first address of a structure inside the function call as shown in the example in Figure 44 Figure 44 Example of function call generating a MISRA rule 45 error declared in module 75x tim c Pointer to TIMER1 peripheral of standard library register base address Ed TIM ResetCounter TIM1 75x tim c module void TIM ResetCounter TIM TypeDef TIMx Pointer to TIMER peripheral base address is passed T the base address of the TypeDef structure UM0312 MISRA compliance 6 3 MISRA compliance for PMSM library files Table 4 MISRA compliance of PMSM library files Module name MISRA Deviation compliant MC_Clarke_Park h Yes MC_RevPark h Yes MC qmath h Yes MC const c Yes MC const h Yes MC type h Yes 75x TBTimer c Yes 75x TBTimer h Yes MC Globals c Yes MC Globals h Yes MC Display c Yes MC Display h Yes MC PMSM motor param h Yes 75x MClib h Yes MC Control Param h Yes 75x conf h Yes 75x MCconf h Yes MC encoder param h Yes MISRA rule 45 non compliance due to 75x svpwm 3shunt c STR750 standard library function call See Section 6 2 Limitations on page 76 MISRA rule 45 non compliance due to 75x svpwm 3shunt h S
54. egral Ki x Slip Error Integral term frozen If enabl Gas ei Differential Kd x Error Speed S important Previous Error Speed note in section 2 2 1 Output Proportional 2 8 Integral 2 14 Differential terms 2 8 Is Output lt lower lir or PI D upper limit Clamp Output value to unsigned PI D lower limit PI D upper limit Set Saturated Output Flag Reset Saturated Output Flag return Output value signed 16 bit 75 84 MISRA compliance UM0312 6 6 1 6 2 76 84 MISRA compliance Based on the The Motor Industry Software Reliability Association s Guidelines for the Use of the C Language in Vehicle Based Software the purpose of this section is to provide a report of any MISRA deviation in the version 1 0 of the library modules Analysis method The software library was checked for MISRA compliance using the IAR Embedded Workbench toolchain The IAR Systems implementation is based on version 1 of the MISRA C rules dated April 1998 Limitations Compliance tests were performed on required MISRA rules only and not on advisory rules Due to the extensive use of the STR750 standard library which itself is not fully MISRA compliant as of September 2006 the interaction through function calls for example between the standard library and PMSM library modules necessarily induces non compliances The main reason is du
55. en in Section 4 2 3 Thus depending on the space vector sector the A D conversion of voltage V will be performed only on the two phases where the duty cycles applied to the low side switches are the highest In particular by looking at Figure 16 you can deduct that in sectors 1 and 6 the voltage on the Phase A shunt resistor can be discarded likewise in sectors 2 and 3 for Phase B and finally in sectors 4 and 5 for Phase C Moreover in order to properly synchronize the two stator current reading A D conversions it is necessary to distinguish between the different situations that can occur depending on PWM frequency and applied duty cycles The explanations below refer to space vector sector 1 They can be applied in the same manner to the other sectors Case 1 Duty cycle applied to Phase A low side switch is larger than DT Ty 2Ts Ty TpMA Where DT is dead time Ty is the duration of the noise induced on the shunt resistor voltage of a phase by the commutation of a switch belonging to another phase Tsisthe sampling time of the STR750 A D converter Refer to the STR750 reference manual for more detailed information Tgisthe holding time of the STR750 A D converter Refer to the STR750 reference manual for more detailed information Tpma the time required for the DMA to load the value related to the next conversion delay in TIMO OCR2 refer to Section 4 2 3 Current sampling in three shunt topology and
56. entioned in Figure 37 the derivative term of the PID can be disabled independently through a compiler option see 75x MCcon f Rh file for the torque flux or the speed regulation a PI can then be quickly implemented whenever the system doesn t require a PID control algorithm Regulation sampling time The sampling time needs to be modified to adjust the regulation bandwidth As an accumulative term the integral term is used in the algorithm increasing the loop time decreases its effects accumulation is slower and the integral action on the output is delayed Inversely decreasing the loop time increases its effects accumulation is faster and the integral action on the output is increased This is why this parameter has to be adjusted prior to setting up any coefficient of the PID regulator In order to keep the CPU load as low as possible and as shown in equation 1 in Figure 37 the sampling time is directly part of the integral coefficient thus avoiding an extra 1577 UM0312 PID regulator implementation and tuning multiplication Figure 38 describes the link between the time domain and the discrete system Figure 38 Time domain to discrete PID equations Time domain f t Ky x Error s t Kix J p Errors s dt S Errors 0 T Discrete Discrete Kyx Error y Error Error 0 sampling done at Fs 1 Ts frequency kx To 5 2 1 Adjusting th
57. eturned Note Indicates the limits of the function or specific requirements that must be taken into account before implementation Caution Indicates important points that must be taken into account to prevent hardware failures Functions called Lists called functions Useful to prevent conflicts due to the simultaneous use of resources Code example Indicates the proper way to use the function and if there are certain prerequisites interrupt enabled etc Some of these sections may not be included if not applicable for example no parameters or obvious use Motor control software layer The software related to motor control is part of several modules These modules provide Basic setup Control routines Related interrupt handling routines Current sampling for torque and flux regulation Speed acquisition for closed loop operation 75x svpwm 3shunt module Two important tasks are performed in the 75x svpwm 3shunt module Space vector pulse width modulation SVPWM e Three shunt resistor topology current reading In order to reconstruct the currents flowing through a three phase load with the required accuracy using three shunt resistors it is necessary to properly synchronize A D conversions with the generated PWM signals 31 84 Motor control library routines UM0312 SVPWM 3ShuntInit 32 84 Synopsis Description Input Returns Caution Functions called void SVPWM 3Shuntlnit void The purp
58. frequency Max duty cycle Max modulation index MMI Up to 11 4kHz 10096 10096 12 2kHz 99 5 99 12 9kHz 99 98 13 7kHz 98 5 97 14 4kHz 98 96 15 2kHz 97 5 95 16kHz 97 94 16 7kHz 96 596 93 17 5kHz 96 92 The figures above were measured using the MB459 board This evaluation platform is designed to support several motor driving topologies PMSM and AC induction and current reading strategies single and three shunt resistors Therefore the figures provided in should be understood as a starting point and not as a best case The RevPark_Circle_Limitation function performs the discussed stator voltage components saturation as illustrated in Figure 34 UM0312 Motor control library routines Figure 34 Circle limitation working principle V V2 V2 2 MMI S16 MAX P V and V represent the saturated stator voltage component to be passed to the SVPWM block From geometrical considerations it is possible to draw the following relationship des V 516 MAX d IV V V MMI S16 MAX q V IV In order to speed up the computation of the above equations while keeping an adequate resolution the value MMI S16 IV is computed and stored in a look up table for different values of V Furthermore considering that MMI depends on the selected PWM frequency a look up table is stored in MC Clarke Park h with MMI ranging from 92 to 100
59. ge Speed PID Speed Regulator TB ClearFlag This is an interrupt routine STR750 datasheet timebase timer UM0312 Motor control library routines 4 2 12 75x it c module PWM EM IRQHandler Synopsis void PWM EM IROHandler void Description The purpose of this function is to refresh the wGlobal_Flags and State variables upon detection of a signal on the dedicated emergency pin Functions called PWM ClearFlag PWM ITConfig Note This is an interrupt routine See also STR750 datasheet synchronizable PWM timer ADC IRQHandler Synopsis void IRQHandler void Description The purpose of this function is to handle the ADC interrupt request All the PMSM FOC algorithm is processed in this interrupt routine Triggered by ADC ECH JECH ISR the function loads stator currents read by ICS or shunt resistors and carries out Clark and Park transformations converting them to igs and jq see Figure 5 Then these currents are fed to PID regulators together with reference values and ig The regulator output voltages vgs and vgs then must be transformed back to a stator frame through Reverse Park conversion and finally drive the power stage In order to correctly perform Park and Reverse Park transformation it is essential to accurately estimate the rotor flux position 9 this is done by calling the Get Electrical Angle routine Functions called 3 shunts configuration Clarke P
60. general purpose A D conversions on page 37 for further details This case typically occurs when SVPWM with low lt 60 modulation index is generated see Figure 20 The modulation index is the applied phase voltage magnitude expressed as a percentage of the maximum applicable phase voltage the duty cycle ranges from 0 to 100 Figure 21 offers a reconstruction of the PWM signals applied to low side switches of Phase A and B in these conditions plus a view of the analog voltages measured on the STR750 A D converter pins for both Phase B and C the time base is lower than the PWM period UM0312 Motor control library routines Figure 20 Low side switches gate signals low modulation indexes 100 90 80 70 60 50 40 30 20 10 0 0 30 60 Phase A Phase Phase Note that these current feedbacks are constant in the view in Figure 27 because it is assumed that commutations on Phase B and C have occurred out of the visualized time window Moreover it can be observed that in this case the two stator current sampling conversions can be performed between the two commutations of the Phase A low side switch as shown in Figure 21 Figure 21 Low side Phase A duty cycle gt DT Ty 2Ts Ty Toma Low side Phase A D High side Phase A i Est Low side Phase B Phase B i convession High side Phase B Pd T Ts T i rei Current feedback of
61. h other See Section 4 2 8 for the details Input Stator currents ias and ips in q1 15 format as members of the variable Curr Input which is a structure of type Curr Components Returns Stator currents and ig in q1 15 format as members of a structure of type Curr Components Functions called q15 415 q31 52 84 ky UM0312 Motor control library routines Park Rev_Park Synopsis Description Input Returns Functions called Synopsis Description Input Returns Caution Functions called Curr Components Park Curr Components Curr Input s16 Theta The purpose of this function is to transform stator currents and ig which belong to a stationary qd reference frame to a rotor flux synchronous reference frame properly oriented so as to obtain ig and igg See Section 4 2 8 for the details Stator currents and ig in q1 15 format as members of the variable Curr_Input which is a structure of type Curr_Components rotor flux angle 65536 pulses per revolution Stator currents and igs in q1 15 format as members of a structure of type Curr Components mul q15 415 q31 Volt Components Rev Park Volt Components Volt Input This function transforms stator voltage vg and vg belonging to a rotor flux synchronous rotating frame to a stationary reference frame so as to obtain va and vg See Section 4 2 8 for the details Stator voltages vas and Vas 91
62. hat the raw execution time of the PMSM FOC algorithm is around 25 7 5 and that other delays such as the time necessary to enter ADC ISR have to be considered this limits to about 14 4 kHz the maximum PMSM FOC algorithm execution rate when using REP_RATE 1 However no limitations occur in the typical range of PWM frequencies when using REP_RATE 3 The following table summarizes the performance of the system for different PWM frequencies Table 5 System performance when using STR750 MCKIT PWM frequency Max applicable duty cycle Max FOC algorithm execution rate Up to 11 4kHz 100 12 2kHz 99 5 12 9kHz 99 Equal to PWM frequency 13 7kHz 98 596 14 4kHz 98 15 2kHz 97 5 16kHz 97 Equal to PWM frequency 2 16 7kHz 96 5 REP_RATE 3 17 5kHz 96 A 3 Fixed point numerical representation The PMSM software library uses fixed point representation of fractional signed values Thus a number nis expressed as n mf where mis the integer part magnitude and fthe fractional part and both m and fhave fixed numbers of digits In terms of two s complement binary representation if a variable n requires QI bits to express as powers of two its magnitude of which 1 bit is needed for the sign QF bits as inverse powers of two for its fractional part then we have to allocate QI QF bits for that variable Therefore given a choice of QI and QF the variable representation has the following features e Range 2 0 n lt 2498 OF
63. in order to define a working range linear coefficient computation disabled see Disabling the linear curve computation routine 75x it c module on page 73 The second step is for a given target mechanical speed to fine tune all the PID speed parameters most adequate for this speed For each target speed these values should be recorded in the form of a table which will be used by the STR750 standalone firmware You should collect data for 4 speeds the min and max speeds and 2 intermediate speeds of your choice The STR750 firmware will then make a linear extrapolation of these parameters between the 4 specified speeds to ensure smooth operation linear coefficient computation enabled see Figure 40 on page 73 How to define and add a module This section explains how you can create your own library modules to enhance the functionalities offered by the PMSM software library 1 Create a new file You can either copy and paste an existing file and rename it or in the File menu choose New then click the File icon and save it in the right format c h extension as shown in Figure 7 UM0312 Getting started with the library Figure 7 Creating a new file Z IAR Embedded Workbench IDE dit View Project Tools Window Help OS 059600205 BUD Open Workspace k E EL 7 fi5554444444444444445 C COPYRIGHT 2004 STMicroelectronics 44444444444444444444 Save Workspace File Name main
64. ing the JTAG interface of the MCU you can enter in circuit debugging sessions with most toolchains Each toolchain can be provided with an interface connected between the PC and the target application Figure 1 JTAG interface for debugging and programming JTAG D E interface STR750 Application board The JTAG interface can also be used for in circuit programming of the MCU Other production programmers can be obtained from third parties UM0312 Getting started with tools 1 3 Library source code 1 3 1 Download The complete library source files are available for free download on the ST web site www stmcu com in the Support section Note It is highly recommended to check for the latest releases of the library before starting any new development and then to verify from time to time all release notes to be aware of any new features that might be of interest for your project Registration mechanisms are available on ST web sites to automatically obtain updates 1 3 2 File structure The PMSM software library contains the workspace for the IAR toolchain Once the download files are unzipped the following library structure appears as shown in Figure 2 Figure 2 Library structure for PMSM software library version 1 0 STR750 FOC Firmware Libraries v1 0 V StdLib v1 0 IAR Debug Release Settings config Include Source FOC_AC_SR_v1 0 Vass
65. ion call See Section 6 2 Limitations on page 76 MC DAC h Yes UMO0312 Additional information Appendix A Additional information A 1 Adjusting CPU load related to PMSM FOC algorithm execution The Synchronizable PWM Timer peripheral has the built in capability of updating PWM registers only after a given number of PWM semi periods This feature is handled by a programmable repetition counter It is particularly useful to adjust the CPU load related to PMSM FCC algorithm execution for a given PWM frequency refer to STR750 Reference Manual for more information on programmable repetition counter When using ICS the injected chain of conversions for current reading is directly triggered by a PWM register update event Moreover since the PMSM FOC algorithm is executed at the end of the injected chain of conversions in the related ISR changing the repetition counter has a direct impact on PMSM FOC refresh rate and thus on CPU load However in the case of three shunt topology current reading to ensure that the PMSM FOC algorithm is executed once for each PWM register update it is necessary to keep the synchronization between current conversions triggering and PWM signal In the proposed software library this is automatically performed so that you can reduce the frequency of execution of the PMSM FOC algorithm by simply changing the default value of the repetition counter the REP RATE parameter the MC Control P
66. l software architecture The figure below shows the architecture of the firmware It uses the STR750 Standard Library extensively but it also acts directly on hardware peripherals when optimizations in terms of execution speed or code size are required APPLICATION LAYER i STR750 7 orque PIDs Sd User Speed Current Library Interface feedback feedback SN Motor Control Library 1 GPIO TB TIM ADC DMA PWM Peripherals February 2007 Rev 1 1 84 www st com UM0312 Note 2 84 PMSM software library 1 0 features CPU running at 60MHz m Permanent magnet motor with encoder Open loop operation Closed loop operation PID regulation with 0 5ms to 127ms sampling time m Current sampling method 2isolated current sensors 3 shunt resistors Current regulation for torque and flux control PIDs sampling time adjustable up to the PWM frequency 16 bit space vector PWM generation frequencies PWM frequency can be manually adjusted Centered PWM pattern type 11 bit resolution at 14 6kHz Free C source code and spreadsheet for look up tables e Motor control modules developed in accordance with MISRA C rules These figures are for information only this software library may be subject to changes depending on the final application and peripheral resource
67. lied before the control board MB469B This way the current sensing conditioning network can reach steady state before performing calibration Standard Library ADC GetFlagStatus ConversionCmd GetConversionValue SVPWM IcsGetPhaseCurrentValues Synopsis Description Input Returns Caution Functions called Curr Components SVPWM_IcsGetPhaseCurrentValues void This function computes current values of Phase A and Phase B in q15 format from the values acquired from the A D converter None Curr Components type variable In order to have a 41 15 format for the current values the digital value corresponding to the offset must be subtracted when reading phase current A D converted values Thus the function must be called after SVPWM lIcsCurrentReadingCalibration None 49 84 Motor control library routines UM0312 SVPWM_IcsCalcDutyCycles 4 2 6 50 84 Synopsis void SVPWM_IcsCalcDutyCycles Volt Components Stat_Volt_Input Description After execution of the PMSM FOC algorithm new stator voltages component Va and Vg are computed The purpose of this function is to calculate exactly the three duty cycles to be applied to motor phases from the values of these voltage components Refer to Section 4 2 2 for details about the theoretical approach of SVPWM and its implementation Input Va and Vg Returns None Caution None Functions called None Isolated current sensor topology current sa
68. lignment the value is hardware dependent 17 84 Getting started with the library UM0312 2 2 3 2 2 4 18 84 Figure 6 Alignment procedure Stator Current Reset of encoder timer 1 ALIGNMENT p 0 T ALIGNMENT Time ms After the alignment procedure a reset of the encoder timer is done in order to record the 0 degree rotor angle reference Encoder parameters MC ENCODER param h file The purpose of this header file is to provide the compiler with the encoder parameters define TIMERO HANDLES TACHO To be uncommented if the encoder outputs are connected to the TIMERO input define TIMER1 HANDLES TACHO To uncommented if the encoder outputs are connected to the TIMER 1 input define TIMER2 HANDLES TACHO To be uncommented if the encoder outputs are connected to the TIMER2 input This is the default setting when using the STR750 MCKIT define ENCODER PPR This statement contains the number of pulses per revolution of the motor encoder For the SHINANO PM Sensored motor provided with the starter kit the default value is 400 Drive control parameters MC Control Param h file The MC Control Param h header file gathers parameters related to Maximum modulation index see page 19 Power device control parameters see page 19 Flux and torque PID regulators sampling rate see page 19 Speed regulation loop frequency see page 19 Speed controller
69. ls 1 4 2 The default extended linker file used in the standard library to configure the device for internal flash based resident firmware is Inkarm_flash xc1 An extract of this file showing the definitions of heap and stack size is provided below Depending on the project requirements it may be necessary to manually edit the segment sizes Embedded Flash 256 128 64Kbytes The user has to change the flash memory length depending STR75xFxx devices Code memory in flash DROMSTART 0x20000000 DROMEND 0x2003FFFF 0x2001FFFF 0x200FFFF Data memory DRAMSTART 0x40000000 DRAMEND 0x40003FFF f 8k ke e ke kk cese e e e e ke e he heck EE EERE KEKE he e kc kc kc kkk kkk Stack and heap segments f kk ke e heck ke cese e se e he ke e he he sk kk EER cce ce ke ke ke he e kk e ke kkk kk kkk kc kc EEE EERE RE k k k RRR kc kc kk k kk k k Add size 0 for ABT Stack UND Stack if you need them size must be 8 byte aligned D CSTACK SIZE 0x200 D SVC STACK SIZE 0x20 D IRQ STACK SIZE D STACK SIZE 0x40 D ABT STACK SIZE D UND STACK SIZE 0x0 D HEAP SIZE 0x400 Memory size modifications must be done according to the MCU specifications Default settings are done for a 256Kb embedded flash memory Depending on the project requirements stack and heap segment size might also need to be changed Extended linker file setting As mentioned in the previous section
70. lues for PID regulators are declared and can be modified in MC Control Param h file see Section on page 19 UM0312 Motor control library routines PID Flux Regulator Synopsis Description Input Output Functions called Note See also PID Torque Regulator Synopsis Description Input Output Functions called Note See also s16 PID Flux regulator PID FluxTYPEDEF PID Flux s16 gld input The purpose of this function is to compute the proportional integral and derivative terms if enabled see Id Ig DIFFERENTIAL TERM ENABLED in Section 2 2 1 on page 16 for the flux regulation PID FluxTYPDEF see MC type h for structure declaration signed 16 bits Signed 16 bits None Default values for the PID flux regulation are declared and can be modified in the MC Control Param h file see Section 2 2 4 on page 18 Figure 42 on page 74 shows the PID block diagram Chapter 5 PID regulator implementation and tuning on page 70 516 PID Torque regulator PID TorqueTYPEDEF Torque S16 glq input The purpose of this function is to compute the proportional integral and derivative terms if enabled see Id Ig DIFFERENTIAL TERM ENABLED in Section 2 2 1 page 16 for the torque regulation TorqueTYPDEF see MC type h for structure declaration signed 16 bits signed 16 bits None Default values for the PID torque regulation are declared and can be modified in the MC Control
71. lux regulator target selection torque is Iq 02000 00000 automatically adjusted by the speed PID Id 00000 00000 Measured torque op right and flux bottom UM0312 Running the demo program 3 3 Caution 3 3 1 In closed loop only the torque reference is the output of the speed PID regulator Although you cannot act directly on the torque reference you can set the flux reference and also observe both the measured flux and torque components varying the flux reference can help to increase the motor speed while the system efficiency decreases also known as field weakening As in open loop pressing the joystick or the KEY button will start the motor The speed PID regulator is enabled and takes control of the torque reference right after the linear ramp up alignment process as shown in Figure 17 Figure 11 Closed loop start up strategy Stator Current Closed loop enabled Alignment F4 ALIGNMENT PI D current reference pam crm gt 0 T ALIGNMENT Time ms Setting up the system when using ICS sensors The default configuration provides for the use of three shunt resistors Section 3 3 1 describes how to change the firmware configuration from three shunt resistors to two ICS stator current reading This section gives you information about how to provide the STR750 with ICS feedback signals and to customize the firmware to use a different hardware
72. mpling and general purpose GP A D conversions integration The three currents l4 12 and l5 flowing through a three phase system follow the mathematical relationship 14 lo 1g 0 Therefore to reconstruct the currents flowing through a generic three phase load it is sufficient to sample only two out of the three currents while the third one can be computed by using the above relationship The flexibility of the STR750 A D converter trigger makes it possible to synchronize the two A D conversions necessary for reconstructing the stator currents flowing through the three phase AC induction motor with the PWM registers update whose rate is also adjusted by the repetition counter This is important because as shown in Figure 37 it is precisely during counter overflow and underflow that the average level of current is equal to the sampled current Refer to the STR750 Reference Manual to learn more about A D conversion triggering and the repetition counter Finally at the end of the injected chain conversion for current reading the general purpose A D conversions are performed while the CPU executes the PMSM FOC algorithm UM0312 Motor control library routines Figure 31 Stator currents sampling and GP conversions in ICS configuration REP_RATE 1 PWM Counter I _ Low side A ie ee T l verage current
73. nd gt DT Tyt2Tst Tyt Tpma 100 0 30 60 Phase Phase Phase 44 84 ky UM0312 Motor control library routines Otherwise if the difference of duty cycles between Phase B and A is long enough to allow only one A D conversion to be performed between Phase B low side switch on and Phase A high side switch off the strategy shown in Figure 29 is used In Figure 29 Trigg represents the time required by the analog voltage on the shunt resistor of a phase signal Current feedback of Phase B to settle after a commutation of the low side switch belonging to the same phase Figure 27 Low side duty cycle Phase A lt DT Ty Ts and ADuty p gt DT Tyt2TstTyt Tpma Low side Phase A High side Phase A Low side Phase B High side Phase B Current feedback of Phase B Current feedback of Phase C e Sampling end Figure 28 Figure 31 Low side duty cycle Phase A lt DT Ty Ts and DT Tgise Ts ADuty 4 p DT Tyt2Ts Tyt Tpma 100 90 80 70 60 50 40 30 20 10 0 0 Phase PhaseB Phase 30 60 45 84 Motor control library routines UM0312 46 84 Figure 29 Low side duty cycle Phase A lt DT Ty Ts and DT Triset s lt ADuty 4 p lt DT Tyt2Ts TH Tpma Ta Current feedback Vt Ne of Phase B _ 3 Phase C h Current feedback 1 7 of Phase C RR
74. on assumes that you are using the STR750 MCKITmotor control starter kit The demo program is intended to provide examples on how to use the software library functions it includes both open speed loop and closed speed loop operations hereafter simply referred to as Open Loop and Closed Loop with the possibility of changing different parameters on the fly The default configuration allows the use of three shunt resistors for current reading and encoder for speed feedback Refer to Section 3 3 on page 27for setting up the system when using ICS When the application is started it first shows a welcome message and switches shortly to the main screen Use the joystick and the button labelled KEY to navigate between the menus Key assignments are shown in Figure 9 Figure 9 Key function assignments DATA a FUNCTION 4 o b FUNCTION _ gt aa ENTER KEY connected to PB3 DATA A simple state machine handles the motor control tasks in the main loop as well as basic monitoring of the power stage This state machine does not differentiate open loop from closed loop control It is described in Figure 10 The power stage is monitored using the ADC peripheral and the PWM peripheral Emergency Stop ES input to watch the following conditions e Heatsink over temperature ADC channel AIN6 and ES input DC bus over under voltage on ADC channel AIN7 Over current protection ES input Any of
75. ose of this function is to set up microcontroller peripherals for performing 3 shunt resistors topology current reading and center aligned PWM generation The function initializes the DMA EIC ADC GPIO PWM and TIMO peripherals In particular the DMA ADC PWM and TIMO peripherals are configured to perform two synchronized A D conversions per PWM switching period None None It must be called at main level Standard Library MRCC_PeripheralClockConfig GPIO Init EIC IRQInit EIC IRQCmd Init TIM DMAConfig Delnit ADC DMACmd PWM Delnit Structlnit PWM Init TRGOSelection PWM ClearFlag PWM ITConfig PWM ResetCounter ADC Structlnit Init StartCalibration ADC_ConversionCmd Init TIM SynchroConfig TIM ResetCounter PWM Cmd Motor Control Library SVPWM_3ShuntCurrentReadingCalibration UM0312 Motor control library routines SVPWM_3ShuntCurrentReadingCalibration Synopsis void SVPWM_3ShuntCurrentReadingCalibration void Description The purpose of this function is to store the three analog voltages corresponding to zero current values for compensating the offset introduced by the amplification network Input None Returns None Caution This function must be called before PWM outputs are enabled so that the current flowing through inverter legs is zero When using STR750 MC Kit the power board MB459B must be supplied before the con
76. p PID Speed InitStructure hRot Freq Hz 6hz Torque value increased by PID resp decreased when motor speed too low resp high Note The PID_Speed_Regulator routine needs to be fed with a mechanical frequency input The following flow diagrams Figure 42 and Figure 43 show the decision tree for the computation of the torque flux and speed regulation routines Figure 42 Torque flux control loop block diagram Measured Torque Flux cp Target Torque Flux Torque Flux error signed 16 bit Proportional Kp x Torque Flux Error Is PI output saturated Integral Integral Ki x Torque Flux Error Integral term frozen If enabled Clamp Output value to See Differential Kd x Error Torque Flux 3 A important Previous Error Torque Flux signed int domain note in section 2 2 1 Output Proportional 2 13 Integral 2 16 Differential terms 2 13 Is Output lt PI D lower lim or gt upper limit Clamp Output value to unsigned PI D lower limit PI D upper limit Set Saturated Output Flag Reset Saturated Output Flag return Output value signed 16 bit Q 74 84 UM0312 PID regulator implementation and tuning Figure 43 Speed control loop block diagram Speed error signed 16 bit Proportional Kp x Speed Error Is PI output saturated Integral Int
77. p frequency define PID SPEED SAMPLING TIME Sampling time for the PID speed control loop This value is 8 bit long and the sampling period is adjustable from 0 500ms to 255 127ms The default sampling time is 2ms 19 84 Getting started with the library UM0312 20 84 Speed controller setpoint and PID constants initial values define PID_SPEED_REFERENCE Mechanical speed reference in closed loop at start up This is a signed 16 bit value expressed with 0 1Hz resolution 150 means 15Hz which is the default value The sign gives the direction of the motor rotation define PID_SPEED_KP_DEFAULT Proportional coefficient gain for the speed control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 5400 define PID_SPEED_KI_DEFAULT Integral coefficient gain for the speed control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 2000 define PID_SPEED_KD_DEFAULT Derivative coefficient gain for the speed control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 7400 Torque and flux controller setpoints and PID constants define PID_TORQUE_REFERENCE Torque reference value in open loop at start up This is a signed 16 bit value default 2500 The sign gives the direction of rotation of
78. r 5 84 Contents UM0312 5 2 1 Adjusting the regulation sampling time 71 5 2 2 Adjusting the speed regulation loop Ki Kp and Kd vs the motor frequency 72 Disabling the linear curve computation routine 75x it c module 73 5 3 Tricks and traps ska we kae Ge ed oe bi NR ER Md ERR RR YER 73 5 4 Implementing closed loop regulation 74 6 MISRA compliance 76 6 1 Analysis method 76 6 2 Limitallonls 22 3x c ewe Ra iR RARE EV PES 76 6 3 MISRA compliance for PMSM library files 77 Appendix A 4 1 79 A 1 Adjusting CPU load related to PMSM FOC algorithm execution 79 A 2 X Selecting PWM frequency for 3 shunt resistor configuration 80 JFixed point numerical representation 81 4 Additional or up to date technical 82 Ab References ess aUa e eC ROW RR eee Skew CE pa RR ROC SK a 82 7 Revision history 83 6 84 171 UM0312 List of tables List of tables Table 1 Table 2 Table 3 Table 4 Table 5 Table 6 Device SUMMA iue toed petens ES eM De 12 Sector identification
79. res set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever any liability of ST ST and the ST logo are trademarks or registered trademarks of ST in various countries Information in this document supersedes and replaces all information previously supplied The ST logo is a registered trademark of STMicroelectronics All other names are the property of their respective owners 2007 STMicroelectronics All rights reserved STMicroelectronics group of companies Australia Belgium Brazil Canada China Czech Republic Finland France Germany Hong Kong India Israel Italy Japan Malaysia Malta Morocco Singapore Spain Sweden Switzerland United Kingdom United States of America www st com 84 84
80. rflow underflow of the counter value occurs TIM CNT The Encoder Timer Overflow variable is then incremented None This is an interrupt routine STR750 Datasheet Synchronizable Standard Timer 61 84 Motor control library routines UM0312 4 2 11 75x TBTimer c module TB Timebase Timer Init Synopsis void TB_Timebase_Timer_Init void Description The purpose of this function is to initialize the Timebase Timer The peripheral clock interrupt auto reload value and counter mode are set up The peripheral is configured to generate an interruption every 500us thus providing a general purpose timebase Functions called EIC IROlnit TB Structlnit TB Init TB ITConfig TB TB ResetCounter TB ResetCounter See also STR750 datasheet timebase timer TB Wait Synopsis void TB Wait u16 time Description This function produces a programmable delay equal to the time variable multiplied by 500us Input Unsigned 16 bits Output None Functions called None Caution This routine exits only after the programmed delay has elapsed Meanwhile the code execution remains frozen in a waiting loop Care should be taken when this routine is called at main interrupt level a call from an interrupt routine with a higher priority than the timebase interrupt will freeze code execution See also STR750 datasheet timebase timer TB Set Delay 500us Synopsis void TB Set Delay 500us u16 hDelay Description This function is used to updat
81. rr T PREX nnn Finally when a high modulation index gt 92 and high frequency gt 11kHz PWM signal is generated it could happen that both Phase A pulse width is lower than DT Ty Ts and that ADutya p lt DT TrisetTs In this case it is not possible to perform the current reading on Phase B see Figure 30 so the PWM patterns are slightly modified to relapse in the case shown in Figure 29 Because this PWM pattern modification produces a distortion on the phase currents it is better to limit the scope of the modification by limiting the modulation index depending on the selected PWM frequency DT 0 7us Ty 2 55 5 Ts 1 6us Ty 2 67us Tpma 0 705 TRise 2 6US UM0312 Motor control library routines Figure 30 Low side duty cycle Phase A lt DT Ty Tg and Duty g DT TRise Ts 1 0 T Low side Phase A x jJ High side Phase A i Low side Phase B A High side Phase B TS NN e EFE E Current feedback E j of Phase a Phase C conversion Current feedback IA 3 urrent feedbac Th 4 of Phase C BN rm i PHASE B NOT ACCESSIBLE The maximum applicable duty cycles are listed in Table 3 as a function of the PWM frequency Table 3 PWM frequency vs maximum duty cycle PWM frequency Max duty cycle Max modulation index MMI Up to 11 4kHz 100 100 12 2kHz 99 596 99 12 9kHz 99 98 13 7kHz 98 596 97 1
82. s Note that it was built using robustness oriented structures thus preventing the speed or code size from being fully optimized The table below summarizes the memory required by the software library as it is delivered three shunt topology for the current reading encoder for speed feedback These metrics include non motor control related code implemented for demo purposes such as user interface via LCD and joystick Therefore the figures provided should be considered as an estimation which would be lower in the final application ROM RAM Size Kbyte 27 5 3 Related documents Available on www st com e SIR750 User Manual e STR750 Datasheet e STR750 Standard Library User Manual STH7 Flash Programming Manual Available on www arm com ARM7TDMI S Rev 4 Technical Reference Manual ARM DDI 0234A UMO312 Contents Contents 1 Getting started with 1 10 1 1 Working environment 10 1 2 Sottware tools ERR X ba eee ieee RT E ERES 10 1 3 Library source code 11 1 3 1 Download ti eder tus beca gU borea EU des HE n dE 11 1 3 2 File Structure s voee e ad we bdv gta Ri Sx kie Vet ads 11 1 3 3 Starting the IAR toolchain 12 1 4 Customizing the workspace for your STR75x device 12 1 4 1 Inkarm xxx xcl file
83. s file is to declare the compiler conditional compilation keys that are used throughout the entire library compilation process to 1 Select which current measurement technique is actually in use the choice is between three shunt or ICS sensors according to availability 2 Enable or disable the derivative action in the speed controller or in the current controllers in accordance with expected performance and code size UM0312 Getting started with the library If this header file is not edited appropriately no choice or undefined choice you will receive an error message when building the project Note that you will not receive an error message if the configuration described in this header file does not match the hardware that is actually in use or in case of wrong wiring More specifically define ICS SENSORS To be uncommented when current sampling is done with isolated current sensors commented by default define THREE SHUNT To be uncommented when current sampling is done with 3 shunt resistors uncommented by default define ENCODER To be uncommented when the encoder is connected to the starter kit Mandatory uncommented by default for the PMSM software library 1 0 e define TACHO To be uncommented when the tacho signal is connected to the starter kit Not used commented by default in the PMSM software library
84. se of this function is to set up microcontroller peripherals for performing ICS reading and center aligned PWM generation The function initializes EIC ADC GPIO and PWM peripherals In particular ADC and PWM peripherals are configured to perform one injected chain of two A D conversions every time PWM registers are updated event called U event Refer to Section 4 2 6 for further information on A D conversion triggering in ICS configuration Input None Returns None Note It must be called at main level Functions called Standard Library MRCC_PeripheralClockConfig GPIO Init EIC IRQlnit IRQOmd Delnit Structlnit PWM Init PWM TRGOSelection ClearFlag PWM ITConfig PWM ResetCounter ADC Structlnit Init ADC StartCalibration ADC_ConversionCmd PWM Motor Control Library SVPWM lIcsCurrentReadingCalibration UM0312 Motor control library routines SVPWM_IcsCurrentReadingCalibration Synopsis Description Input Returns Caution Functions called void SVPWM IcsCurrentReadingCalibration void The purpose of this function is to store the two analog voltages corresponding to zero current values for compensating the offset introduced by both ICS and amplification network None None The function must be called before PWM outputs are enabled so that current flowing through inverter legs is zero When using the STR750 MC Kit ICS sensors must be supp
85. t the PID Speed Coefficients update routine In this case the default values for Ki Kp Kd for torque flux and speed regulation are used See PID TORQUE Kx DEFAULT PID FLUX Kx DEFAULT PID SPEED Kx DEFAULT in the MC control Param h file To disable the linear curve computation routine in the 75x it c module void TB IRQHandler void if wGlobal Flags amp CLOSED LOOP CLOSED LOOP if State RUN PID Speed Coefficients update hRot Freq Hz to be commented out Tricks and traps When tuning the PID parameters you should consider the worst case conditions which may be when the load varies quickly and unpredictably when the inertia is at a minimum or when the mains voltage is maximum for an off line application If regulation tuning is performed in no load condition at the highest it will most probably be unresponsive in the final application and vice versa regulation tuning performed in the application may become unstable in no load conditions 73 84 PID regulator implementation and tuning UM0312 5 4 Implementing closed loop regulation Below is an example of the use of the speed regulation process Figure 41 Speed regulation loop call in 75x TBTimer c if bPID Speed Sampling Time 500us 0 bPID Speed Sampling Time 500us 3 PI D computed every 2ms else PID Speed Coefficients update hRot Freq Hz ID Torque InitStructure Reference PID Speed Regulator am
86. the actual maximum PWM duty cycle is equal to Max duty cycle 100 100 maximum modulation index chosen 2 A 95 modulation index corresponds to a 100 100 95 2 97 5 maximum duty cycle output signals to the power stage 58 84 UM0312 Motor control library routines 4 2 10 75x encoder c module ENC Init Synopsis void ENC Init void Description The purpose of this function is to initialize the encoder timer The peripheral clock input pins and update interrupt are enabled The peripheral is configured in 4X mode which means that the counter is incremented decremented on the rising falling edges of both timer input 1 and 2 TIMx TIO and TIMx pins Functions called PeripheralClockConfig GPIO Init IROlnit TIM Structlnit TIM Init TIM ClearFlag TIM ITConfig TIM ResetCounter Tim Cmd See also STR750 datasheet synchronizable standard timer ENC GetPosition Synopsis u32 ENC GetPosition void Description This function returns the encoder timer value giving a direct reading of the rotor position from 0 to 4 number of encoder pulses per revolution For the SHINANO motor included with the starter kit the encoder delivers 400 pulses per revolution This routine returns 0 for 0 degrees 4 400 2 800 for 180 degrees Input None Output Unsigned 32 bits Functions called None See also STR750 datasheet synchronizable standard timer ENC Get Electrical Angle Synopsis s16 ENC
87. the motor In closed loop this value is computed automatically by the speed regulation loop define PID_TORQUE_KP_DEFAULT Proportional coefficient gain for the torque control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 15000 define PID_TORQUE_KI_DEFAULT Integral coefficient gain for the torque control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 1000 define PID_TORQUE_KD_DEFAULT Derivative coefficient gain for the torque control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 1400 define PID_FLUX_REFERENCE Flux reference value This is a signed 16 bits value default 0 The modification of flux reference can help to increase the maximum speed of the motor while the efficiency will be slightly decreased define PID_FLUX_KP_DEFAULT Proportional coefficient gain for the flux control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 10000 define PID_FLUX_KI_DEFAULT Integral coefficient gain for the flux control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 1200 define PID_FLUX_KD_DEFAULT Derivative coefficient gain for the flux control loop regulation This is a signed 16 bit value adjustable from 0 to 32767 default 1000
88. these three conditions will cause the PWM to be stopped and the state machine to go into FAULT state before coming back to IDLE state Depending on the source of the fault an error message is also displayed on the LCD during FAULT state UM0312 Running the demo program Figure 10 Main c state machine 1sec delay elapsed Button pushed 3 1 LCD display in OPEN loop mode The following sections provide a summary of the screen access and settings in open loop blinking items are shown underlined Open Motor stopped Open closed loop selection Speed 0000 0 Hz Motor running no access Switching from open to closed loop operation and vice versa is done by moving the joystick up or down while the first menu shown in the above figure is displayed and the motor is stopped Moving the joystick left or right in these circumstances allows changing the context into the second menu where it is possible to modify both the torque and flux reference Iq 02000 00000 Id 00000 00000 V PID torque regulator target selection Measured torque top right and flux bottom right Iq 02000 00000 PID flux regulator target selection Id 00000 00000 25 84 Running the demo program UM0312 3 2 26 84 Finally press either the KEY button or the joystick to start the motor main state machine will move from IDLE to START state The ramp up strategy is ill
89. trol board MB469B This way the current sensing conditioning network will reach steady state before performing calibration Functions called Standard Library ADC GetFlagStatus ADC_ConversionCmd ADC_Init ClearFlag ADC_ITConfig Motor Control Library SVPWM_3ShuntCalcDutyCycles SVPWM 3ShuntGetPhaseCurrentValues Synopsis Curr Components SVPWM 3ShuntGetPhaseCurrentValues void Description This function computes current values of Phase A and Phase B in q15 format starting from values acquired from the A D Converter peripheral Input None Returns Curr Components type variable Caution In order to have a q15 format for the current values the digital value corresponding to the offset must be subtracted Thus it must be called after SVPWM SShuntCurrentReadingCalibration Functions called None 174 33 84 Motor control library routines UM0312 SVPWM_3ShuntCalcDutyCycles Synopsis void SVPWM_3ShuntCalcDutyCycles Volt_Components Stat_Volt_Input Description After execution of the PMSM FOC algorithm new stator voltages component Va and Vg are computed The purpose of this function is to calculate exactly the three duty cycles to be applied to motor phases starting from the value of those voltage components Moreover once the three duty cycles to be applied in next PWM period are known this function sets the DMA ADC and TIMO peripherals for the next current reading In particular depending on the duty cycl
90. uments and software can be found directly at http www stmcu com inchtml pages str750 html In addition FAQ and Forums can be found directly at http www stmcu com forumsid 17 html for STR7 general enquiries http www stmcu com forumsid 13 html for motor control related enquiries References 1 P C Krause O Wasynczuk S D Sudhoff Analysis of Electric Machinery and Drive Systems Wiley IEEE Press 2002 2 T A Lipo and D W Novotny Vector Control and Dynamics of AC Drives Oxford University Press 1996 3 P Vas Sensorless Vector and direct Torque Control Oxford University Press 1998 UM0312 Revision history 7 Revision history Table 6 Document revision history Date Revision Changes 9 Feb 2006 1 Initial release 83 84 UM0312 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics NV and its subsidiaries ST reserve the right to make changes corrections modifications or improvements to this document and the products and services described herein at any time without notice All ST products are sold pursuant to ST s terms and conditions of sale Purchasers are solely responsible for the choice selection and use of the ST products and services described herein and ST assumes no liability whatsoever relating to the choice selection or use of the ST products and services described herein
91. ustrated in Figure 6 Alignment procedure on page 18 Basically the applied stator current reference reaches the ALIGNMENT value that is defined in MC_Control_Param h following a linear ramp After a programmed delay T_ALIGNMENT the torque and flux references become adjustable on the fly from the joystick LCD display in CLOSED loop mode The following sections provide a summary of the screen access and settings in closed loop blinking items are shown underlined Closed Ref 0015Hz Motor stopped Open closed loop selection Speed 0000 0 Hz Motor running no access Switching from open to closed loop operation and back is done by moving the joystick up or down while the first menu shown in the above figure is displayed and the motor is stopped Closed Ref 0015Hz Speed 0000 0 Hz PID motor mechanical speed target selection In closed loop operation you can vary the target speed by moving the joystick up or down while the PID motor speed target selection menu is displayed The demo program also allows real time tuning of the speed PID regulator coefficients 990050 PID motor speed integral gain Ki selection Kp 05400 Kd UT460 Current mechanical speed in Hz S 0000 0 Ki 02000 Kp 05400 Kd 07400 PID motor speed proportional gain Kp selection 5 0000 0 1 02000 Kp 05400 Kdz07400 PID motor speed derivative gain Kd selection PID f
92. ve speed torque and flux regulation 15 84 Getting started with the library UM0312 2 2 2 2 1 16 84 Figure 5 PMSM FOC structure stator 9 9 frame stator frame FOC Model rotor flux d q frame Torque command 5 Flux command sear ates L LU I pwm signal va vb vc CURRENT READING POSITION READING CALCULATION Pre checks and library configuration It is quite easy to set up an operational evaluation platform with a drive system that includes the STR750 MCKIT featuring the STR750 microcontroller where this software runs and a permanent magnet sensored motor This section explains how to quickly configure your system and if necessary customize the library accordingly Follow these steps to accomplish this task 1 Gather the information that is needed regarding the hardware in use motor parameters power devices features speed position sensor parameters current sensors characteristics 2 Edit using an IDE the 75x MCconf h configuration header file as explained in more detail in Section 2 2 1 and the following parameter header files PMSM motor param h see Section 2 2 2 encoder param h see Section 2 2 3 MC Control Param h see Section 2 2 4 3 Re build the project and download it on the STR750 microcontroller Library configuration file 75x MCconf h file The purpose of thi
93. y Working environment The PMSM software library was fully validated using the main hardware board included in the STR750 MCKIT starter kit a complete inverter and control board The STR750 MCKIT starter kit provides an ideal toolset for starting a project and using the library Therefore for rapid implementation and evaluation of the software described in this user manual it is recommended to acquire this starter kit It is also recommended to install the IAR EWARM C toolchain which was used to compile the PMSM software library With this toolchain you do not need to configure your workspace You can set up your workspace manually for any other toolchain A free kickstart editio n of the EWARM C toolchain with a 32Kb limitation which is enough to compile and evaluate this library can be downloaded from http www iar com Software tools A complete software package consists of A third party integrated development environment IDE eA third party C compiler the EWARM development environment from IAR is pre configured 30 days time limited or 32Kb kickstart versions can be obtained upon request for evaluation This library was compiled using the third party IAR EWARM C toolchain However the choice of the C toolchain is left to your own appreciation An IAR dedicated workspace can be directly opened in the root of the library installation folder See Section 1 3 e JTAG interface for debugging and programming Us
94. ynamic performance in permanent magnet motor control offered by the field oriented control FOC strategy Through complex machine electrical quantity transformations this well established drive system optimizes the system efficiency to the extent that it is able to offer decoupled torque Tg and magnetic flux X control Figure 4 FOC drive placed in a speed loop Torque controller Flux controller or inverter actual rotor speed Basic information on field oriented structure and library functions is represented in Figure 5 e The 0 calculation block estimates the rotor position which is essential to transformation blocks Park Reverse Park for performing field orientation so that the currents supplied to the machine can be oriented in quadrature to the rotor flux vector More in depth information about reference frame theory is available in Section 4 2 8 on page 54 space vector PWM block SVPWM implements an advanced modulation method that reduces current harmonics thus optimizing DC bus exploitation e Thecurrent reading block allows you to measure stator currents correctly using either shunt resistors or market available isolated current Hall sensors ICS e Thespeed reading block handles the encoder signals in order to acquire properly rotor angular velocity or position e The PID controller block implements a proportional integral and derivative feedback controller to achie

Download Pdf Manuals

image

Related Search

Related Contents

- Mobiletech Blog  Mode d`emploi du catalogue  USER MANUAL - I  WWA-02AA Wireless Water & Freeze Alarm, Installation Instructions  Brochure System-77  Benutzerhandbuch  Studio DV - CONRAD Produktinfo.    

Copyright © All rights reserved.
Failed to retrieve file