Home
STM32F103xx or STM32F100xx PMSM single/dual
Contents
1. PMSM FOC ver Current controllers Set points Amp Iq 1500 W 1500 Eps Deg Id 3 0 Measured speed 1500 rpm Stert stop Iq PID Gains Id PID Gains Link kP 7000 KI 500 kp 710097 KI 509 Input Am Ep V Motor selected 1 M519361V1 e The Amp field field 1 in Figure 68 is used to set and read the current reference amplitude for the active motor This control is read only if the active motor is set in speed mode otherwise it is modifiable Amplitude reference is expressed in digits e The Eps field field 2 in Figure 68 is used to set and read the current reference phase for the active motor This control is read only if active motor is set in speed mode it otherwise is modifiable Phase is expressed in degrees Doc ID 18458 Rev 2 92 122 LCD user interface UM1052 8 2 7 93 122 Figure 69 Iq Id component versus Amp Eps component T Iq q Id Amp Eps Sensorless tuning STO amp PLL page This page is present only if the firmware is configured to use a state observer STO plus PLL sensor set as a primary or auxiliary speed and position sensor If the state observer sensor is set as an auxiliary speed and position sensor the AUX label will be shown near the page title See field 9 in Figure 70 To enter the sensorless tuning page press the joystick RIGHT from current controllers page It is possible to navigat
2. 00 ccc eee ee 29 Transformation from an abc stationary frame to a rotating frame q d 31 Circle limitation working principle 0 0 0 0 000 cet 32 Three shunt topology hardware architecture 1 2 0 00 c eee eee 34 PWM and ADC synchronization 0000 eee 35 Inverter leg and shunt resistor position 2 0 2 0 cee eee 36 Low side switch gate signals low modulation indexes 0 00 cece eee 37 Low side Phase A duty cycle gt DT TN 00 c eee eee 38 DT Ty Ts 2 lt ADuty4 lt Dr Ty and ADutyap lt Dy7 TptTs AA AA ee aetna 38 ADutyA lt DT Ty Ts 2 and ADutya_p gt DT T Rts 2 eee 39 ADutyy lt DT Ty Ts 2 and ADutya p lt DT TRtls 1 eee 39 Single shunt hardware architecture 00 cece eae 40 Single shunt current reading 0 00 cee tetas 41 Boundary between two space vector sectors n ausus 0c eee ee 42 Low modulation index 0 0 0 teens 43 Definition of noise parameters tees 44 Regularregion sernir aaa cornat roek AYANG NAG eee aa Seo ve asa eae Geers 44 Boundary Tasa ete aoe eS edie einem EEE EEA Os maa GN DRAG 45 Boundary 2 mami cee BG ee ee ae ed eos an Bae bed ew eS 45 Boundary Seye ganan oe BKT aaah ke gates 2 fa be eee aoe Se ene Ba Sa eee ees 46 ICS hardware architecture 0 0 0 0 ccc ttt 46 Stator currents sampling in ICS configuration 0 0 c eee 47 General sensorless algorithm block diagram 0
3. Measured current ai1 4850 For this analysis the motor electrical characteristics are assumed to be isotropic with respect to the q and d axes It is assumed that the torque and flux regulators have the same starting value of Kp and that they also have the same K value Doc ID 18458 Rev 2 26 122 Overview of the FOC and other implemented algorithms UM1052 Figure 15 shows the closed loop system in which the motor phase is modelled using the resistor inductance equivalent circuit in the locked rotor condition Block A is the proportionality constant between the software variable storing the voltage command expressed in digit and the real voltage applied to the motor phase expressed in Volt Likewise block B is the is the proportionality constant between the real current expressed in Ampere and the software variable storing the phase current expressed in digit Figure 15 Closed loop block diagram Target i e current Measured current ai14851 The transfer functions of the two blocks A and B are expressed by the following formulas 3 WeuDC R 16 A 2 A and B Shunt op respectively 516 3 3 ana By putting Kp K Le Re it is possible to perform pole zero cancellation as described in Figure 16 Figure 16 Pole zero cancellation Target current ai14852 In this condition the closed loop system is brought back to a firs
4. LCD project Contains source files of the optional LCD user interface and configuration files for IDEs Motor control workspace The Motor Control SDK is composed of three projects as shown in Figure 51 which constitute the MC workspace Doc ID 18458 Rev 2 a UM1052 Working environment Figure 51 MC workspace structure 1101110101 0100101111 0001101010 101 User Project 101001010 1001101011 MC Application Project 0101010101 0100 1100100101 0100010100 1010010101 001 MC Library Project MS19321V1 The Motor Control Library project the collection of all the classes 37 among base and derivative classes developed to implement all the features Each class has its own public interface A public interface is the list of the parameters needed to identify an object of that kind and of the methods or functions available Note that in the case of a derivative class applicable methods are those of the specific derived plus those of the base class Further detail is provided in the Advanced developers guide for STM32F 103xx STM32F 100xx PMSM single dual FOC library UM1053 All these interfaces constitute the Motor Control Library Interface The Motor Control Library project is independent from system parameters the only exception is single dual drive configuration and is built as a compiled library not as an executabl
5. ULGetReg g_oUI D N LEDLPoling T17 Ul ExecCmdg oUI CMD LCDI_UpdateAll oUN CA LCDI_UpdateMes sured oU Call functions of that module MS19368V1 The LCD_Interface is a module written in C that performs the interface between UI objects and the STMFC library When LCD Init or LCD_UpdateAll are called the LCDI UpdateAll method is also called and updates all values of the LCD GUI You can also call LCDI UpdateMesured to update only the measured quantity the quantity that changes inside the MC object itself such as measured speed measure l Using the LCD Manager To use the LCD manager you must 1 Obtain the oMCT and oMCI object through GetMCIList GetMCTList functions exported by MCTasks h The oMCI and oMCT are two arrays of objects CMCI oMCI MC_NUM CMCT oMCT MC_NUM GetMCIList oMCI GeMCTList oMCT 2 Instantiate and initialize a CLCD UI object CLCD UI oLCD LCD New0bject MC NULL UI Init CUI o0oLCD MC NUM oMCI oMCT pUICfg LCD Init oLCD CUI oDAC s_fwVer Note that you must call both Ul Init and LCD Init LCD Init must be called after the UI Init pUICfg is the user interface configurations array See Section 9 2 User interface configuration Doc ID 18458 Rev 2 ky UM1052 User Interface class overview 9 5 oDAC is the related DAC object that should be driven by LCD manager This DAC object should b
6. 1 eee 68 LCD Ul project cc eee 69 State machine flow diagram 1 6 sasaaa aaaea 72 Radians VS SIG a kn ei Soe Nah Meee nde EE E eee ed bela sop as 78 User interface reference 2 0 0 eee 79 Page structure and navigation ee eee 80 STM32 Motor Control demonstration project welcome message 82 Configuration and debug page 83 Dual control panel page tte ee 87 Speed controllers page tetas 89 Current controllers page eae 91 Current controllers page with polar coordinates an 92 lq ld component versus Amp Eps component 0 0 c eee ee 93 Sensorless tuning STO amp PLL page 00 0 ae 94 Example of rev up sequence 0 eee 95 Sensorless tuning STO amp CORDIC page 0 c cee 96 Software laye S eretet DADA mad ea eee Pee i eee wae Wee Gee eee 98 User interface block diagram 00 eee 99 User interface configuration bit field 0 0 0 eet eee 101 LCD Manager block diagram 0000 e eee ae 103 Serial communication software layers eee ee 104 Serial communication in motor control application 0000 cee eee 109 Master Slave communication architecture sasaaa 000 c eee eee 110 Set register frame 6 teens 111 Get register frame 2 AL 113 Execute command frame 0 ete eee 114 Execute ramp frame 0 2 0 0 eee 115 SPCC
7. R2 MC PROTOCOL REG OBS CR i f pa EE ANCER 77 7 observer CORDIC sensor configured as primary or auxiliary speed sensor MC PROTOCOL REG OBS CR Observed motor speed This variable is related to state observer ROT_SPEED CORDIC sensor configured as primary or auxiliary speed sensor MC_PROTOCOL_REG_OBS_CR_ Observed alpha component of motor phase s current expressed in I ALPHA alpha beta reference This variable is related to state observer CORDIC sensor configured as primary or auxiliary speed sensor MC_PROTOCOL_REG_OBS_CR_ Observed beta component of motor phase s current expressed in T BETA alpha beta reference This variable is related to state observer E CORDIC sensor configured as primary or auxiliary speed sensor MC PROTOCOL REG OBS CR Observed alpha component of motor BEMF expressed in a alpha beta reference This variable is related to state observer BEMF ALPHA n Pr CORDIC sensor configured as primary or auxiliary speed sensor MC PROTOCOL REG OBS CR Observed beta component of motor BEEF expressed in alpha beta aaa reference This variable is related to state observer CORDIC T sensor configured as primary or auxiliary speed sensor MC PROTOCOL REG DAC USE User defined DAC variable Section 9 9 describes how to configure R1 user defined DAC variables MC PROTOCOL REG DAC USE User defined DAC variable Section 9 9 describes how to configure user defined DAC variables Ea
8. Sector Ill VI TimePhA 4 5 TimePhB TimePhC X TimePhC TimePhA Y Detailed explanation about reference frame transformations PM synchronous motors show very complex and time varying voltage equations By making a change of variables that refers stator quantities to a frame of reference synchronous with the rotor it is possible to reduce the complexity of these equations This strategy is often referred to as the Reference Frame theory 1 Supposing fax fbx fox are three phase instantaneous quantities 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 20 supposing fox fax fox are their transformations directed along Doc ID 18458 Rev 2 30 122 Overview of the FOC and other implemented algorithms UM1052 31 122 paths orthogonal to each other the equations of transformation to a reference frame rotating at an arbitrary angular velocity a can be expressed as cos0 cos 6 Zr cos o Zr 3 3 2 fadox fax a sino sin 0 22 sin 9 22 fbx 1 1 1 2 2 2 where 9 is the angular displacement of the q d reference frame at the time of observation and 9 that displacement at t 0 see Figure 20 Figure 20 Transformation from an abc stationary frame to a rotating frame q d ai14844 With Clark s transformation stator currents ias and ips which are directed along axes each displaced by 120
9. For an SM PMSM the inductances of the d and q axis circuits are the same refer to Section 3 2 that is we have mr o qs Lus Lis S On the other hand IPMSMs show a salient magnetic structure so their inductances can be written as 3 Lms Los las z bed ms s 3 L L Lus Lis E 2s SM PMSM field oriented control FOC The equations below describe the electromagnetic torque of an SM PMSM Say i l Pec is Te 5P Mala Aq ia 5P Lglg ig Pmig akal ig 3 R Te 5P Pnlg The last equation makes it clear that the quadrature current component ig has linear control on the torque generation whereas the current component iy has no effect on it as mentioned above these equations are valid for SM PMSMs Therefore if is the motor r te d current then its maximum torque is produced for igs ls and igs 0 in fact i ia In any case it is clear that when using an SM PMSM the torque current ratio is pi by letting iy 0 This choice therefore corresponds to the MTPA maximum torque per ampere control for isotropic motors On the other hand the magnetic flux can be weakened by acting on the direct axis current igs this extends the achievable speed range but at the cost of a decrease in maximum quadrature current ig and hence in the electromagnetic torque supplied to the load see Section 3 6 Flux weakening control for details about the Flux weakening strategy In conclusion by
10. N UM1052 YI User manual STM32F103xx or STM32F 100xx PMSM single dual FOC SDK v3 0 May 2011 Introduction This manual describes the Motor Control Software Development Kit generically called software library designed for and to be used with STM32F103xx or STM32F100xx microcontrollers STM32F103xx also called STM32 performance line STM32F100xx also called STM32 value line The software library implements the Field Oriented Control FOC drive of 3 phase Permanent Magnet Synchronous Motors PMSM both Surface Mounted SM PMSM and Internal I PMSM The control of an AC induction motor equipped with encoder or tacho generator is described in the UM0483 user manual The STM32F family of 32 bit Flash microcontrollers is based on the breakthrough ARM Cortex MB83 core specifically developed for embedded applications These microcontrollers combine high performance with first class peripherals that make it suitable for performing both permanent magnet and AC induction motor FOC The PMSM FOC library can be used to quickly evaluate ST microcontrollers and complete ST application platforms as well as to save time when developing Motor Control algorithms to be run on ST microcontrollers This PMSM FOC library is written in C language and implements the core Motor Control algorithms reference frame transformations currents regulation speed regulation space vector modulation energy efficiency optimizations as well as sensors rea
11. 0x0000 Prescaler preload Prescaler active Transfer from preload to active on next capture update event Figure 45 Hall sensor timer interface prescaler increase Capture Capture Capture Capture OxFFFF i ovf VIN ovf Timer overflowed the i prescaler is increased 0x5500 estas Lf AE RA KEY AP ee 0x0000 Prescaler preload 30 pa 31 31 31 Prescaler active 30 bd 30 31 gt lt Fr Transfer from preload to active on next capture update event The prescaler modification is done in the capture interrupt taking advantage of the buffered registers the new prescaler value is taken into account only on the next capture event by the hardware without disturbing the measurement Further details are provided in the flowchart shown in Figure 46 which summarizes the actions taken into the TIMx_IRQHandler Doc ID 18458 Rev 2 52 122 Rotor position speed feedback UM1052 5 2 2 53 122 Figure 46 TIMx_IRQHandler flowchart HALL_IRQHandler Capture event Update OVF event Read present state OVF_Counter Extract spinning direction a oo OVF Counter 5 HALL MAX OV ERFLOWS Extract electrical angle There were overflows Re compute capture Yes Captured value Store capture Store capture is
12. CORDIC sensor Table 32 User interface configuration CFG bit descriptions Code Description UI_CFGOPT_NONE Enable this option when no other option is selected Enable this option when the flux weakening is enabled in the MC UI_CFGOPT_FW z firmware UI_CFGOPT_SPEED_KD Enable this option when the speed controller has derivative action UI_CFGOPT_Iq_KD Enable this option when the lq controller has derivative action UI_CFGOPT_Id_KD Enable this option when the Id controller has derivative action UI_CFGOPT_DAC Enable this option if a DAC object is associated with the UI UI_CFGOPT_SETIDINSPDMOD EnablethisoptiontoallowsettingtheldreferencewhenMCisin E speed mode UI_CFGOPT_PLLTUNING Enable this option to allow setting the PLL KP and KI LCD manager class CLCD Ul This is a derived class of UI that implements the management of the LCD screen It is based on the LCD graphical library STMFC written in C language A functional block diagram of LCD manager is shown in Figure 76 The MC objects MCI MCT are linked to the LCD manager by the UI_Init and are accessed only by base class methods Doc ID 18458 Rev 2 102 122 User Interface class overview UM1052 9 4 103 122 Figure 76 LCD Manager block diagram MCT Get LCD Init ObjGet LCD_UpdateAll Obj Set A LCD_UpdateMeasued MC object L Ul SetReg g_oU1 D val LCDI InitfoUn
13. The ADC can also be used to synchronize the current sampling point with the PWM output using the external triggering capability of the peripheral Owing to this current conversions can be performed at any given time during the PWM period To do this the control algorithm uses the fourth PWM channel of TIM1 to synchronize the start of the conversions Doc ID 18458 Rev 2 34 122 Current sampling UM1052 35 122 Figure 23 shows the synchronization strategy between the TIM1 PWM output and the ADC The A D converter peripheral is configured so that it is triggered by the rising edge of TIM1_CH4 Figure 23 PWM and ADC synchronization Counter overflow OCR 4 OCR 4 H OCR 2 f OCR 2 OCR 3 f OCR 3 fey TIM1_CH1 TIM1_CH1 TIM1_CH2 TIM1_CH2 TIM1_CH3 E TIM1_CH3 Sampling point before counter overflow Sampling point after counter overflow In this way supposing that the sampling point must be set before the counter overflow that is when the TIM1 counter value matches the OCR4 register value during the upcounting the A D conversions for current sampling are started If the sampling point must be set after the counter overflow the PWM 4 output has to be inverted by modifying the CC4P bit in the TIM1_CCER register In so doing when the TIM1 counter matches the OCR4 register value during the downcounting the A D samplings are started After execution of the FOC algorithm the value to be loaded into the OCR4 re
14. Ul manages DAC outputs using a virtual DAC implemented with a filtered PWM output generated by a timer peripheral This is the default setting when DAC output is enabled using the STM32F103xB Medium density device CDACS UI does not perform a digital to analog conversion but sends the output variables through SPI communication User interface class CUI This class implements the interaction between the user and the motor control library MC Library using the motor control application layer MC Application In particular the CUI object is to be used for reading or writing relevant motor control quantities for example Electrical torque Motor speed and execute the motor control commands exported by MC Application for example Start motor execute speed or torque ramps customize the startup Any object of this class must be linked to a derived class object Doc ID 18458 Rev 2 ky UM1052 User Interface class overview The user interface class requires the following steps implemented inside the method UI_Init e Defines the number of motor drives managed by user interface objects Implementation of MC firmware manages at most two motor drives The CUI can manage N drivers e Creates the link between MC tuning MCT MC interface MCI objects and the user interface objects See Section 7 1 MCInterfaceClass and Section 7 2 MCTuningClass for more information about MCI and MCT e Configures the options of user inte
15. and is represented by the list of labels in the LCD screen point 7 in Figure 63 If a fault condition occurred and is over the relative label is displayed in blue If a fault condition is still present the relative label is displayed in red It is gray if there is no error To acknowledge the fault condition press the Fault ack button field 8 in Figure 64 If a fault condition occurs the motor is stopped and it is no longer possible to navigate in the other pages In this condition it is not possible to restart the motor until the fault condition is over and the occurred faults have been acknowledged by the user pushing the Fault ack button point 8 in Figure 63 If a fault condition is running the Fault ack button is disabled Table 22 Fault conditions list Fault Description This fault occurs when the microcontroller break input signal is activated It is Overcurrent wor i usually used to indicate hardware over current condition This fault occurs when the programmed rev up sequence ends without Revup fail validating the speed sensor information The rev up sequence is performed only when state observer is configured as primary speed sensor This fault occurs only in RUN state when the sensor no longer meets the Speed fdbk conditions of reliability This fault occurs when software detects a general fault condition In present SW error implementation the software error is raised when the FOC frequency is too
16. configuration and parameters This part of the process ends by generating the h parameters in the correct directory Installation folder System amp Drive Params If the system is configured to enable the LCD User Interface download the specific firmware See Section 6 6 LCD UI project Open the MC workspace of choice FreeRTOS based Installation folder FreeRTOS Project EWARM RTOS_Workspace eww Non FreeRTOS Installation folder Project EWARM Workspace eww Enable the user project callout 1 in Figure 56 User project and select the appropriate option from the combo box callout 2 in Figure 56 User project If none of the boards displayed is in use read Section 6 5 User project to perform a correct configuration Press F8 to batch build the entire workspace The dialog box shown in Figure 53 Workspace batch build appears Select a batch command callout 1 Figure 53 as for step 4 then click the Make button to make the build callout 2 Figure 53 If no error or relevant warning appears download the firmware callout 3 Figure 53 and do a test run Doc ID 18458 Rev 2 ky UM1052 Working environment 6 3 Figure 53 Workspace batch build IAR Embedded Workbench IDE Doug STM32100B EVAL Files a UserProject STM32100B EVAL 0 CI Motor control TRA ical Marketir Std projecttemplate eee User interface workspace rebuild STEVAL IHMO22V 1 New D workspace rebuild STM32100B
17. g aaa N s 37 extern void iar_data_init3 void Ha DJ cmsis Ne a4 o Ha DJ EWARMV5 39 void main void Ha GLCD Interface 40 Ha E StdPeriph_Driver ja i 41 Don t run application from here Just flas STM32_EVAL oi 42 Ha 9 STMFC 43 9 UI Library Interface aa see E D i 45 brief This function is used as entry poir LA LI Output 46 param void List of imported functions j H 47 retval void List of exported functions i 48 47 49 void const LCDI_Entry void ImportedFunctior y UI Project fol a lt I T A Ready Ln 41 Col 11 MS19351V1 Figure 58 displays the logical arrangement of files left hand side and actions that may be needed for set up and download Four project configurations are provided callout 1 Figure 58 one for each STM32 evaluation board that has been tested with the MC SDK STM32F10B EVAL STM32F10E EVAL STM32F100B EVAL STEVAL IHM022V 1 This configuration affects LCD driver and linker file selection Build the project callout 2 Figure 58 and download it to the microcontroller memory callout 3 Figure 58 To test that the LCD UI is flashed correctly for both option 1 and 2 open build and download the user project see Section 6 2 MC SDK customization process and Section 6 5 User project From the debug session run the firmware F5 and then after a while stop debugging CTRL Shift D The LCD UI is not flashed properly if the progr
18. 0 These functions are performed inside UlTask c Time base for serial communication time out also uses Timebase c or RTOS by default DAC Manager Class CDACx Ul There are three derivatives of CUI that implement DAC management DAC UI DAC_UI DAC peripheral used as output DACRCTIMER UI DACT_UI General purpose timer used and output together with a RC filter DACSPI UI DACS Ul SPI peripheral used as output The data can be d codified by an oscilloscope for instance For each DAC class the number of channels two is defined The DAC variables are predefined motor control variables or user defined variables that can be output by DAC Doc ID 18458 Rev 2 ky UM1052 User Interface class overview objects DAC variables can be any value MC PROTOCOL REG xxx exported by UserlnterfaceClass h Table 33 describes a set of relevant motor control quantities Table 33 Description of relevant DAC variables Variable name Description MC_PROTOCOL_REG_I_A Measured phase A motor current MC_PROTOCOL_REG_I_B Measured phase B motor current M i i NG PROTOCOL REC St ALPHA easured alpha component of motor phase s current expressed in alpha beta reference Measured beta component of motor phase s current expressed in alpha beta reference MC PROTOCOL REG I BETA Measured q component of motor phase s current expressed in q d MC PROTOCOL REG I Q re
19. 2 in Figure 66 This sets the duration of a speed ramp for the active motor Duration is expressed in milliseconds The value set in this control is not automatically sent to motor control related object but it is used to perform a speed ramp execution See description of exec button field 3 in Figure 66 It is possible to set a duration value of 0 to program a ramp with an instantaneous change in the speed reference from the current speed to the final motor speed field 1 in Figure 66 ky Doc ID 18458 Rev 2 UM1052 LCD user interface 8 2 6 sa Table 24 Speed controllers page controls continued Control Exec button field 3 in Figure 66 Description This executes a speed ramp for the active motor The execute speed ramp command is sent to the motor control related object together with final motor speed and duration presently selected field 1 and 2 in Figure 66 The execute speed ramp command performs a speed ramp from the current speed to the final motor speed in a time defined by duration The command is buffered and takes effect only when the motor becomes in RUN state Measured speed field 4 in Figure 66 This reads the motor speed for the active motor Motor speed is expressed in RPM and is a read only control Start Stop button field 5 in Figure 66 This sends a start stop command for the active motor A start stop command starts the motor if it is stopped or stop
20. ADC Tm Mana TMSU ADC2 is used in time sharing Trigger selection is performed in the TIM UP ISR Used by the first or second motors configured in ADC1 i i TIM8 Nana TIM8 UP C1 three shunt depending on the user selection ADC ADC2 is used in time sharing Trigger selection is performed in the TIM UP ISR 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 Root part number 1 A D converter trigger makes it possible to synchronize the two A D conversions necessary for reconstructing the stator currents flowing through the motor with the PWM reload register updates This is important because as shown in Figure 40 it is precisely during counter overflow and underflow that the average level of current is equal to the sampled current Refer to the Root part number 1 reference manual to learn more about A D conversion triggering Figure 40 Stator currents sampling in ICS configuration PWM Counter Compare AL Ka Compare Bi _ LowsideA LowsideB Phase current a i Averagecurrent T TIM Update l T TIM Update ADC trigger ADC trigger MS19317V1 Doc ID 18458 Rev 2 ky UM1052 Rotor position speed feedback 5 Rotor position speed feedback Section 3 1 Introduction t
21. EVAL workspace rebuild 5TM3210B EVAL stm32f1 Dx ito workspace rebuild STM3210E EVAL Edt stm32f1 Dx MC itc deere El Timebase c oe GUIDANCE ONL E UlTask c THEIR PRODUCT E Output Gee ICS SHALL NOI DAMAGES WITH Cancel AND OR THE US EN IN CONNECTI Build Overview MC Application MC Library UserProject Clean Rebuild All Ready SIMicroelectily It should be noted here that when system configuration or parameters are modified it may be necessary to rebuild all three projects or just one The batch command conveniently builds all three to avoid problems This method is not time consuming from the compiler point of view because if a project is not affected by the modification it is not recompiled Then usually after having run tests on the motor or found a fine tune the procedure required to change drive parameters re build and flash the firmware again is shorter only steps 1 5 6 need to be done It s thus suggested that ST MC Workbench GUI and IDE are left open The following sections provide more information about each of the three projects of the MC workspace Motor control library project confidential distribution The MC Library project available only in confidential distribution is a collection of classes related to motor control functionalities 1 To access the project using IAR IDE open the MC workspace of choice FreeRTOS based or not and click the name in the workspace
22. Error Acknowledgment frame BOARD mad OxFF 0x1 ERROR_CODE CRC asii The Master sends the requested current references The payload length is always 4 lq LB and lq HB is the requested new lq reference expressed in digit respectively least significant byte and most significant byte ld LB and Id_HB is the requested new Id reference expressed in digit respectively least significant byte and most significant byte Doc ID 18458 Rev 2 118 122 Serial communication class overview UM1052 Note 119 122 To convert current expressed in Amps to current expressed in digit is possible to use the formula Current digit Current Amp x65536xR ShuntxA OP Vdd micro The Acknowledgment frame can be of two types e Data Acknowledgment frame if the operation has been successfully completed the payload of this Data Acknowledgment frame will be zero e Error Acknowledgment frame if the operation has not been successfully completed by the firmware The payload of this Error Acknowledgment frame is always 1 The list of error codes are shown in Table 36 List of error codes Doc ID 18458 Rev 2 UM1052 Document conventions 11 4 Document conventions Table 39 List of abbreviations Abbreviation Definition AC Alternate Current API Application Programming Interface B EMF Back Electromotive Force CORDIC COordinate Rotation Dig
23. 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 Figure 40 Figure 41 Figure 42 Figure 43 Figure 44 Figure 45 Figure 46 Figure 47 Figure 48 ky MC software library architecture 1 sssaaa anaua 10 Motor control library 2 0 ete 11 Example SCONAMNO cece ee ea eee ee Re ee 12 Basic FOC algorithm structure torque control 0 00 cee eee 16 Speed control loop aisida eee 16 Different PM motor constructions 00 0 0 ce tees 17 Assumed PMSM reference frame convention 000 ccc eee eee eee eee 18 MTPA trajectory 0 eee 21 MTPA CONtOI mGA MABIGLA aes ata oe ae AG bee ane wan 21 Feed forward current regulation 0 0 cee eee 23 Flux weakening operation scheme nana 24 PID general equation eee tenes 25 Time domain to discrete PID equations 0 0 eee 26 Block diagram of Pl controller 0 0 0 0 00 cee eee 26 Closed loop block diagram 0 0 ttt eee 27 Pole zero cancellation 2 0 0 cee teens 27 Block diagram of closed loop system after pole zero cancellation 28 Va and Vp stator voltage components 000 c eee 29 SVPWM phase voltage waveforms
24. O to 3 3 volt Table 19 Definitions Definition Currents quantity la lq Description Current quantities are output to DAC as signed 16 bit numeric quantities converted in the range of DAC voltage range Zero current is at 1 65 volt of DAC output Maximum positive current that runs from inverter to the motor is at 3 3 volt of DAC output Maximum negative current that runs from inverter to the motor is at 0 volt of DAC output Voltage quantity Valpha Vq Voltage quantities are output to DAC as signed 16 bit numeric quantities converted in the range of DAC voltage range 0 of modulation index is at 1 65 volt of DAC output 100 of modulation index is at O and 3 3 volt of DAC output Electrical angle This is expressed in digits converted to the DAC voltage range 180 electrical degrees is at O and 3 3 volt of DAC output 0 electrical degrees is at 1 65 volt of DAC output Motor speed This is proportional to the maximum application speed 0 speed is at 1 65 volt of DAC output Maximum positive application speed is at 3 3 volt of DAC output Maximum negative application speed is at 0 volt of DAC output Observer BEMF voltage This is referenced to the maximum application speed and the voltage constant configured in the firmware Values of BEMF present at maximum application speed is at O and 3 3 volt of DAC output 83 122 Doc ID 18458 Re
25. Two versions of this user project are available One is based on FreeRTOS the other is not The demonstration user project can be dismantled and replaced by the user application layer or quite easily integrated as shown in Figure 3 the user application layer uses the STM32F10x Standard Library for its own purposes sends commands directly to the MC API while the serial communication interface provided in the demonstration user project dispatches commands received from the outer world to the MC API More information about the modules integrated with the demonstration user project such as serial communication protocol drive variables monitoring through DAC SPI HID Doc ID 18458 Rev 2 ky UM1052 MC software development kit architecture a generically called UI library and a description of LCD screens can be found in Section 8 LCD user interface and Section 9 User Interface class overview Figure 3 Example scenario User Application Layer MC Application MC Library STM 32F10x Std Lib MS19302V1 Doc ID 18458 Rev 2 12 122 Documentation architecture UM1052 2 2 1 13 122 Documentation architecture Where to find the information you need Technical information about the MC SDK is distinguished and organized by topic The following is a list of the documents that are available and the subjects they cover This manual UM1052 STM32F103xx STM32F 100xx permanent magnet synchronous
26. a is created in Installation folder Project EWARM MC Interface Compiled Exe or Installation folder FreeRTOS Project EWARM MC Interface Compiled Exe 6 5 User project The User project is the application layer that exploits the MC API 1 Access the project using IAR IDE by opening the MC workspace of choice FreeRTOS based or not and clicking its name in the workspace tabbed browser callout 1 4 Doc ID 18458 Rev 2 64 122 Working environment UM1052 Figure 56 Remember that IDE toolbars and commands always refer to the active project the one whose tab is engraved Figure 56 displays the logical arrangement of files and actions necessary to set up and download the User project Figure 56 User project 9 IAR Embedded Workbench IDE 3 file Timebase c E 4 author IMS Systems Lab and Technical Mar D E yemin Betad 0 Bote 02 F Motor control FR Ha DI MG Applicatiod interface LO DIMO Library LA O interface Ha O Std projecttemplate mma CMSIS iy Category 4 Fail Doc 3 EWARMv5 C C Compiler StdPeriph_Driver La O STM32_EVAL Ha G User interface N Ha E main c E strn32f1 0x_it c Assembler Output Converter Target Output Library Configuration Library Options MISRA C 200 4 gt Custom Build Build Actions 5 Linker E stm32f10x MC itc A Debugger O
27. ai15143 If the voltage demand vector lies in Boundary 1 or Boundary 2 region a distortion must be introduced in the related PWM signal phases to sample the motor phase current An ST patented technique for current sampling in the Boundary regions has been implemented in the firmware Please contact your nearest ST sales office or support team for further information about this technique Current sampling in isolated current sensor topology Figure 39 illustrates the ICS topology hardware architecture Figure 39 ICS hardware architecture ICS must generate a positive voltage when current goes 3 3V L out of the inverter gt Voltage from ICS Voltage to be converted MS19316V1 The three currents l4 lo and Ig flowing through a three phase system follow the mathematical relationship li lo 4 1350 Doc ID 18458 Rev 2 46 122 Current sampling UM1052 47 122 Table 8 ICS current reading used resources single drive F103 LD MD ADC ADC Adv timer DMA ISR Note master slave DMA is used to enable ADC injected TIM1 DMA1_CH5 None ADC1 ADC2 conversion external trigger Disabling is performed by software Table 9 ICS current reading used resources single or dual drive F103 HD Adv timer DMA ISR ADC Note Used by the first or second motors configured in ADC1 three shunt depending on the user selection
28. and MMI Maximum Modulation Index Doc ID 18458 Rev 2 ky UM1052 Current sampling 4 4 1 Current sampling Section 3 1 Introduction to the PMSM FOC drive shows that current sampling plays a crucial role in PMSM field oriented control This Motor Control Library provides complete modules for supporting three shunt single shunt and ICS topologies Refer to sections Section 4 1 Section 4 2 Section 5 respectively for further detail The selection of decoding algorithm to match the topology actually in use can be performed through correct settings in the h parameter files generated by the ST MC Workbench GUI used to initialize the MC Application during its boot stage Current sampling in three shunt topology Figure 22 shows the three shunt topology hardware architecture Figure 22 Three shunt topology hardware architecture Voltage on R Shunt Voltage to be converted MS19310V1 The three currents l4 lo and l3 flowing through a three phase system follow the mathematical relation l lo l3 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 Root part number 1 A D converter makes it possible to synchronously sample the two A D conversions needed for reconstructing the current flowing through the motor
29. 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 2011 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 Philippines Singapore Spain Sweden Switzerland United Kingdom United States of America www st com ky Doc ID 18458 Rev 2 122 122
30. control is automatically sent to motor control related object allowing the run time tuning of current controller This control is only present if state observer PLL object is set as the primary or auxiliary speed and position sensor and if the PLL tuning option is enabled in the firmware Duration field 5 in Figure 70 To set the duration of the active rev up stage for the active motor The value set in this control is automatically sent to motor control related object and becomes active on next motor start up allowing the tuning of the rev up sequence Duration is expressed in milliseconds F Speed field 6 in Figure 70 To set the final mechanical speed for the active motor and active rev up controller stage The value set in this control is automatically sent to motor control related object and becomes active on next motor start up allowing the run time tuning of rev up sequence Final mechanical speed is expressed in RPM Doc ID 18458 Rev 2 94 122 LCD user interface UM1052 8 2 8 95 122 Table 28 Sensorless tuning STO 4 PLL page controls continued Control Description To set the final torque reference for the active motor and active rev up controller stage The value set in this control is automatically sent to motor control related object and becomes active on next motor start up allowing the la field 7 in tuning of rev up sequence Final torque reference is expressed in Id current F
31. current controller Iq PI D gain KI field 6 in Figure 67 To set the integral coefficient of the lq current controller for the active motor The value set in this control is automatically sent to the motor control related object allowing the run time tuning of current controller Id PI D gain KP field 7 in Figure 67 To set the proportional coefficient of the ly current controller for the active motor The value set in this control is automatically sent to the motor control related object allowing the run time tuning of current controller This control is only read if the link check box is checked Id PI D gain KI field 8 in Figure 67 To set the integral coefficient of the ly current controller for the active motor The value set in this control is automatically sent to the motor control related object allowing the run time tuning of current controller This control is only read if the link check box is checked To enable or disable the link between I and lg controllers KP and KI gains This is performed checking or unchecking the link check box field 9 in Figure 67 It is possible to change the current reference variables from Cartesian coordinates Iq Id to polar coordinates Amp Eps Figure 68 using the input combo box field 10 in Figure 67 If polar coordinates are selected the current controller page is modified as in Figure 68 Figure 68 Current controllers page with polar coordinates
32. debugging and programming Application board with an STM32F103xx STM32F 100xx properly designed to drive its power stage PWM outputs to gate driver ADC channels to read currents DC bus voltage Many evaluation boards are available from ST some of them have an ST link programmer onboard Three phase PMSM motor Table 11 explains the MC SDK file structure for both Web and confidential distributions Table 11 File structure File Subfile Description MC library Source file of the MC library layer interface Public definitions interfaces of classes inc available only in confidential distribution Private definitions data structure of classes src available only in confidential distribution Source files obj available only in confidential distribution Compiled classes Public definitions interfaces of classes and common definitions exported up to the highest level PI Digital Output reference frame transformation MC Application Source file of the MC application layer interface Public definitions interfaces of classes inc Private definitions data structure of classes src Source files UI library Source file of the User Interface layer interface Public definitions interfaces of classes inc Private definitions data structure of classes src Source files STMFC LCD graphics library Libraries FreeRTOS source FreeRTOS V1 6 distribution GNU GPL license htt
33. drawings b and c in Figure 6 the magnets are embedded in the rotor structure This construction is known as IPMSM interior PMSM Figure 6 Different PM motor constructions a b c SM PMSMs inherently have an isotropic structure which means that the direct and quadrature inductances Lg and Lg are the same Usually their mechanical structure allows a wider airgap which in turn means lower flux weakening capability On the other hand IPMSMs show an anisotropic structure with Ly lt Lg typically slight in the b construction called inset PM motor strong in the c configuration called buried or radial PM motor This peculiar magnetic structure can be exploited as explained in Section 3 4 to produce a greater amount of electromagnetic torque their fine mechanical structure usually shows a narrow airgap thus giving good flux weakening capability This firmware library is optimized for use in conjunction with SM PMSMs and IPMSMs machines Doc ID 18458 Rev 2 ky UM1052 Overview of the FOC and other implemented algorithms 3 3 PMSM fundamental equations Figure 7 Assumed PMSM reference frame convention With reference to Figure 7 the motor voltage and flux linkage equations of a PMSM SM PMSM or IPMSM are generally expressed as Dave Vabe slabe dt L Lms Lis Lms ae sin 2n L L sin 9 22 Nabe a List Liris ma labo T 39 27 L L sin 9
34. high to be sustainable by the microcontroller Under volt This fault occurs when the DC bus voltage is below the configured threshold This fault occurs when the DC bus voltage is above the configured threshold If Over volt the dissipative brake resistor management is enabled this fault is not raised This fault occurs when the heat sink temperature is above the configured Over temp threshold 4 Doc ID 18458 Rev 2 86 122 LCD user interface UM1052 8 2 4 Note 87 122 e Execute encoder initialization If the firmware is configured to use the encoder as primary speed sensor or auxiliary speed sensor the encoder alignment button is also present In this case the alignment of the encoder is required only once after each reset of the microcontroller Dual control panel page This page is present only if the firmware is configured for dual motor drive To enter the dual control page press the joystick RIGHT from configuration and debug page It is possible to navigate between focusable controls present in the page pressing joystick UP DOWN The dual control panel page shown Figure 65 is used to send commands and get feedback from both motors It is divided into three groups Groups A and group B depend on speed torque settings The group content is updated on the fly when the control mode torque speed is changed in the configuration and debug page The control present in group A is related t
35. igs Pairs that minimizes the current consumption for each required torque see Figure 8 This feature can be activated through correct settings in h parameter files generated by the ST MC Workbench GUI used to initialize the MC Application during its boot stage In confidential distribution the classes that implement the MTPA algorithm are provided as compiled object files The source code is available free of charge from ST on request Please contact your nearest ST sales office Doc ID 18458 Rev 2 20 122 Overview of the FOC and other implemented algorithms UM1052 21 122 Figure 8 MTPA trajectory ome TPA trajectory Tn Nominal Torque 0 8 Tn 06 Tn 04 Tn 0 2 Tn me lin Current limit circle Figure 9 shows the MTPA strategy implemented inside a speed control loop In this case iq output of the PI regulator is fed to the MTPA function iy is chosen by entering the linear interpolated trajectory Figure 9 8MTPA control MTPA control Doc ID 18458 Rev 2 ky UM1052 Overview of the FOC and other implemented algorithms 3 5 In all cases by acting on the direct axis current igs the magnetic flux can be weakened so as to extend the achievable speed range As a consequence of entering this operating region the MTPA path is left see Section 3 6 Flux weakening control for details about the flux weakening strategy In conclusion by regulating the
36. its Systick Handler and PendSV Handler as resources Alternatively an Operating System can be used for this purpose as is done in the FreeRTOS based demonstration project The timebase should provide the clocks listed in Table 13 Table 13 Integrating the MC Interface in a user project 2 Number Function to call Periodicity Priority Preemptiveness 4 TSK_LowFrequencyTask 10 ms Base Yes over non MC functions Equal to that set in ng TSK MediumFrequencyTa ST MC Workbench Higher than 1 Yes over 1 sk speed regulation rate a Yes over 1 3 TSK_SafetyTask 0 5 ms Higher than 2 z optional over 2 include source files Note In the following code stands for Installation Folder 3 Libraries CMSIS CM3 CoreSupport core_cm3 c Libraries CMSIS CM3 DeviceSupport ST STM32F10x system_stm32f1 Ox c Libraries CMSIS CM3 DeviceSupport ST STM32F10x startup XxXxX st artup stm32f10x YYY s XXX according to IDE YYY according to device Project stm32f10x_it c removing conditional compilation can be modified Project System amp Drive Params stm32 10x_MC_it c GUI generated according to system parameters Libraries STM32F10x_StdPeriph_Driver src standard peripheral driver sources as needed include paths Note In the following code stands for Installation Folder 75 122 Libraries CMSTS CM3 CoreSupport Libraries CMSIS CM3 DeviceSu
37. motor currents through their ig and iy components FOC manages to regulate the PMSM torque and flux Current regulation is then achieved by means of what is usually called a synchronous frame CR PWM Feed forward current regulation The feed forward feature provided by this firmware library aims at improving the performance of the CR PWM current regulated pulse width modulation part of the motor drive It calculates in advance the vg and vg stator voltage commands required to feed the motor with the i and ig current references By doing so it backs up the standard PID current regulation see Figure 10 The feed forward feature works in the synchronous reference frame and requires good knowledge of some machine parameters such as the winding inductances Ly and Lg or Ls if an SM PMSM is used and the motor voltage constant Kg The feed forward algorithm has been designed to compensate for the frequency dependent back emf s and cross coupled inductive voltage drops in permanent magnet motors As a result the q axis and d axis PID current control loops become linear and a high performance current control is achieved As a further effect since the calculated stator voltage commands vg and vg are compensated according to the present DC voltage measurement a bus voltage ripple compensation is accomplished Doc ID 18458 Rev 2 22 122 Overview of the FOC and other implemented algorithms UM1052 3 6 23 12
38. motor electrical angle This variable is present only if a state Obs El Angle observer sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs Rotor Speed Observed motor speed This variable is present only if a state observer sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Observed alpha component of motor phase s current expressed in alpha beta Obs lalpha reference This variable is present only if a state observer sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Observed beta component of motor phase s current expressed in alpha beta Obs Ibeta reference This variable is present only if a state observer sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs B emf alpha Observed alpha component of motor BEMF expressed in alpha beta reference This variable is present only if a state observer sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs B emf beta Exp B emf level Observed beta component of motor BEMF expressed in alpha beta reference This variable is present only if a state observer sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor The expected Bemf squared level Obs B emf level The observed Bemf squared level Do
39. motor single dual FOC software library V3 0 This provides the following Features Architecture Workspace Customization processes Overview of algorithms implemented FOC current sensors speed sensors MC API Demonstrative user project Demonstrative LCD user interface Demonstrative serial communication protocol Advanced developers guide for STM32F 103xx STM32F 100xx PMSM single dual FOC library UM1053 This provides the following Object oriented programming style used for developing the MC library Description of classes that belong to the MC library Interactions between classes Description of tasks of the MCA MC library source documentation Doxygen compiled HTML file This provides a full description of the public interface of each class of the MC library methods parameters required for object creation MC Application source documentation Doxygen compiled HTML file This provides a full description of the classes that make up the MC API User Interface source documentation Doxygen compiled HTML file This provides a full description of the classes that make up the UI Library STM32F 10x Standard Peripherals Library source documentation doxygen compiled html file ST MC Workbench GUI documentation This is a field guide that describes the steps and parameters required to customize the library as shown in the GUI In depth documentation about particular algori
40. selected it is shown in the status bar present at the bottom of the screen field 2 in Figure 64 Commands performed on or feedback from a control are only relative to the active motor e select the control mode field 3 in Figure 64 Two control modes are available speed and torque You can change the control mode from speed to torque and vice versa on the fly even if the motor is already running Doc ID 18458 Rev 2 82 122 LCD user interface UM1052 Figure 64 Configuration and debug page PMSM FOC ver Configuration and debug Motor Ctrl mode Spd Tra Power board st 3 DC Bus volt Heatsink T 35 l DAC Settings Under volt chi a Ng n Fault ack Motor selected MS19 7 1 read the DC bus voltage value field 4 in Figure 64 This control is read only read the heat sink temperature value field 5 in Figure 64 This control is read only e select the variables to be put in output through DAC channels field 6 in Figure 64 These controls are present only if the DAC option is enabled in the firmware The list of variables also depends on firmware settings Table 20 and Table 21 present the list of variables that can be present in these combo boxes depending on the configuration Table 19 shows the conventions used for DAC outputs of Currents Voltages Electrical angles Motor Speed and Observed BEMF Note Table 19 assumes that the DAC voltage range is
41. sensors output state correspondence 3 sensors 120 3 sensors 60 H1 State5 gt State1 gt State 3 gt State1 gt State3 gt State 7 gt State2 gt State6 gt State 4 gt Stateb gt State4 gt State 0 s ai14846 Consequently it is possible to reconstruct the rolling direction of the rotor by comparing the present state with the previous one In the presence of a positive speed the sequence must be as illustrated in Figure 43 Period measurement Although the principle for measuring a period with a timer is quite simple it is important to keep the best resolution in particular for signals such as the one under consideration that can vary with a ratio that can easily reach 1 1000 In order to always have the best resolution the timer clock prescaler is constantly adjusted in the current implementation Doc ID 18458 Rev 2 ky UM1052 Rotor position speed feedback The basic principle is to speed up the timer if the captured values are too low for an example of short periods see Figure 44 and to slow it down when the timer overflows between two consecutive captures see example of large periods in Figure 45 Figure 44 Hall sensor timer interface prescaler decrease Capture q Capture q Capture q Capture q OxFFFF Capture value is too low the prescaler is decreased Ox5500 ampaw ahas ai a es a a a ra pee PAANAN KA Aa
42. tabbed browser callout1 Figure 54 Remember that IDE toolbars and commands always refer to the active project the one whose tab is engraved Figure 54 displays the logical arrangement of files on the left hand side similar arrangement is in folders For each class the MC Library subfolder src contains the source code private contains its private definitions interface contains its public interface obj contains compiled object files of certain classes Doc ID 18458 Rev 2 62 122 Working environment UM1052 6 4 63 122 Figure 54 MC Library project F IAR Embedded Workbench IDE File Edit View Project Simulator Tools Window Help A brief Uncomment define MC CLASS DYNAMIC to m allocation on the contrary static memc a a ig F IMC Library SINGLE DRIVE that case the pool size of each class i Os Libra n link MLibraryConf Static Size definitions 1 Ha Ginterface 6 7 Oi obj 45 define MC CLASS DYNAMIC O private 46 47 ifdef MC LIBRARY DUAL 48 L K stm32f1 Ox_MisraCompliance h 49 defgroup MCLibraryConf Static Static compilati Bi stm32f10xh 504 f E Output 51 4 i 52 1 53 44 54 brief PIRegulatorClass pool dimension Sa 56 define MAX PI NUM l0u 8 M Overview MC Application MC Library UserProject fol Ready MS19349V1 Depending on system characteristics configure the project for single motor d
43. 1 MClnterfaceClass aaa baa the heenbe bs KALA poe eeriuttewnere 71 7 1 1 User commands 00 iaar Ea E E 71 7 1 2 Buffered commands 2 73 7 2 MCTUNINGOC ASS 23822544 Aha AKA a a oaea a BARETA DA LGA MAA 74 7 3 How to create a user project that interacts with the MC API 75 7 4 Measurement units nannaa annaa anaana annaa 77 7 4 1 Rotor angle se sese at ae eee aa ee bee i a Re KAL LG KA eg 77 7 4 2 Rotor speed 1 0 0 nrd stnn bant ra eee 78 7 4 3 Current measurement aaaea ee 78 7 4 4 Voltage measurement anan aa eee 78 8 LCD user interface Xa sidan cease AA ABA KAG NA AA 79 8 1 Running the motor control firmware using the LCD interface 79 8 2 LCD User interface structure 0c eee eee 80 8 2 1 Motor control application layer configuration speed sensor 81 8 2 2 Welcome message 0c c eet tee ee 82 8 2 3 Configuration and debug page eee eee 82 8 2 4 Dual control panel page 2 0 eee 87 8 2 5 Speed controller page 0 cece eee 88 8 2 6 Current controllers page cee eee eee 90 8 2 7 Sensorless tuning STO amp PLL page 20 0c eee eee 93 3 122 Doc ID 18458 Rev 2 ky UM1052 Contents 8 2 8 Sensorless tuning STO amp CORDIC page 0 0a aaaa 95 9 User Interface class overview eee eee eee eee 98 9 1 User interface class CUI 00 00 ees 99 9 2 Us
44. 2 Figure 10 Feed forward current regulation r Kama a aaa z bus voltage measurement AC Mains Bus voltage Or Depending on certain overall system parameters such as the DC bulk capacitor size electrical frequency required by the application and motor parameters the feed forward functionality can provide a major or a poor contribution to the motor drive It is therefore recommended that you assess the resulting system performance and enable the functionality only if a valuable effect is measured This feature can be activated through proper settings in h parameter files generated by the ST MC Workbench GUI used to initialize the MCA during its boot stage In confidential distribution the classes that implement the feed forward algorithm are provided as compiled object files The source code is available free of charge from ST on request Please contact your nearest ST sales office Flux weakening control The purpose of the flux weakening functionality is to expand the operating limits of a permanent magnet motor by reaching speeds higher than rated as many applications require under operating conditions where the load is lower than rated Here the rated speed is considered to be the highest speed at which the motor can still deliver maximum torque Doc ID 18458 Rev 2 ky UM1052 Overview of the FOC and other implemented algorithms The magnetic flux can be weakened by acting on d
45. 2 Project configurations STM32 device part single dual drive a y R selection Viable configuration among existing STM32F103 low density medium density STM32F10B EVAL STM32F1 03 high density XL density Single STM32F10E EVAL motor drive pia 03 high density XL density Dual motor STEVAL IHM022V1 STM32F100 low medium high density STM32F100B EVAL Furthermore if the target is not one of the above mentioned ST evaluation boards or if you want to modify the configurations provided right click on User Project callout 3 Figure 56 gt Option to open the Options dialog box Select the correct device part number callout 4 Figure 56 and edit the linker file callout 5 Figure 56 Note MC SDK default linker files reserve an amount of flash and RAM heap for LCD UI manager see Section 6 5 We recommend that you restore their total size please refer to the STM32 datasheet if you do not need it Once all these settings have been performed the MC Library and MC Application projects are built and you can build the user project callout 6 Figure 56 and download it to the microcontroller memory callout 7 Figure 56 6 6 LCD UI project When an STM32 evaluation board equipped with LCD such as STM3210B EVAL STM3210E EVAL STM32100B EVAL STEVAL IHM022V 1 is in use you can enable the LCD plus Joystick User Interface a useful feature of the demonstration user project that can be used as run time command launcher fine tuning or monitoring to
46. 7 sensor MC_PROTOCOL_REG_OBS_ROT Observed motor speed This variable is related to state observer _SPEED PLL sensor configured as primary or auxiliary speed sensor rv 5 i MC PROTOCOL REG OBS IA Observed alpha component of motor phase s current expressed in EPR alpha beta reference This variable is related to state observer PLL sensor configured as primary or auxiliary speed sensor rv t i i MC_PROTOCOL_REG_OBS_I_B Observed beta component of motor phase s Current expressed in ETA alpha beta reference This variable is related to state observer z PLL sensor configured as primary or auxiliary speed sensor rv Iph mpon i MC PROTOCOL REG OBS BEM Observed alpha compo ent of motor BEMF expressed in a ALPER alpha beta reference This variable is related to state observer PLL sensor configured as primary or auxiliary speed sensor rv t mponent of motor BEMF expr i MC PROTOCOL REG OBS BEM Observed be a component of moto 3 expressed in alpha beta ae reference This variable is related to state observer PLL sensor T configured as primary or auxiliary speed sensor 4 Doc ID 18458 Rev 2 106 122 User Interface class overview UM1052 9 8 107 122 Table 33 Description of relevant DAC variables continued Variable name Description Observed motor electrical angle This variable is related to state
47. 8 indicates the list of the commands Table 38 List of commands Command Command ID Description Start Motor 0x01 Indicates the user request to start the motor regardless the state of the motor Stop Motor 0x02 Indicates the user request to stop the motor regardless the state of the motor Doc ID 18458 Rev 2 114 122 Serial communication class overview UM1052 10 4 115 122 Table 38 List of commands continued Command Command ID Description i th ti f ramp that Stop Ramp 0x03 Indicates the user request to stop the execution of speed ramp tha is currently executed Indicates the user request to start the motor if the motor is still or Start Stop os stop the motor is runs Fault Ack 0x07 Communicates the user acknowledges of the occurred fault conditions Encoder Align 0x08 Indicates the user request to perform the encoder alignment procedure Execute ramp frame The execute ramp frame Figure 83 is sent by the master to the motor control firmware to request the execution of a speed ramps A speed ramps start always from the current motor speed and is defined by a duration and final speed See Figure 84 Figure 83 Execute ramp frame Execute ramp frame Data Acknowledgment frame No errors OR Execute ramp frame PC ama 0x07 0x06 FS_ x DR_LB DR_HB CRC Error Acknowledgment frame BOARD gt OxFF ERROR CODE CRC MS19376V1 Payload length is alway
48. B459 board a positive sequence of the motor phases may be connected to J5 2 1 and 3 3 Run the firmware in encoder configuration and turn by hand the rotor in the direction assumed to be positive If the measured speed shown on the LCD is positive the connection is correct otherwise it can be corrected by simply swapping and rewiring the encoder output signals If this is not practical a software setting may be modified instead using the ST MC Workbench GUI see GUI help file Alignment settings Quadrature encoder is a relative position sensor Considering that absolute information is required for performing field oriented control it is necessary to somehow establish a 0 position This task is performed by means of an alignment phase Section 8 2 3 Configuration and debug page callout 9 in Figure 64 Configuration and debug page and shall be carried out at first motor startup and optionally after any fault event It consists of imposing a stator flux with a linearly increasing magnitude and a constant orientation If properly configured at the end of this phase the rotor is locked in a well known position and the encoder timer counter is initialized accordingly Doc ID 18458 Rev 2 ky UM1052 Working environment 6 Working environment The working environment for the Motor Control SDK is composed of e PC A third party integrated development environment IDE A third party C compiler JTAG SWD interface for
49. Core Ha E Timebase c 5 Simulator E UlTask c i Angel Device 5T STM32F10xx8 Tr GDB Server TAR ROM monitor J Lin J Trace LMI FTDI Marrainnr Little Endian mode 1 MS19345V1 The Motor Control folder contains the MC API and interfaces of classes that may also be useful in the user s application such as PI Digital Output reference frame transformation The Std project template folder contains STM32F10x Standard Peripherals Library e CMSIS library startup and vector table files for EWARMV5 toolchain e IC drivers LCD IOE SD card used in STM32 evaluation boards All these files belong to V3 3 0 distribution of the STM32 Standard Peripheral Library package updates available from STMicroelectronics Web site www st com This demonstration user project exploits the features offered by the User Interface Library see Section 9 User Interface class overview for further details Four project configurations callout 2 Figure 56 User project are provided one for each STM32 evaluation board that has been tested with the MC SDK e STM32F10B EVAL STM32F10E EVAL STM32F100B EVAL e STEVAL IHM022V1 65 122 Doc ID 18458 Rev 2 ky UM1052 Working environment If the target is one of these boards just select its name from the combo box Otherwise the LCD UI should be disabled using the ST MC Workbench GUI and the choice is to be done according to Table 12 Table 1
50. Current feedback phase B N i pi io e Sampling start i i i u Si i e Current feedback phase C LUR ALE A An hA e Sampling end m Space available for sampling lt T en s Case 3 ADutyA lt DT Ty Ts 2 and ADuty 4 p5DT TptTs In this case it is no more possible to sample the currents during Phase A low side switch on Anyway the two currents can be sampled between Phase B low side switch on and Doc ID 18458 Rev 2 38 122 Current sampling UM1052 39 122 Phase A high side switch off The choice was therefore made to sample the currents Ts us before of phase A high side switch off see Figure 28 Figure 28 ADutyA lt DT Ty Ts 2 and ADuty 3 gt DT TptTs 1 ADuty 2 i Low side phase A aa High side phase A ii ia Low side phase B pat Ei High side phase B id a ry rs i T H 1 EN AGES i Current feedback phase B 1 j NA a og ed e Sampling start Current feedback phaseC EU iy Sampling end Space available for sampling mag imi lt I Case 4 ADuty lt DT Ty Ts 2 and ADuty 3 lt DT TR Ts In this case the duty cycle applied to Phase A is so short that no current sampling can be performed between the two low side commutations Furthermore if the difference in duty cycles between Phases B and A is not long enough to allow the A D conversions to be performed between Phase B low side switch on and Phase A high side switch off it is impossible to sample th
51. L R SystemNDriveParams h 25 F k stm32f1 Ox h i 26 include MCInterfaceClass h C Application MC Library UserProject Ga Ap MiTnterfacellaaaPrizate h NUM THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE WITH CODING INFORMATION REGARDING THEIR PR TIME AS A RESULT SIMICROELECTRONICS SHAL DIRECT INDIRECT OR CONSEQUENTIAL DAMAGES FROM THE CONTENT OF SUCH FIRMWARE AND OR T CODING INFORMATION CONTAINED HEREIN IN CON BE as 21 Includes 22 include FOCDriveClass h 23 include SpeednTorqCtrlClass h 24 include StateMachineClass h MS19350 1 Project source files are arranged in the logical folder MC Application The MC Library Interface folder contains all the interfaces of each class belonging to the MC Library The System and Drive Parameters folder contains the header files that should be filled in so as to describe characteristics and parameters of user s system 2 To adjust system and drive parameters callout 2 Figure 55 separately for Motor 1 and Motor 2 edit the header files manually or generate them using the ST MC Workbench GUI The header file SystemNDriveParams h arranges all these parameters in the form of constant structures for object initialization so that the MC Application can create the controls required during the initial run time boot 3 After these settings have been performed build the Motor Control Interface callout 3 Figure 55 The output file MC Interface
52. M period is subdivided into 7 subperiods see Figure 31 During three subperiods I IV VII the current through the shunt resistor is zero During the other subperiods the current through the shunt resistor is symmetrical with respect to the center of the PWM Doc ID 18458 Rev 2 40 122 Current sampling UM1052 41 122 For the conditions showed in Figure 31 there are two pairs subperiods II and VI during which ighynt is equal to ic subperiods Ill and V during which igpunt is equal to i4 So under these conditions it is possible to reconstruct the three phase current through the motor from the sampled values ais isnunt Measured during subperiod Ill or V ici ishunt Measured during subperiod Il or VI J ip iy ic Figure 31 Single shunt current reading 1 Il III IV V VI VII i i ai15136 But if the stator voltage demand vector lies in the boundary space between two space vector sectors two out of the three duty cycles will assume approximately the same value In this case the seven subperiods are reduced to five subperiods Under these conditions only one current can be sampled the other two cannot be reconstructed This means that it is not possible to sense both currents during the same PWM period when the imposed voltage demand vector falls in the gray area of the space vector diagram represented in Figure 31 Single shunt current reading Table 6 Single
53. MC_it c 9 9 How to configure the user defined DAC variables Two user defined DAC variables can be put as analog output These variables enable custom debugging on variables that change in real time and monitor the correlation with relevant motor control values such as real measured currents You cannot put more than two DAC variables motor control predefined or user defined in the output To store the user value in a user defined DAC variable follow these steps 1 Obtain the DAC objects oDAC through the GetDAC function exported by UlTask h 2 Call the Ul DACSetUserChannelValue method of CUI object to update the content of user defined DAC variable UI_DACSetUserChannelValue oDAC 0 hUser1 In this case the value hUser1 is set in the first 0 user defined DAC variable 3 Configure user defined DAC variables to be put in output using the UI DACChannelConfig method or put the user defined variables in the output using the LCD Joystick interface see Section 8 2 3 Configuration and debug page UI DACChannelConfig CUI oDAC DAC_CHO MC PROTOCOL REG DAC USER1 4 The user value is physically put in the output when Ul DACExec is executed The UlTask c performs the following UI_DACExec CUI ODAC ky Doc ID 18458 Rev 2 108 122 Serial communication class overview UM1052 10 109 122 Serial communication class overview Applications on the market that require an electrica
54. SpeedRamp MCI_ExecTorqueRamp or MCI_SetCurrentReferences Buffered commands void MCI ExecSpeedRamp CMCI oMCI int16 t hFinalSpeed uint16 t hDurationms sets the control mode in speed control generates a ramp of speed references from real speed to hFinalSpeed parameter to be expressed as mechanical rotor speed tenth of hertz The ramp execution duration is hDurationms parameter to be expressed in milliseconds If hDurationms is set to O a step variation is generated This command is only executed when the state machine is in the START_RUN or RUN state The user can check the status of the command calling the MCI_IsCommandAcknowledged method void MCI_ExecTorqueRamp CMCI oMCI int16 t hFinalTorque uint16 t hDurationms sets the control mode in torque control generates a ramp of torque references from real torque to hFinalTorque parameter to be expressed as s16A The ramp execution duration is hDurationms parameter to be expressed in milliseconds If hDurationms is set to O a step variation is generated This command is only executed when the state machine is in the START_RUN or RUN state The user can check the status of the command calling the MCI_IsCommandAcknowledged method void MCI SetCurrentReferences CMCI oMCI Curr_Components Iqdref sets the control mode in torque control external see Advanced developers guide for STM32F103xx STM32F 100xx PMSM singl
55. SysTick timer easy scheduler based user project Available User Interface options and combinations of them e LCD C programmed plus joystick Serial communication protocol e Drive system variables logging displaying via SPI DAC DAC peripheral available only on STM32F100xx or STM32F103xx High Density and XL Density RC filtered PWM signal option where not available Doc ID 18458 Rev 2 ky UM1052 MC software development kit architecture MC software development kit architecture Figure 1 shows the system architecture The Motor Control SDK has a four layer structure STM32F 10x standard peripherals library and CMSIS library e Motor Control Library Motor Control Application e Demonstration user project Figure 1 MC software library architecture Demo User Project Demo FreeRTOS User Project StartMotor StopMotor O MC API ExecSpeedRamp Q COD CSpeedSensor croc CFW entSensor CHall C3shunt CEncoder C1shunt CMTPA MS19303V1 From the bottom layer upwards The STM32F 10x Standard Peripherals Library is an independent firmware package that contains a collection of routines data structures and macros that cover the features of the STM32 peripherals Version 3 3 0 is included in the MC SDK The STM32F 10x Standard Peripherals Library is CMSIS and MISRA C compliant Visit www st com stm32 for complete documentation The Motor Control Library is a wide collection of cl
56. TAM a ana NGA aa Aira ea nG bata a Sed ee a Rae Ge ee 116 Get revup data frame tees 116 Revup sequence et eee 117 Set revup data frame eee 117 Set current reference frame cee tee ee 118 Doc ID 18458 Rev 2 ky UM1052 List of tables List of tables Table 1 Table 2 Table 3 Table 4 Table 5 Table 6 Table 7 Table 8 Table 9 Table 10 Table 11 Table 12 Table 13 Table 14 Table 15 Table 16 Table 17 Table 18 Table 19 Table 20 Table 21 Table 22 Table 23 Table 24 Table 25 Table 26 Table 27 Table 28 Table 29 Table 30 Table 31 Table 32 Table 33 Table 34 Table 35 Table 36 Table 37 Table 38 Table 39 Table 40 Referent eS smrada aa i aa aa aha konaa a Pa aeaa e a a a E a a e a 17 Sector identification 20 0 ene enn e eens 30 3 shunt current reading used resources single drive F103 LD MD 35 3 shunt current reading used resources single drive or dual drive F103 HD 36 Current through the shunt resistor nnana 0 00 cc eee eee eee 40 Single shunt current reading used resources single drive F103 F100 LD MD 41 Single shunt current reading used resources single or dual drive F103HD 42 ICS current reading used resources single drive F103 LD MD 47 ICS current reading used resources single or dual drive F103 HD 47 Legend for Fig
57. To convert a current expressed in s16A to current expressed in Ampere use the formula Current A Current s16A Vdd micro V 65536 Rshunt Ohm AmplificationNetworkGain Curr_Components MCI_GetCurrentsReference CMCI oMCI returns stator current references and Id in s16A To convert a current expressed in s16A to current expressed in Ampere use the formula Current A Current s16A Vdd micro V 65536 Rshunt Ohm AmplificationNetworkGain int16 t MCI_GetPhaseCurrentAmplitude CMCI oMCI returns the motor phase current amplitude 0 to peak in s16A To convert a current expressed in s16A to current expressed in Ampere use the formula Current A Current s16A Vdd micro V 65536 Rshunt Ohm AmplificationNetworkGain int16 t MCI_GetPhaseVoltageAmplitude CMCI oMCT returns the applied motor phase voltage amplitude 0 to peak in s16V To convert a voltage expressed in Doc ID 18458 Rev 2 72 122 MC application programming interface API UM1052 71 2 73 122 s16V to voltage expressed in Volt use the formula PhaseVoltage V PhaseVoltage s16V Vbus V sart 3 32767 STC Modality t MCI_GetControlMode CMCI oMCI returns the present control mode speed mode or torque mode int16 t MCI GetImposedMotorDirection CMCI oMCI returns the motor direction imposed by the last command MCI_Exec
58. a Acknowledgment frame The size of pay load depends on the Reg Id and is equal to the Payload length present in Table 37 minus 1 The value is returned starting from least significant byte to most significant byte Error Acknowledgment frame if the operation has not been successfully completed by the firmware The payload of this Error Acknowledgment frame is always 1 The list of error codes are shown in Table 36 Execute command frame The execute command frame Figure 82 is sent by the master to the motor control firmware to request the execution of a specific command Figure 82 Execute command frame Execute command frame Data Acknowledgment frame No errors BOARD OxFO 0x00 CRC OR Execute command frame PC 0x03 0x1 COMMAND ID CRC Error Acknowledgment frame BOARD OxFF 0x1 ERROR_CODE CRC MS19375V1 Payload length is always 1 Command Id indicates the requested command See Table 38 The Acknowledgment frame can be of two types e Data Acknowledgment frame if the operation has been successfully completed In this case the returned value embedded in the Data Acknowledgment frame is an echo of the same Command ld The size of payload is always 1 e Error Acknowledgment frame if the operation has not been successfully completed by the firmware The payload of this Error Acknowledgment frame is always 1 The list of error codes are shown in Table 36 Table 3
59. al FOC drive The following sections provide details on this The equivalent workspace based on FreeRTOS is located in Installation folder FreeRTOS Project EWARM RTOS_Workspace eww ky Doc ID 18458 Rev 2 60 122 Working environment UM1052 61 122 Figure 52 Workspace overview IAR Embedded Workbench IDE File Edit View Project Tools Window Help UserProject STEVAL HM0221 Files 8 Workspace MC Application RELEASE MC Library SINGLE DRIVE UserProject STEVAL IHM022V1 saba Overview MC Application MC Library UserProject a EE ROL oT SEER TER ECOOTETES file main c 3 author IMS Systems Lab and Techni version Betail 0 date 03 Feb 2011 15 57 Main program body PE copy THE PRESENT FIRMWARE WHICH IS FOR G WITH CODING INFORMATION REGARDING T TIME AS A RESULT SIMICROELECTRONI DIRECT INDIRECT OR CONSEQUENTIAL D FROM THE CONTENT OF SUCH FIRMWARE A CODING INFORMATION CONTAINED HEREIN Hoh kh hh hh Hh HR KM lt hZ gt lt ccenter gt ecopy COPYRIGHT 2011 S x 2 Ln 1 Col 1 N MS19319V1 Section 6 2 MC SDK customization process provides the procedure for customizing the Motor Control SDK MC SDK customization process This section explains how to customize the Motor Control SDK using IAR EWARM IDE so that it corresponds with the user s current system 1 Using the ST MC Workbench GUI enter the page information to reflect the system
60. ally given by the value S16 MAX 32767 which produces the maximum output voltage magnitude corresponding to a duty cycle going from 0 to 100 Nevertheless when using a single shunt or 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 S16 MAX depending on PWM switching frequency when using a single shunt or three shunt resistor configuration The Circle Limitation function performs the discussed stator voltage components saturation as illustrated in Figure 21 Figure 21 Circle limitation working principle S16 MAX r MMI S16 MAX ai14845 Doc ID 18458 Rev 2 32 122 Overview of the FOC and other implemented algorithms UM1052 33 122 Vg and Vg represent the saturated stator voltage components to be passed to the Reverse Park transformation function while Vg and V are the outputs of the PID current controllers From geometrical considerations it is possible to draw the following relationship va MMI S16_MAX Vq es 3 V q 2a MMI S16 MAX FG V In order to speed up the computation of the above equations while keeping an adequate resolution the value MMI 516 MAX gt V is computed and stored in a look up table for different values of Kal
61. am is stalled in a trap in UlTask c line 133 Doc ID 18458 Rev 2 ky UM1052 MC application programming interface API 7 MC application programming interface API The Motor Control Application is built on top of the Motor Control Library On the condition that parameter files are generated by the ST MC workbench GUI or manually edited starting from default for the purpose of describing the system configuration e auser project such as the one included in the SDK or any other one that complies with the guidelines described in Section 7 3 How to create a user project that interacts with the MC API is in place The MCA grants the user layer the execution of a set of commands named the MC Application Programming Interface MC API The MC API is divided into two sections and is included in two files MCInterfaceClass h and MCTuningClass h MCInterfaceClass details in Section 7 1 holds the principal high level commands while MC TuningClass details in Section 7 2 acts as a gateway to set and read data to and from objects such as sensors PI controllers belonging to the Motor Control Application A third section belongs to MC API MCtask h it holds the MCboot function and tasks low medium high frequency and safety to be clocked by the user project see Section 7 3 How to create a user project that interacts with the MC API for details When the user project calls function MCboot oMCI oMCT the Motor Co
62. ampling stator currents in three shunt resistor topology 36 4 2 Current sampling in single shunt topology aa 40 4 2 1 Definition of the noise parameter and boundary zone 43 4 3 Current sampling in isolated current sensor topology 46 5 Rotor position speed feedback 0000 cee eee eens 48 5 1 The sensorless algorithm 00 00 cee ee 48 5 1 1 A priori determination of state observer gains 49 5 2 Hall sensor feedback processing a 51 ky Doc ID 18458 Rev 2 2 122 Contents UM1052 5 2 1 Speed measurement implementation a 51 5 2 2 Electrical angle extrapolation implementation 53 5 2 3 Setting up the system when using Hall effect sensors 54 5 3 Encoder sensor feedback processing aaa 56 5 3 1 Setting up the system when using an encoder 57 6 Working environment c eee eee eee 58 6 1 Motor control workspace 2 ana ka haw RE cn de ee Sek eee TARA dened x 59 6 2 MC SDK customization process cece eee 61 6 3 Motor control library project confidential distribution 62 6 4 Motor control application project 2 eee eee 63 6 5 Yser project daa GREAT ANA edesauetacats bese Che BAGA 64 66 LEDUDPINEO aa Banawa aaa Ba aY Gene KANDADO KENA GS KAPAG UAE 66 7 MC application programming interface API 70 7
63. anages a numerical value It can be read only or read write A read only edit box has a gray background and cannot be focusable A read write edit box has a white background and can be focusable When a read write edit box is focused it can be activated for modification by Edit box pressing JOYSEL An activated read write edit box has a green background and its value can be modified pressing and or keep pressed joystick UP DOWN rpm When joystick UP is kept pressed the value is increased with a constant acceleration When joystick DOWN is kept pressed the value is decreased with a constant acceleration The new value is set to the motor control related object instantaneously when the value changes unless otherwise mentioned in this manual The control can be deactivated by pressing JOYSEL again Manages a list of predefined values The values associated to a combo box are text strings that correspond with different configurations or options of the firmware For example Speed or Torque control mode The combo box is always Combo box focusable and when focused can be activated for modification by pressing JOYSEL An activated combo box has a green background and its value can be Speed VI modified by pressing the joystick UP DOWN The combo box values are circular Going UP from the first value selects the last value and vice versa The new value is set to the motor control related object instantaneously when the value changes unl
64. and Vg stator voltage components 0 5 Vbeta Valfa Figure 19 SVPWM phase voltage waveforms 100 0 60 120 180 240 300 360 Phase A Phase B Phase C Sector 1 Sector 2 Sector 3 Sector 4 Sector 5 Sector 6 Doc ID 18458 Rev 2 UM1052 Overview of the FOC and other implemented algorithms 3 10 With the following definitions for U 3xTxV Ug Tx Vp and X Up a Y 2508 and z be literature demonstrates that the space vector sector is identified by the conditions shown in Table 2 Table 2 Sector identification Yz0 Y gt 0 Z lt 0 Z 0 Z lt 0 Z 0 X lt 0 X gt 0 X lt 0 X gt 0 Sector V IV Ill Vi l II The duration of the positive pulse widths for the PWM applied on Phase A B and C are respectively computed by the following relationships _T X Z 2 Sector I IV ta tp ta Z tc tp X Sector Il V ta aga te eZ te ta Y Sector Ill VI t a aa tg tc X to ta Y where T is the PWM period Now considering that the PWM pattern is center aligned and that the phase voltages must be centered at 50 of duty cycle it follows that the values to be loaded into the PWM output compare registers are given respectively by T 1 24X Z Sector I IV TimePhA TimePhB TimePhA Z TimePhC TimePhB X 4 2 Sector Il V TimePhA Tbe TimePhB TimePhA Z TimePhC TimePhA Y Les 2 Y X
65. ant motor control 0x02 variable See Get register frame Execute command frame It is used to send a command to the motor control 0x03 i object See Execute command frame 0x06 Get board info It is used to retrieve the information about the firmware currently running on the microcontroller 0x07 Exec ramp It is used to execute a speed ramp See Section 10 4 Execute ramp frame 0x08 Get revup data It is used to retrieve the revup parameters See Section 10 5 Get revup data frame Doc ID 18458 Rev 2 110 122 Serial communication class overview UM1052 Note 10 1 111 122 Table 35 Starting frame codes continued Frame ID Description 0x09 Set revup data It is used to set the revup parameters See Section 10 6 Set revup data frame Ox0A Set current references It is used to set current reference See Section 10 7 Set current references frame In case of dual motor control the target of the frame action is only the active motor drive The master can select the target motor sending a set register frame with a Reg Id equal to zero Target motor register and the value of new selected motor See Section 10 1 Set register frame The set register frame Figure 80 is sent by the master to write a value into a relevant motor control variable Figure 80 Set register frame Set register frame PC 0x01 PAYLOAD LENGTH REG ID REG IB REG HB CRC Data Acknowled
66. asses that describe the functionality of elements involved in motor control such as speed sensors current sensors algorithms Each class has an interface which is a list of methods applicable to objects of that class Figure 2 is a conceptual representation of the library Two distributions of the Motor Control Library are available e Web distribution available free of charge at www st com where the Motor Control Library is provided as a compiled lib file e Confidential distribution available free of charge on demand by contacting your nearest ST sales office or support team Source classes files are provided except for ST protected IPs which are furnished as compiled object files Source files of protected IPs can also be provided free of charge to ST partners upon request Contact your nearest ST office or support team for further information Doc ID 18458 Rev 2 10 122 MC software development kit architecture UM1052 11 122 Figure 2 Motor control library Motor Control Library CSpeedSensor CStateMachine New New GetMechanicalSpeed GetState GetElectricalAngle NextState CFOCDrive New CalcCurrentReferences CurrentController MS19304V1 The Motor Control Library uses the lower STM32F 10x Standard Peripheral Library layer extensively for initializations and settings on peripherals Direct access to STM32 peripheral registers is preferred when optimizations in terms of execution spee
67. ation Each sensor is defined using 4 bits The values Ul SCODE xxx are exported by UserlnterfaceClass h See Table 31 The first 4 bit defines the main speed and position sensor The second 4 bit defines the auxiliary speed and position sensor Figure 75 User interface configuration bit field 4bit 4bit 8bit 8bit 8bit Main sensor Auxiliary sensor Reserved Reserved CFG 8bit Reserved PLL Tuning Setld in Spd Speed Kd Flux weakening The remaining bit field values Ul CFGOPT xxx are exported by UserlnterfaceClass h See Table 32 Doc ID 18458 Rev 2 ky UM1052 User Interface class overview Note 9 3 sa To configure the user interface object the configuration should be passed in the UI Init function as 5th parameter The 5th parameter of UI Init function is an array of configuration values one for each motor drive The 32 bit configuration value is automatically computed by preprocessor in the Parameters conversion h file basing on the configuration present in the System 8 Drive Params folder It can be manually edited by the user Table 31 User interface configuration Sensor codes Code Description UI SCODE HALL This code identifies the Hall sensor PJ UI_SCODE_ENC This code identifies the Encoder sensor UI SCODE STO PLL This code identifies the State observer PLL sensor UI SCODE STO CR This code identifies the State observer
68. ations 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 synchronized with the counter overflow as shown in Figure 26 Figure 26 Low side Phase A duty cycle gt DT Ty ADuty Counter overflow Low side phase A High side phase A 7 a Low side phase B Far ag n High side phase B 1 i Sy i i UG T i at NA Current feedback phase g 4f i NG I H i i Sampling start Current feedback phase C A PEN KAA i e Sampling end EEE Space available for sampling Case 2 DT TytTs 2 lt ADuty4 lt Dr Ty and ADuty 4g lt Dr TRtTs With the increase in modulation index ADuty can have values smaller than D7 Ty Sampling synchronized with the counter overflow could be impossible In this case the two currents can still be sampled between the two Phase A low side commutations but only after the counter overflow Consider that in order to avoid the acquisition of the noise induced on the phase B current feedback by phase A switch commutations it is required to wait for the noise to be over Ty See Figure 27 Figure 27 DT TytTs 2 lt ADuty4 lt D Ty and ADuty ap lt Dr TRt Ts ADuty ADuty it at Low side phase A High side phase a 1 ay 1 L k i i Low side phase B oF io High side phase B ro an se pnase Lg a
69. c ID 18458 Rev 2 84 122 LCD user interface UM1052 85 122 Table 20 List of DAC variables continued Variable name User 1 Description User defined DAC variable Section 9 9 describes how to configure user defined DAC variables User 2 User defined DAC variable Section 9 9 describes how to configure user defined DAC variables Observed variables Obs in Table 20 refer to a configuration that uses only one sensorless speed sensor confi sensor When the f gured as primary or auxiliary sensor and refers to that state observer irmware is configured to use two sensorless speed sensors state observer plus PLL and state observer plus CORDIC as primary and auxiliary speed sensor the DAC variables related to each state observer sensor are indicated in Table 21 Table 21 DAC variables related to each state observer sensor when two state observer speed sensors are selected Variable name Obs El Ang PLL Description Observed motor electrical angle This variable is present only if a state observer plus PLL sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs lalpha PLL Obs Rot Spd PLL Observed alpha component of motor phase s current expressed in alpha beta reference This variable is present only if a state observer plus PLL sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Ob
70. c eee eee 49 PMSM back emfs detected by the sensorless state observer algorithm 50 Hall sensors output state correspondence cece tee 51 Hall sensor timer interface prescaler decrease cee eee 52 Hall sensor timer interface prescaler increase 0c eee eee 52 TIMx_IRQHandler flowchart 53 Hall sensor output transitions eee 54 60 and 120 displaced Hall sensor output waveforms eee eee 55 Doc ID 18458 Rev 2 5 122 List of figures UM1052 Figure 49 Figure 50 Figure 51 Figure 52 Figure 53 Figure 54 Figure 55 Figure 56 Figure 57 Figure 58 Figure 59 Figure 60 Figure 61 Figure 62 Figure 63 Figure 64 Figure 65 Figure 66 Figure 67 Figure 68 Figure 69 Figure 70 Figure 71 Figure 72 Figure 73 Figure 74 Figure 75 Figure 76 Figure 77 Figure 78 Figure 79 Figure 80 Figure 81 Figure 82 Figure 83 Figure 84 Figure 85 Figure 86 Figure 87 Figure 88 6 122 Determination of Hall electrical phase shift a 56 Encoder output signals counter operation 0 000 cee eee 57 MC workspace structure 2 0 eee 60 Workspace OVEIVIEW 6 nett 61 Workspace batch build 2 0 ete ee 62 MC Library project 0 aaaea 63 Motor control application project 0 aaua aaua 64 SEN arare aro pa som ante dh athe a ae a aha Bhai aes AGE aed ee eae 65 Flash loader wizard Screen
71. ch DAC variable can be selected to be output to a DAC channel The DAC channel is physically put in the output by calling the Ul DACExec method Using the DAC manager 1 Obtain the oMCT and oMCl object through GetMCIList GetMCTList functions exported by MCTasks h The oMCI and oMCT are two arrays of objects CMCI OMCI MC NUM CMCT oMCT MC NUM GetMCIList oMCI GeMCTList oMCT 2 instantiate and initialize CDACx UI objects Choose the correct CDACx_UI object based on the hardware setting CDACx UI oDAC U nit CUI oDAC DACT_NewObject MC_NULL MC_NULL oMCIList oMCTList pUICfg bMCNum UI DACInit CUI oDAC Note that you must call both the Ul Init and Ul DACInit pUICfg is the user interface configurations array See Section 9 2 User interface configuration 3 Configure the DAC variables for each DAC channel UI DACChannel UI DACChannel Config CUI oDAC DAC CHO MC PROTOCOL REG Config CUI oDAC DAC CH1 MC PROTOCOL REG I B Doc ID 18458 Rev 2 UM1052 User Interface class overview In this case the motor current la and Ib will be put in output 4 Periodically update the DAC output by calling the Ul DACExec method that performs the update of DAC channel into the physical output These functions are performed inside UlTask c For the update the DAC outputs also uses the stm32f10x_
72. class overview UM1052 9 6 9 7 105 122 Using the motor control protocol 1 Obtain the oMCT and oMCI object through GetMCIList GetMCTList functions exported by MCTasks h The oMCI and oMCT are two arrays of objects CMCI oMCI MC_NUM CMCT oMCT MC_NUM GetMCIList oMCI GeMCTList OMCT MCP parameters Frame parameters and USART parameters are defined in USARTParams h and can be modified if required Instantiate and initialize CMCP_UI CFCP COM objects CMCP_UI oMCP MCP_NewObject MC_NULL amp MCPParams CFCP oFCP FCP_NewObject amp FrameParams_str CUSART_COM oUSART USART_NewObject amp USARTParams_str FCP Init oFCP CCOM oUSART MCP_Init oMCP oFCP s fwVer UI_Init CUI oMCP bMCNum oMCIList oMCTList pUICfg Note that you must call both MCP Init and UI Init pUICfg is the user interface configurations array See Section 9 2 User interface configuration s _fwVer is a string containing the Firmware version and Release version It is separated by the 0x0 character that will be sent back to PC after a get firmware info command Manage the serial communication time out After the first byte is received by the microcontroller a timeout timer is started If all the expected bytes of the frame sequence are received the timeout counter is stopped On the contrary if the timeout occurs the timeout event must be handled calling Exec UI IRQ Handler UI_IRQ_USART 3
73. d ID The command ID has not been recognized 0x08 Overrun error The frame has not been received correctly because the transmission speed is too fast Timeout error The frame has not been received correctly and a time out occurs 0x09 This kind of error occurs usually when the frame is not correct or is not correctly recognized by the firmware Table 37 indicates the following for each of the relevant motor control registers Type u8 8 bit unsigned u16 16 bit unsigned u32 32 bit unsigned s16 16 bit signed 32 32 bit signed e Payload length in Set register frame allowed access R read W write e Regld Table 37 List of relevant motor control registers Register name Type Payload length Access Reg Id Target motor u8 2 RW 0x00 Flags u32 5 R 0x01 Status u8 2 0x02 Control mode u8 2 RW 0x03 Speed reference s32 5 RW 0x04 Speed KP u16 3 RW 0x05 Speed KI u16 3 RW 0x06 Speed KD u16 3 RW 0x07 Torque reference lq s16 3 RW 0x08 Torque KP u16 3 RW 0x09 Torque KI u16 3 RW Ox0A Torque KD u16 3 RW 0x0B Flux reference Id s16 3 RW 0x0C Flux KP u16 3 RW 0x1D Flux Kl u16 3 RW Ox1E Flux KD u16 3 RW Ox1F Observer C1 32 5 RW 0x10 Observer C2 32 5 RW 0x11 Doc ID 18458 Rev 2 112 122 Serial communication class overview UM1052 Table 37 List of relevant motor control registers continued Register name Type Payloa
74. d length Access Reg Id PLL KI u16 3 RW 0x12 PLL KP u16 3 RW 0x13 Flux weakening KP u16 3 RW 0x14 Flux weakening KI u16 3 RW 0x15 Flux weakening BUS Voltage allowed percentage u16 3 RW 0x16 reference Bus Voltage u16 3 R 0x17 Heatsink Temperature u16 3 0x18 Motor Power u16 3 R 0x19 DAC Out 1 u8 2 RW Ox1A DAC Out 2 u8 2 RW 0x1B Speed measured 32 5 0x1C Torque measured Iq s16 3 0x1D Flux measured Id s16 3 Ox1E Flux weakening BUS Voltage allowed percentage u16 3 R Ox1F measured Revup stage numbers u8 2 0x20 0x20 10 2 113 122 Get register frame The get register frame Figure 81 is sent by the master to read a value from a relevant motor control variable Figure 81 Get register frame PC BOARD OR Get register frame 0x02 0x1 REG_ID CRC Data Acknowledgment frame No errors sf oro PAYLOAD LENGTH FEGI mec He ORO Get register frame PC BOARD CC X 0x02 0x1 REG_ID CRC Error Acknowledgment frame OxFF 0x1 ERROR CODE CRC MS19374V1 Payload length is always 1 Reg Id indicates the register to be queried See Table 37 Doc ID 18458 Rev 2 a UM1052 Serial communication class overview 10 3 The Acknowledgment frame can be of two types e Data Acknowledgment frame if the operation has been successfully completed In this case the returned value is embedded in the Dat
75. d or code size are required More information about the Motor Control Library its classes and object oriented programming can be found in the Advanced developers guide for STM32F 103xx STM32F 100xx PMSM single dual FOC library UM1053 The Motor Control Application MCA is an application that uses the Motor Control Library in order to accomplish commands received from the user level This set of commands is specified in its Application Programming Interface API During its boot stage the MCA creates the required controls in accordance with actual system parameters defined in specific h files that are generated by the ST MC Workbench GUI or manually edited It coordinates them continuously for the purpose of accomplishing received commands by means of tasks of proper priority and periodicity More information about the MCA can be found in Section 7 MC application programming interface API and details on tasks and implemented algorithms in the Advanced developers guide for STM32F 103xx STM32F 100xx PMSM single dual FOC library UM1053 At the user level a user project has been implemented to demonstrate how to interact with the MC API to successfully achieve the execution of commands Depending on definable options the user project can act as a Human Interface Device using a joystick buttons and LCD screens as a command launcher through a serial communication protocol as a data logging displaying utility or as a tuning tool
76. d sensor decoding Timbase gt 2 Table 15 Priority configuration overall non FreeRTOS Component MC Library 0 1 2 Preemption priority Timebase MCA clocks 3 4 User 5 6 7 Doc ID 18458 Rev 2 76 122 MC application programming interface API UM1052 Table 16 Priority configuration overall FreeRTOS Component Preemption priority MC Library 0 1 2 3 reserved User only FreeRTOS API 4 5 6 FreeRTOS 7 RTOS priority MCA clock tasks Highest User tasks Lower 7 Include the Motor Control Interface in the source files where the API is to be accessed include MCTuningClass h include MCInterfaceClass h include MCTasks h 8 Declare a static array of type CMCI MC Interface class CMCI oMCI MC_NUM 4 MC NUM is the number of motors to drive 9 Declare a static array of type CMCT MC Tuning class CMCT oMCT MC_NUM MC NUM is the number of motors to drive 10 Start the MC Interface boot process MCboot oMCI 0MCT 11 Send the command to the MC API For example MCI ExecSpeedRamp oMCI 1 100 1000 MCI_StartMotor oMCI 1 after a laps of time MCI_StopMotor oMCI 1 7 4 Measurement units 7 4 1 Rotor angle The rotor angle measurement unit used in the MC API has been named s16degrees being 2r 65536 1s16degree The picture below shows how an angle expressed in rad
77. d to change the speed controller gains in real time Flux wk tuning Used to tune the flux weakening related variables Measured speed with start stop button Composed of two controls that are also present in the current controllers page and in the sensorless tuning page this provides for fast access to the measured speed and to the motor start stop function Figure 66 Speed controllers page PMSM FOC ver 3 0 Speed controller Set point Target speed 7500 Urpm Ramp duration J T006 ns PID gains KP 1000 KI Measured speed 1500 rpm Start Stop H Flux wk tuning BUS amp BUS amp Motor selected 1 MS19359V1 If the firmware is configured as dual motor drive it is possible to know which is the active motor by reading the label at the bottom of the page To change the active motor change the motor field in the configuration and debug page field 1 Figure 66 Table 24 lists the actions that can be performed using this page Table 24 Speed controllers page controls Control Target speed field 1 in Figure 66 Description This sets the final motor speed of a speed ramp for the active motor Motor speed is expressed in RPM The value set in this control is not automatically sent to the motor control related object but it is used to perform a speed ramp execution See Exec button description field 3 in Figure 66 Ramp duration field
78. degrees are resolved into currents i and ip on a stationary reference frame o B Appropriate substitution into the general equations given above yields a as BZ las Zips p J3 In Park s change of variables stator currents i and ips which belong to a stationary reference frame a B are resolved to a reference frame synchronous with the rotor and oriented so that the d axis is aligned with the permanent magnets flux so as to obtain ig and igs Doc ID 18458 Rev 2 ky UM1052 Overview of the FOC and other implemented algorithms 3 10 1 Consequently with this choice of reference we have igs loCOS9 igsino igs luSINO Hip COS0 On the other hand reverse Park transformation takes back stator voltage Va and vg belonging to a rotating frame synchronous and properly oriented with the rotor to a stationary reference frame so as to obtain vy and vp Va VgsC0S90 Vgs S NO Vg Vgs S NO Vgs COS9 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 q and v of the stator voltage producing flux and torque components of the stator current have been independently comput an flux and torque PIDs it is necessary to saturate the magnitude of the resulting vector hi before passing them to the Reverse Park transformation and finally to the SVPWM block The saturation boundary is norm
79. der speed sensor is used It must be called after any system reset and before the first motor start State t MCI_GetSTMState CMCI oMCI returns the state machine status see Figure 59 Further detail is provided in the Advanced developers guide for STM32F 103xx STM32F 100xx PMSM single dual FOC library UM1053 Doc ID 18458 Rev 2 ky UM1052 MC application programming interface API Figure 59 State machine flow diagram DLE FAULT NOW IDLE ALIGNMENT v baa FAULT OVER START ALIGNMENT NG START RUN 4 any state can evolve RUN into FAULT_NOW 4 ANY_STOP Permanent states 4 Pass trou gh states STOP 4 STOP IDLE int16 t MCI_GetMecSpeedRef01Hz CMCI oMCI returns the current mechanical rotor speed reference expressed in tenths of Hertz int16 t MCI_GetAvrgMecSpeed01Hz CMCI oMCT returns the last computed average mechanical speed expressed in tenth of Hertz int16 t MCI GetTorqueRef CMCI oMCT returns the present motor torque reference This value represents the current reference expressed in s16A To convert a current expressed in s16A to current expressed in Ampere use the formula Current A Current s16A Vdd micro V 65536 Rshunt Ohm AmplificationNetworkGain int16 t MCI_GetTorque CMCI oMCTI returns the present motor measured torque This value represents the current expressed in s16A
80. ding decoding algorithms three shunts ST patented single DC link shunt isolated current sensors incremental encoder hall sensors and a sensorless algorithm for rotor position reconstruction When deployed with STM32F103xx High Density XL Density devices Flash memory density between 256 and 512 Kbytes 768 Kbytes and 1 Mbyte the PMSM FOC library enables simultaneous dual FOC of two different motors The library can be customized to suit user application parameters motor sensors power stage control stage pin out assignment and provides a ready to use Application Programming Interface API A user project has been implemented to demonstrate how to interact with the Motor Control API The project provides an LCD User Interface and a USART User Interface represents a convenient real time fine tuning and remote control tool for the motor control application A PC Graphical User Interface GUI the ST Motor Control Workbench allows complete and easy customization of the PMSM FOC library In conjunction with the STM3210B MCKIT motor control starter kit a PMSM motor can be made to run in a very short time using default parameters Basic knowledge of C programming C programming for customizing the LCD User Interface PM motor drives and power inverter hardware is necessary for using the software library In depth know how of STM32F103xx or STM32F100x peripherals functions is only required for customizing existing modules and for ad
81. ding new ones for a complete application development Doc ID 18458 Rev 2 1 122 www st com UM1052 Contents Contents 1 MC software development kit architecture 10 2 Documentation architecture eee ee 13 2 1 Where to find the information you need eee eee eee 13 2 2 Related documents 0002 eee eee 14 3 Overview of the FOC and other implemented algorithms 15 3 1 Introduction to the PMSM FOC drive 00 0 eee eee 15 3 2 PM motor structures 3 daa Kas BEA GA AGA aakel woes teas BETA EES 17 3 3 PMSM fundamental equations 0 0 00 ee 18 3 3 1 SM PMSM field oriented control FOC 0002 cee eee 19 3 4 PMSM maximum torque per ampere MTPA control 20 3 5 Feed forward current regulation 0 e eee ee 22 3 6 Flux weakening control 0 cece eee ee 23 3 7 PID regulator theoretical background 0 00 e eee ee eee 25 3 7 1 Regulator sampling time setting 0 ce eee eee 25 3 8 A priori determination of flux and torque current PI gains 26 3 9 Space vector PWM implementation 0000 cee eee ee 29 3 10 Detailed explanation about reference frame transformations 30 3 10 1 Circle limitation 0 0 0 0c een 32 4 Current sampling aaa ech oe te AW ee ences da AA 34 4 1 Current sampling in three shunt topology aaa 34 4 1 1 Tuning delay parameters and s
82. e 13 Time domain to discrete PID equations Time domain f t Kp x Error sys t K x f Eory at Kyx 2 Errorsys t T Pleciptp X7 Kp X Errorsys HkiX T SErrorgy Kg x Errorsys Errorsys 0 sampling done at Fs 1 Ts frequency a TO EK 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 For speed 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 Hall sensors are used while driving the motor at low speed 3 8 A priori determination of flux and torque current PI gains This section provides a criterion for the computation of the initial values of the torque flux PI parameters K and Kp This criterion is also used by the ST MC Workbench in its computation To calculate these starting values it is required to know the electrical characteristics of the motor stator resistance R and inductance L and the electrical characteristics of the hardware shunt resistor Rgpunt Current sense amplification network Ao and the direct current bus voltage VgusDC The derivative action of the controller is not considered using this method Figure 14 shows the PI controller block diagram used for torque or flux regulation Figure 14 Block diagram of PI controller Target Voltage current command
83. e CRC Data Acknowledgment frame No errors BOARD gt oxeo Fs FTB FHB DRB DR HB crc OR Get revup data frame PC gt 0x08 0x01 Stage CRC Error Acknowledgment frame BOARD gt OxFF 0x1 ERROR CODE CRC MS19378V1 The master indicates the requested stage parameter sending the stage number in the starting frame payload Payload length is always 1 The Acknowledgment frame can be of two types e Data Acknowledgment frame if the operation has been successfully completed In this case the returned values are embedded in the Data Acknowledgment frame The pay load size of this Data Acknowledgment frame is always 8 The four bytes FS x represent the final speed of the selected stage expressed in rpm from least significant byte to most significant byte FT_LB and FT_HB represent the final torque of the selected stage expressed in digit respectively least significant byte and most significant byte Doc ID 18458 Rev 2 116 122 Serial communication class overview UM1052 Note 10 6 117 122 To convert current expressed in Amps to current expressed in digit use the formula Current digit Current Amp x65536xR ShuntxA OP V DD Micro DR LB and DR HB represent the duration of the selected stage expressed in milliseconds respectively least significant byte and most significant byte e Error Acknowledgment frame if the o
84. e Dual control panel is only present if the firmware is configured for dual motor drive Speed controller page is only present when the firmware is configured in speed mode Sensorless tuning page PLL is only present if the firmware is configured with state observer with PLL as primary or auxiliary speed sensor Sensorless tuning page CORDIC is only present if the firmware is configured with state observer with CORDIC as primary or auxiliary speed sensor To navigate the help menus use e RIGHT navigate to the next page on the right e LEFT navigate to the next page on the left Figure 62 Page structure and navigation WELCOME CERI HELP PAGE RIGHT CONFIG DUAL SPEED CURRENT SENSORLESS SENSORLESS gt AND DEBUG CONTROL CONTROLLER CONTROLLERS TUNING PAGE TUNING PAGE PAGE PANEL PAGE PAGE CORDIC RIGHT RIGHT RIGHT RIGHT RIGHT LEFT LEFT LEFT LEFT LEFT RIGHT LEFT MS19355V1 Each page is composed of a set of controls Table 18 presents the list of controls used in the LCD demonstration program You can navigate between focusable controls in the page by pressing the joystick UP and DOWN The focused control is highlighted with a blue rectangle When focused you can activate the control by pressing JOYSEL Doc ID 18458 Rev 2 80 122 LCD user interface UM1052 Table 18 List of controls used in the LCD demonstration program Control name and Example Description M
85. e between focusable controls present in the page pressing joystick UP DOWN The sensorless tuning page shown in Figure 70 is used to send commands and get feedback related to state observer plus PLL object from the active motor There are three groups of control in this page Table 27 Control groups Control group Description State observer tuning Used to configure the parameters of the state observer object in real time Used to change the start up related parameters in real time This group is only Rev up tuning gains present if the state observer plus PLL sensor is selected as primary speed and position sensor Measured speed Composed of two controls that are also present in the current controllers page with start stop and in the sensorless tuning page this provides for fast access to the button measured speed and to the motor start stop function Doc ID 18458 Rev 2 Ty UM1052 LCD user interface sa Figure 70 Sensorless tuning STO 4 PLL page PMSM FOC ver 3 0 Sensorless tuning STO amp PLL AUX G1 m G2 J PLL KP PLL KI Measured speed 1500 rpm Start Stop Rev up tuning Duration 700 Elms Stage F Speed 0 Flrpm Iq 20000 Motor selected 1 If the firmware is configured as dual motor drive it is possible to know which is the active motor by reading the label at the bottom of the page To change the active motor change the motor field in the configura
86. e correctly instantiated before the LCD Init calls See DAC manager class CDAC s_fwVer is a string that will be displayed in the LCD See Figure 63 STM32 Motor Control demonstration project welcome message containing both the Firmware version and Release version it must be separated by the 0x0 character 3 Periodically call the LCD_UpdateMeasured method This updates LCD GUI variables and calls the LCD_Exec method that performs the LCD screen refresh LCD Exec oLCD LCD UpdateMeasured oLCD These functions are performed inside UlTask c The LCD refresh also uses Timebase c or RTOS Motor control protocol class CMCP Ul This is a derived class of UI that is based on the serial communication This class is on the top layer of the serial communication architecture See Figure 77 and manages the highest level of the motor control protocol Figure 77 Serial communication software layers Level increasing STM32 Std Library The frame communication protocol CFCP implements the transport layer of the serial communication It is responsible for the correct transfer of the information CRC checksum and so on The class CCOM implements the physical layer through its derivatives For each physical communication channel there is a specific derivative of the CCOM object Only the USART channel has been implemented so far by CUSART COM class Doc ID 18458 Rev 2 104 122 User Interface
87. e currents See Figure 29 To avoid this condition it is necessary to reduce the maximum modulation index or decrease the PWM frequency Figure 29 ADuty lt DT Ty Ts 2 and ADuty 3 lt DT Tp Ts ADuty 5 Low side phase aQ High side phase A f ji ig Low side phase B Pat mi High side phase B To ii B Current feedback phase B Current feedback phase C l RA Apa No space available for sampling l Pa lt T Doc ID 18458 Rev 2 i UM1052 Current sampling 4 2 Current sampling in single shunt topology Figure 30 illustrates the single shunt topology hardware architecture Figure 30 Single shunt hardware architecture K Pa K INA IK pamp Offset al lt INI I P OpAmp Offset soon Voltage to be converted Voltage on A Shunt MSIs 05v1 It is possible to demonstrate that for each configuration of the low side switches the current through the shunt resistor is given in Table 5 T4 Ts and Tg assume the complementary values of T4 T and T3 respectively In Table 5 the value O means that the switch is open whereas the value 1 means that the switch is closed Table 5 Current through the shunt resistor Ty T2 T3 Ishunt 0 0 0 0 0 1 1 in 0 0 1 ic 1 0 1 ig 1 0 0 ig 1 1 0 ic 0 1 0 ig 1 1 1 0 Using the centered aligned pattern each PW
88. e direction of current I 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 Fortunately as discussed in Section 4 1 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 given in Section 4 1 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 19 you can deduct that in sectors 1 and 6 the ky Doc ID 18458 Rev 2 36 122 Current sampling UM1052 Note 37 122 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
89. e dual FOC library UM1053 and directly sets the motor current references and ly to be expressed as s16A This command is only executed when the state machine status is START RUN or RUN CommandState t MC sCommandAcknowledged CMCI oMCI returns information about the state gt of the last buffered command CommandState_t can be one of the following codes MCI_BUFFER_EMPTY if no buffered command has been called MCI_COMMAND_NOT_ALREADY_EXECUTED if the buffered command condition hasn t already occurred MCI_COMMAND_EXECUTED_SUCCESFULLY if the buffered command has been executed successfully In this case calling this function reset the command state to MCI_BUFFER_EMPTY MCI_COMMAND EXECUTED _UNSUCCESFULLY if the buffered command has been executed unsuccessfully In this case calling this function reset the command state to MCI_BUFFER_EMPTY Doc ID 18458 Rev 2 ky UM1052 MC application programming interface API 7 2 MCTuningClass The MCTuningClass allows the user to obtain objects of the Motor Control Application and apply methods on them MCTuningClass h is divided into three sections e Public definitions of all the MC classes exported MCT GetXXX functions used to receive objects e For each of the classes exported a list of applicable methods For example if you wa
90. e file see Section 6 3 The Motor Control Application project the application that uses the Motor Control Library layer Parameters and configurations related to user s application are used here to create right objects and rights in what is called the run time system boot The Motor Control API is the set of commands granted to the upper layer This project is built as a compiled library not as an executable file see Section 6 4 The user project the demonstration program included in the SDK that makes use of the Motor Control Application through its MC API and provides it the required clockings and access to Interrupt Handlers The program can run some useful functionalities depending on user options such as serial communication LCD keys interface system variables displaying through DAC Two equivalent and alternative user projects exist They differ in how they generate the clocks one implements a simple time base itself the other exploits an Operating System FreeRTOS to do it See Section 7 3 How to create a user project that interacts with the MC API to understand how to create a brand new user project Previously built lib files are linked with the user project in order to generate the file that can be downloaded into microcontroller memory for execution see Section 6 5 Figure 52 provides an overview of the IAR EWARM IDE workspace located in Installation folder Project EWARM Workspace eww configured for du
91. e modified The four bytes FS x is the requested new final speed of the selected stage expressed in rpm from the least significant byte to the most significant byte FT LB and FT_HB is the requested new final torque of the selected stage expressed in digit respectively least significant byte and most significant byte To convert current expressed in Amps to current expressed in digit is possible to use the formula Current digit Current Amp 65536 Rshunt Aop Vdd micro DR_LB and DR_HB is the requested new duration of the selected stage expressed in milliseconds respectively least significant byte and most significant byte The Acknowledgment frame can be of two types e Data Acknowledgment frame if the operation has been successfully completed the payload of this Data Acknowledgment frame will be zero e Error Acknowledgment frame if the operation has not been successfully completed by the firmware The payload of this Error Acknowledgment frame is always 1 The list of error codes are shown in Table 36 Set current references frame The set current references frame Figure 88 is sent by the Master to modify the current references lq la Figure 88 Set current reference frame Set current references frame PC gt xA 0x04 lq LB lq HB ld LB ld HB CRC Data Acknowledgment frame No errors OR Set current references frame PC naaa OXOA 0x04 lq LB lq HB ld LB ld HB CRC
92. eld 1 in automatically sent to the motor control related object allowing the run time Figure 72 tuning of state observer object This value is proportional to the K1 observer gain and is equal to C2 STO object parameter See doxygen chm To modify the G2 gain parameter in real time The value set in this control is G2 field 2 in automatically sent to motor control related object allowing the run time tuning Figure 72 of state observer object This value is proportional to the K2 observer gain and is equal to C4 STO object parameter See doxygen chm Duration field 3 in Figure 72 To set the duration of the active rev up stage for the active motor The value set in this control is automatically sent to motor control related object and becomes active on next motor start up allowing the tuning of the rev up sequence Duration is expressed in milliseconds F Speed field 4 in Figure 72 To set the final mechanical speed for the active motor and active rev up controller stage The value set in this control is automatically sent to motor control related object and becomes active on next motor start up allowing the run time tuning of rev up sequence Final mechanical speed is expressed in RPM sa Doc ID 18458 Rev 2 96 122 LCD user interface UM1052 97 122 Table 30 Sensorless tuning STO amp PLL page controls continued Control la field 5 in Figure 72 Description To set the final to
93. en after a while stop debugging CTRL Shift D The LCD Ul is not flashed properly if the program is stalled in a trap inside UlTask c line 133 Doc ID 18458 Rev 2 ky UM1052 Working environment 4 Figure 57 Flash loader wizard screen Flash Loader Demonstrator STMicroelectronics C Erase All Download to device Download from file TIONSLCD Project HEX STM3210B_EVAL_SINGLEDRIVE hed El G Erase necessary pages C No Erase Global Erase I Jump to the user program I Optimize Remove some FFs IV Verify after download I Apply option bytes a Upload from device Upload to file m Enable Disable Flash protection El C Edit option bytes Next ance Close MS19348V1 Option 2 This option is intended for users who want to modify the LCD UI code 1 2 Use an IDE to rebuild and download the LCD UI After parameter files are generated by the GUI to set the single dual drive configuration using IAR EWARM IDE V5 50 open the workspace located in Installation folder LCD Project EWARM UI Project eww Doc ID 18458 Rev 2 68 122 Working environment UM1052 69 122 Figure 58 LCD UI project IAR Embedded Workbench IDE File Edit View Project Tools Window Help Cea a pe NABOPA wonpace STM32100B EVAL 34 define HardFault Handler OxABCDEF12 files R IAR dependent 4 a GUI Project STM32100B EVAL
94. ent the mathematical transformations required by FOC Doc ID 18458 Rev 2 ky UM1052 Overview of the FOC and other implemented algorithms Figure 4 Basic FOC algorithm structure torque control Power converter MS19340V1 Figure 5 Speed control loop AC Mains Doc ID 18458 Rev 2 16 122 Overview of the FOC and other implemented algorithms UM1052 3 2 17 122 Table 1 References Reference Detail Section 3 4 PMSM maximum torque Explains the MTPA maximum torque per ampere strategy per ampere MTPA control optimized for IPMSM Section 3 6 Flux weakening control Explains flux weakening control Section 3 5 Feed forward current Shows how to take advantage of the feed forward current regulation regulation Figure 5 Speed control loop shows the speed control loop built around the core torque control loop plus additional specific features offered by this Motor Control Library see Table 1 References Each of them can be set as an option depending on the motor being used and user needs via the ST MC Workbench GUI which generates the h file used to correctly initialize the MCA during its boot stage PM motor structures Two different PM motor constructions are available In drawing a in Figure 6 the magnets are glued to the surface of the rotor and this is the reason why it is referred to as SM PMSM surface mounted PMSM In
95. er The value is expressed in permillage o of DC bus voltage Bus o field 9 in Figure 66 Flux wk PI gain KP field 10 in Figure 66 Flux wk PI gain KI field 11 in Figure 66 This reads the quantity of DC bus voltage percentage presently used for the active motor and is a read only control This control is present only if the flux weakening feature is enabled in the firmware The value is actually expressed in permillage o of DC bus voltage the proportional coefficient of the flux weakening controller for the active motor This control is only present if the flux weakening feature is enabled in the firmware The value set in this control is automatically sent to the motor control related object allowing the run time tuning of flux weakening controller Sets the integral coefficient of the flux weakening controller for the active motor This control is only present if the flux weakening feature is enabled in the firmware The value set in this control is automatically sent to the motor control related object allowing the run time tuning of flux weakening controller Current controllers page To enter the current controllers page press the joystick RIGHT from speed controller page or from one of the described above pages if speed controller page is not visible It is possible to navigate between focusable controls present in the page pressing joystick UP DOWN Doc ID 18458 Rev 2 90 122 LCD user i
96. er interface configuration 0 000 eee ee ee 101 9 3 LCD manager class CLCD_Ul 2 00020 cee eee 102 9 4 Using the LCD Manager 0 00 cee eee 103 9 5 Motor control protocol class CMCP UN 00 0000 104 9 6 Using the motor control protocol a 105 9 7 DAC Manager Class CDACx UN aa 105 9 8 Using the DAC manager aana eee 107 9 9 How to configure the user defined DAC variables 108 10 Serial communication class overview 2 aaa 109 10 1 Set register frame ee ee 111 10 2 Get register frame 2 aaa sivadaessede tena Seared yada weed 113 10 3 Execute command frame 000 cee ee 114 10 4 Execute ramp frame aa eeGue eeNeeh KNANG KNA REY eet wanes 115 10 5 Getrevup data frame 0 ce es 116 10 6 Set revup data frame a ak is ibe pid seeped teh neg bawee bearer 117 10 7 Set current references frame 0 cee ee 118 11 Document conventions 0 0 c eee ee 120 Appendix A Additional information 000000 cee eee 121 A 1 References Hang ani eacdnewideepaeeanteeeratedaneieee knee axe 121 Revision hISLOLY iia esac sith ae a a a a a ca a a a AN 121 ky Doc ID 18458 Rev 2 4 122 UM1052 List of figures 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
97. ess otherwise mentioned in this manual The control can be deactivated by pressing JOYSEL again Sends commands to motor control related object For example a start stop Button button This button can be enabled or disabled A disabled button is drawn in light gray and cannot be focusable An enabled button is painted in black and can be focusable When focused a button can be activated by pressing JOYSEL This corresponds to pushing the button and sending the related command Check box Enables or disables an option It is always focusable and when focused can be activated by pressing JOYSEL This correspond to check uncheck the Link control and means enable disable the option 8 2 1 Motor control application layer configuration speed sensor The motor control application layer can be configured to use a position and speed sensor as a primary or auxiliary speed sensor A primary speed and position sensor is used by the FOC algorithm to drive the motor It is mandatory to configure a primary speed sensor An auxiliary speed and position sensor may be used in parallel with the primary sensor for debugging purposes It is not used by the FOC algorithm It is not mandatory to configure an auxiliary speed sensor 81 122 Doc ID 18458 Rev 2 ky UM1052 LCD user interface 8 2 2 8 2 3 The following sensors are implemented in the MC library e Hall sensor Quadrature encoder e State observer plu
98. ference M red d component of motor phase rrent expr in MC PROTOCOL REG ID Hila d component of motor phase s current expressed in q d Target q component of motor phase s current expressed in q d MC PROTOCOL REG I Q REF reference Target d component of motor phase s current expressed in q d reference MC PROTOCOL REG I D REF Forced q component of motor phase s voltage expressed in q d reference MC PROTOCOL REG V Q For d component of motor phase s volt Xpri in MC PROTOCOL REG V D aa component of motor phase s voltage expressed in q d Forced alpha component of motor phase s voltage expressed in MC PROTOCOL REG V ALPHA alpha beta reference Forced beta component of motor phase s voltage expressed in alpha beta reference MC PROTOCOL REG V BETA M r H G H H LU n MC_PROTOCOL_REG Meas Ex Measu ed motor electrical angle This variable is related to real ANGIR sensor encoder Hall configured as primary or auxiliary speed mia sensor MC PROTOCOL REG MFAS RO Measured motor speed This variable is related to real sensor T SPEED encoder Hall configured as primary or auxiliary speed MC PROTOCOL REG OBS EL Observed motor electrical angle This variable is related to state Peake observer PLL sensor configured as primary or auxiliary speed
99. ference field 1 in Figure 67 Description To set and read the reference for the active motor This control is read only if the active motor is set in speed mode otherwise it can be modified The reference is expressed in s16A To convert current expressed in Amps to current expressed in digits use the formula Current s16A Current Amp 65536 Rshunt Aop Vdd micro ly reference field 2 in Figure 67 To set and read the ly reference for the active motor This control is usually read only if the active motor is set in speed mode otherwise it can be modified The lg reference is expressed in digits It is also possible to configure the firmware to have Id reference modifiable even in speed mode To convert current expressed in Amps to current expressed in s16A is possible to use the formula Current s16A Current Amp 65536 Rshunt Aop Vdd micro Doc ID 18458 Rev 2 ky UM1052 LCD user interface sa Table 26 Current controllers page controls continued Control Measured lg field 3 in Figure 67 Description To read the measured lg for the active motor Measured lg is expressed in s16A and is a read only control Iq PI D gain KP field 5 in Figure 67 To set the proportional coefficient of the current controller for the active motor The value set in this control is automatically sent to the motor control related object allowing the run time tuning of
100. g direction the yellow and the red waveforms C1 C2 are respectively the observed back emfs alpha and beta the blue square wave C3 is a signal coming from a Hall sensor cell placed on the a axis the green sinewave is current i C4 In confidential distribution the classes that implement the sensorless algorithm are provided as compiled object files The source code is available free of charge from ST on request Please contact your nearest ST sales office A priori determination of state observer gains The computation of the initial values of gains K1 and K2 is based on the placement of the state observer eigenvalues The required motor parameters are r motor winding resistance Ls motor winding inductance T sampling time of the sensorless algorithm which coincides with FOC and stator currents sampling Doc ID 18458 Rev 2 ky UM1052 Rotor position speed feedback The motor model eigenvalues could be calculated as rT s Ai Napa s E551 The observer eigenvalues are placed with e iobs F e 2 Ebobs f Typically as a rule of the thumb set f 4 The initial values of K1 and K2 could be calculated as e te 2 r K lobs po PI a K L A 12 10bs 7 oo e obs 2o0bs T This procedure is followed by the ST MC Workbench GUI to calculate proper state observer gains It is also possible to modify these values using other criteria or after fine tuning Figure 42 PMSM back emfs detected by the sensor
101. gister is calculated to set the sampling point for the next PWM period and the A D converter is configured to sample the correct channels Table 3 3 shunt current reading used resources single drive F103 LD MD Adv timer DMA ISR ADC ADC Note master slave DMA is used to enable ADC injected TIM1 DMA1 CH5 None ADC1 ADC2 conversion external trigger Disabling is performed by software Doc ID 18458 Rev 2 ky UM1052 Current sampling Table 4 3 shunt current reading used resources single drive or dual drive F103 HD Adv timer DMA ISR ADC Note Used by first or second motor configured in ADC1 three shunt according to user selection TIMI None TIMI UP ADC2 ADC is used in time sharing Trigger selection is performed in the TIM UP ISR used by first or second motor configured in ADC1 three shunt according to user selection TIM Nene TIM8 UP ADC2 ADC is used in time sharing Trigger selection is performed in the TIM_UP ISR 4 1 1 Tuning delay parameters and sampling stator currents in three shunt resistor topology Figure 24 shows one of the three inverter legs with the related shunt resistor Figure 24 Inverter leg and shunt resistor position To indirectly measure the phase current 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 th
102. gment frame No errors BOARD OxFO 0x00 CRC OR Set register frame PC 0x01 PAYLOAD_LENGTH REG_ID REG LB REG HB CRC Error Acknowledgment frame BOARD OxFF 0x1 ERROR_CODE CRC MS19373V1 Payload length depends on REG ID See Table 36 Reg Id indicates the register to be updated The remaining payload contains the value to be updated starting from least significant byte to most significant byte The Acknowledgment frame can be of two types e Data Acknowledgment frame if the operation has been successfully completed The payload of this Data Acknowledgment frame is zero e Error Acknowledgment frame if the operation has not been successfully completed by the firmware The payload of this Error Acknowledgment frame is always 1 The list of error codes are shown in Table 36 Table 36 List of error codes Error code Description 0x01 BAD Frame ID The Frame ID has not been recognized by the firmware 0x02 Write on read only Master wants to write on a read only register 0x03 Read not allowed The value can t be read Doc ID 18458 Rev 2 ky UM1052 Serial communication class overview sa Table 36 List of error codes continued Error code Description 0x04 Bad target drive Target motor is not supported by the firmware 0x05 Out of range The value used in the frame is outside the range expected by the firmware 0x07 Bad comman
103. he slave answers this frame with the acknowledge frame See Figure 79 Doc ID 18458 Rev 2 ky UM1052 Serial communication class overview Figure 79 Master Slave communication architecture Starting frame Master Slave Acknowledgment frame Master MS19371V1 The implemented MCP is based on the physical layer that uses the USART communication A generic starting frame Table 34 is composed of 5 Frame ID this byte defines the type of the starting frame See Table 35 e Payload_Length the total number of bytes that compose the frame payload e Payload ID first byte of the payload that contains the identifier of payload Not necessary if not required by this type of frame e Payload x the remaining payload content Not necessary if not required by this type of frame CRC byte used for cyclic redundancy check The CRC byte is computed as follows Total unsigned t6bit FramelD PayloadLength x7 Payloadi CRC unsigned8bit HighByte Total LowByte Total Table 34 Generic starting frame FRAME_ID PAYLOAD_LENGTH PAYLOAD_ID PAYLOAD 0 PAYLOAD n CRC Table 35 shows the list of possible starting frames Table 35 Starting frame codes Frame ID Description 0x01 Set register frame It is used to write a value into a relevant motor control variable See Set register frame Get register frame It is used to read a value from a relev
104. hreshold then ij decreases to zero and the MTPA block resumes control The current iy output from the flux weakening controller must be checked against iy max to avoid the demagnetization of the motor Figure 11 Flux weakening operation scheme FLUX WEAKENING control voltage level ig limiter This feature can be activated through correct settings in h parameter files generated by the ST MC Workbench GUI used to initialize the MC Application during its boot stage In confidential distribution the classes that implement the flux weakening algorithm are provided as compiled object files The source code is available free of charge from ST on request Please contact your nearest ST sales office Doc ID 18458 Rev 2 24 122 Overview of the FOC and other implemented algorithms UM1052 3 7 3 74 25 122 PID regulator theoretical background The regulators implemented for Torque Flux and Speed are actually Proportional Integral Derivative PID regulators PID regulator theory and tuning methods are subjects which have been extensively discussed in technical literature This section provides a basic reminder of the theory PID regulators are useful to maintain a level of torque flux or speed according to a desired target Figure 12 PID general equation torque f rotor position 7 torque and flux regulation for maximum flux f rotor position g
105. iable is present only if a state observer plus CORDIC sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor a Doc ID 18458 Rev 2 UM1052 LCD user interface Table 21 DAC variables related to each state observer sensor when two state observer speed sensors are selected continued Variable name Description Observed beta component of motor phase s current expressed in alpha beta reference This variable is present only if a state observer plus CORDIC sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs Ibeta CR Observed alpha component of motor BEMF expressed in alpha beta reference This variable is present only if a state observer plus CORDIC sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs Bemf a CR Observed beta component of motor BEMF expressed in alpha beta reference Obs Bemfb CR This variable is present only if a state observer plus CORDIC sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Table 21 lists the DAC variables related to each state observer sensor when two state observer speed sensors are selected e Itis possible to read the list of fault causes field 7 in Figure 64 if fault conditions have occurred or if they are still present The list of possible faults is summarized in Table 22
106. ians can be mapped into the s16degrees domain 77 122 Doc ID 18458 Rev 2 ky UM1052 MC application programming interface API Figure 60 Radians vs s16 angle 516 4 32767 L ae eae gt 0 2T angle radians 32768 ai14842 7 4 2 Rotor speed The rotor speed units used in the MC API are e Tenth of Hertz 01Hz straightforwardly it is 101Hz 0 1 Hz e digit per control period dpp the dpp format expresses the angular speed as the variation of the electrical angle expressed in s16 format within a FOC period so 1dpp 1s16degree 1FOCperiod An angular speed expressed as frequency in Tenth of Hertz 01Hz can be easily converted to dpp using the formula KA 65536 upp 1Hz 17 FOCfreq 7 4 3 Current measurement Phase currents measurement unit used in the MC API has been named s16A being MaxMeasureableCurrent IS16AH 32767 A current expressed in Ampere can be easily converted to s16A using the formula _ i X 65536 e RShunt x AmplificationGain ls16A yC_VDD 7 4 4 Voltage measurement Applied phase voltage unit used in the MC API has been named s16V being MaxApplicablePhaseVoltagey 1s16V 32767 Doc ID 18458 Rev 2 78 122 LCD user interface UM1052 8 8 1 79 122 LCD user interface Running the motor control firmware using the LCD interface The STM32 motor control library V3 0 includes a demonstration program that enables you to display dr
107. igure 70 and becomes active on next motor start up To convert current expressed in Amps to current expressed in digits use the formula Current s16A Current Amp 65536 Rshunt Aop Vdd micro Stage Field 8 in To set the active rev up stage that receives the Duration F Speed and Final Figure 70 torque reference Iq new values set in Fields 5 6 and 7 The rev up sequence consists of five stages Figure 71 shows an example of rev up sequence It is possible to tune each stage in run time using rows 5 8 of Table 28 Figure 71 Example of rev up sequence lq ref Duration time Stage 0 gt Stage 0 Stage 1 Stage 2 Sensorless tuning STO amp CORDIC page This page is only present if the firmware is configured to use a state observer plus CORDIC sensor set as a primary or auxiliary speed and position sensor If the state observer sensor is set as auxiliary speed and position sensor the AUX label will be shown near the page title See field 7 in Figure 72 To enter the sensorless tuning page press the joystick RIGHT from current controllers page It is possible to navigate between focusable controls present in the page pressing joystick UP DOWN The sensorless tuning page shown in Figure 72 is used to send commands and get feedbacks related to state observer plus CORDIC object from the active motor There are three groups of controls in this page Doc ID 18458 Rev 2
108. ion sensor less control of interior permanent magnet synchronous motors ACEMP 07 pp 647 652 2007 M Cacciato G Scarcella G Scelba S M Bill D Costanzo A Cucuccio Comparison of Low Cost Implementation Sensorless Schemes in Vector Controlled Adjustable Speed Drives SPEEDAM 08 Applied Power Electronics Conference and Exposition 2008 6 Revision history Table 40 Document revision history Dba ren E 18 Apr 2011 1 Initial release Added references for web and confidential distributions of STM32 24 May 2011 2 FOC PMSM SDK v3 0 121 122 Doc ID 18458 Rev 2 ky UM1052 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 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 pa
109. ions 00000e cee eee 102 Description of relevant DAC variables 000 cece eee ae 106 Generic starting frame 1 2 6 teens 110 Starting frame codes 6 6 teen eee 110 List ofGrror COdCS 4 enced ae bd ee eee aba eae eee a a oe 111 List of relevant motor control registers 0 0 0 AA tees 112 List Of commands coercere maa iw ge eae we Rae Se Phe A Be pear ee ahha ata edi 114 List of abbreviations 0 0 tet eeee 120 Document revision history 0 0c eee 121 Doc ID 18458 Rev 2 7 122 UM1052 Motor control library features Single or simultaneous Dual PMSM FOC sensorless sensored Dual PMSM FOC only when running on STM32F103xx High Density STM32F103xx XL Density Speed feedback Sensorless B EMF State Observer PLL rotor speed angle computation from B EMF Sensorless B EMF State Observer CORDIC rotor angle computation from B EMF 60 or 120 displaced Hall sensors decoding rising falling edge responsiveness Quadrature incremental encoder For each motor dual simultaneous speed feedback processing On the fly speed sensor switching capability Current sampling methods Two ICS only when running on STM32F 103xx Single common DC link shunt resistor ST patented Three shunt resistors placed on the bottom of the three inverter legs only when running on STM32F103xx Flux weakening algorithm to attain higher than rated motor s
110. irect axis current iy given a motor rated current lp such that ig ig if we choose to set id O then the maximum available quadrature current i is reduced Consequently in case of an SM PMSM as shown in Section 3 3 1 the maximum deliverable electromagnetic torque is also reduced On the other hand for an IPM motor acting separately on iy causes a deviation from the MTPA path as explained in Section 3 4 PMSM maximum torque per ampere MTPA control Closed loop flux weakening has been implemented Accurate knowledge of machine parameters is not required which strongly reduces sensitivity to parameter deviation see 3 4 in Appendix Section A 1 References This scheme is suitable for both IPMSMs and SM PMSMs The control loop is based on stator voltage monitoring Figure 11 shows the diagram The current regulator output V is checked against a settled threshold voltage level parameter If V is beyond that limit the flux weakening region is entered automatically by regulating a control signal is that is summed up to ig the output of the MTPA controller This is done by means of a PI regulator whose gain can be tuned in real time in order to prevent the saturation of the current regulators It clearly appears then that the higher the voltage level parameter is settled by keeping up current regulation the higher the achieved efficiency and maximum speed If V is smaller than the settled t
111. is possible to offer electromagnetic torque Te regulation and to some extent flux weakening capability This resembles the favorable condition of a DC motor where those roles are held by the armature and field currents Therefore it is possible to say that FOC consists of controlling and orienting stator currents in phase and quadrature with the rotor flux this definition makes clear that a means of measuring stator currents and the rotor angle is needed Basic information on the algorithm structure and then on the library functions is represented in Figure 4 The igs and igs current references can be selected to perform electromagnetic torque and flux control The space vector PWM block SVPWM implements an advanced modulation method that reduces current harmonics thus optimizing DC bus exploitation The current reading block allows the system to measure stator currents correctly using either cheap shunt resistors or market available isolated current Hall sensors ICS The rotor speed position feedback block allows the system to handle Hall sensor or incremental encoder signals in order to correctly acquire the rotor angular velocity or position Moreover this firmware library provides sensorless detection of rotor speed position e The PID controller blocks implement proportional integral and derivative feedback controllers current regulation The Clarke Park Reverse Park amp Circle limitation blocks implem
112. ital Computer DAC Digital to Analog Converter DC Direct Current FOC Field Oriented Control GUI Graphical User Interface I PMSM Internal Permanent Magnet Synchronous Motor IC Integrated Circuit ICS Isolated Current Sensor IDE Integrated Development Environment MC Motor Control MCI Motor Control Interface MCT Motor Control Tuning MTPA Maximum Torque Per Ampere PID controller Proportional Integral Derivative controller PLL Phase Locked Loop PMSM Permanent Magnet Synchronous Motor SDK Software Development Kit SM PMSM Surface Mounted Permanent Magnet Synchronous Motor SV PWM Space Vector Pulse Width Modulation UI User Interface Doc ID 18458 Rev 2 120 122 Additional information UM1052 Appendix A Additional information A 1 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 S Morimoto Y Takeda T Hirasa K Taniguchi Expansion of Operating Limits for Permanent Magnet Motor by Optimum Flux Weakening Conference Record of the 1989 IEEE pp 51 56 1989 J Kim S Sul Speed control of Interior PM Synchronous Motor Drive for the Flux Weakening Operation IEEE Trans on Industry Applications 33 pp 43 48 1997 4 a4 5 M Tursini A Scafati A Guerriero R Petrella Extended torque speed reg
113. ive variables customize the application by changing parameters and enable and disable options in real time The user interface reference is the one present in the STM32 evaluation boards and is shown in Figure 61 The interface is composed of Figure 61 User interface reference A 320x240 pixel color LCD screen e A joystick see Table 17 for the list of joystick actions and conventions e A push button KEY button Table 17 Joystick actions and conventions Keyword User action UP Joystick pressed up DOWN Joystick pressed down LEFT Joystick pressed to the left RIGHT Joystick pressed to the right JOYSEL Joystick pushed KEY Press the KEY push button Doc ID 18458 Rev 2 ky UM1052 LCD user interface 8 2 In the default firmware configuration the LCD management is enabled It can be disabled using the STM32 MC Workbench or disabling the feature and manually changing the line define define LCD JOYSTICK BUTTON FUNCTIONALITY DISABLE line 316 of the Drive parameters h file The LCD management is provided by a separate workspace UI Project that should be compiled and programmed before the motor control firmware programming LCD User interface structure The demonstration program is based on circular navigation pages Figure 62 shows the page structure The visibility of certain pages shown in Figure 62 depends on the firmware configuration
114. ky UM1052 LCD user interface Table 29 Control groups Control group State observer tuning Description Used to configure the parameters of the state observer object in real time Rev up tuning gains Used to change the start up related parameters in real time This group is only present if the state observer plus CORDIC sensor is selected as primary speed and position sensor Measured speed with start stop button Composed of two controls that are also present in the current controllers page and in the sensorless tuning page this provides for fast access to the measured speed and to the motor start stop function Figure 72 Sensorless tuning STO amp CORDIC page PMSM FOC ver 3 0 Sensorless tuning STO amp CORDIC auxi G1 A G2 J Measured speed 590 ron Start Stop Rev up tuning Duration 700 Elms Stage F Speed o Elrpm Iq 20000 EI Motor selected 1 MS19365V1 If the firmware is configured as dual motor drive it is possible to know which is the active motor by reading the label at the bottom of the page To change the active motor change the motor field in the configuration and debug page Table 30 lists the actions that can be performed using this page Table 30 Sensorless tuning STO amp PLL page controls Control Description To modify the G1 gain parameter in real time The value set in this control is G1 fi
115. l motor to be driven usually have the electronics split in two parts application board and motor drive board To drive the system correctly the application board requires a method to send a command to the motor drive board and get feedback from it This is usually performed using serial communication See Figure 78 Figure 78 Serial communication in motor control application Applicati nboard papa ae at KAG gal se Serial communication To target this kind of application a dedicated serial communication protocol has been developed for real time data exchange The aim of this protocol is to implement the feature requested by motor control related applications The implemented protocol is called motor control protocol MCP MCP makes it possible to send commands such as start stop motor and set the target speed to the STM32 FOC motor control firmware and also to tune in real time relevant control variables such as PI coefficients It is also possible to monitor relevant quantities such as the speed of the motor or the bus voltage present in the board related to the controlled system The implemented communication protocol is based on a master slave architecture in which the motor control firmware running on STM32 microcontroller is the slave The master usually a PC or another microcontroller present on a master board can start the communication at any time by sending the first communication frame to the slave T
116. less state observer algorithm Table 10 Legend for Figure 42 Reference Description C1 b emf alpha C2 b emf beta C3 Hall 1 C4 phase A measured current More information on how to fine tune parameters to make the firmware suit the motor can be found in Section 8 LCD user interface Doc ID 18458 Rev 2 50 122 Rotor position speed feedback UM1052 5 2 5 2 1 51 122 Hall sensor feedback processing Speed measurement implementation Thanks to the Root part number 1 F100xx general purpose timer TIMx features it is very simple to interface the microcontroller with three Hall sensors In fact when the TI1S bit in the TIMx_CR2 register is set the three signals on the TIMx_CH1 TIMx_CH2 and TIMx_CH pins are XORed and the resulting signal is input to the logic performing TIMx input capture In this way the speed measurement is converted into the period measurement of a square wave with a frequency six times higher than the real electrical frequency The only exception is that the rolling direction which is not extractable from the XORed signal is on the contrary performed by directly accessing the three Hall sensor outputs Rolling direction identification As shown in Figure 43 it is possible to associate any of Hall sensor output combinations with a state whose number is obtainable by considering H3 H2 H1 as a three digit binary number H3 is the most significant bit Figure 43 Hall
117. ly explains how to operate it For communication purposes you need to verify that you have an available COM port RS232 on your PC After the program is installed run the Flash loader demonstrator application from the Programs menu making sure that the device is connected to your PC and that the boot configuration pins are set correctly to boot from the system memory check the evaluation board user manual Reset the microcontroller to restart the system memory boot loader code When the connection is established the wizard displays the available device information such as the target ID the firmware version the supported device the memory map and the memory protection status Select the target name in the target combo box Click the Download to device radio button see Figure 57 and browse to select the appropriate hexadecimal file STM3210B EVAL SINGLEDRIVE hex STM32100B_EVAL_SINGLEDRIVE hex STM3210E EVAL SINGLEDRIVE hex STEVAL IHM022V1 SINGLEDRIVE hex STEVAL IHM022V1 DUALDRIVE hex from Installation folder LCD Project Hex Program the downloading to Flash memory After the code is successfully flashed setup the board to reboot from the user Flash memory and reset the microcontroller To test that the LCD UI is flashed correctly for both option 1 and 2 open build and download the user project see Section 6 2 MC SDK customization process and Section 6 5 User project From the debug session run the firmware F5 and th
118. mmands MC PROTOCOL CMD xxx is exported by UserlnterfaceClass h See STM32 FOC PMSM FW library v3 O developer Help file chm For example To execute a Start command to the first motor Doc ID 18458 Rev 2 100 122 User Interface class overview UM1052 Note 9 2 101 122 1 Obtain the oMCT and oMCl object through GetMCIList GetMCTList functions exported by MCTasks h The oMCI and oMCT are two arrays of objects CMCI oMCI MC_NUM CMCT oMCT MC_NUM GetMCIList oMCTI GeMCTList OMCT 2 Instantiate and initialize a CUI object OUI UI_NewObject MC NULL UI Init oUI MC NUM oMCI oMCT MC NULL 3 Select the motor drives UI_SelectMC oUI 2 4 Provide a command for example Start motor UI_ExecCmd oUI MC_PROTOCOL_CMD_START_MOTOR e Execute torque and speed ramps set current reference and set or get revup data See STM32 FOC PMSM FW library v3_0 developer Help file chm e Execute specific functions dedicated to CDAC objects See Section 9 7 DAC Manager Class CDACx Ul All derived classes of CUI act on MCI and MCT objects through the CUI methods For instance the LCD manager updates a motor control quantity calling UI_SetReg method and so on User interface configuration User interface object and its derivatives are configured using a 32bit configuration value see Figure 75 The first byte of this register contains the sensor configur
119. n RUN state To read the motor speed field 2 and 7 in Figure 65 respectively for motor 1 and motor 2 Motor speed is expressed in RPM This control is read only Send a start stop command field 4 for motor 1 field 10 for motor 2 in Figure 65 This is performed pushing the start stop button A start stop command means start the motor if it is stopped or stop the motor if it is running If the drive is configured in speed mode when the motor starts a speed ramp with the latest values of final motor speed and duration is performed If a fault condition occurs at any time the motor is stopped if running and the start stop button is disabled When a fault condition is over the Fault ack button Figure 65 field 5 for motor 1 field 11 for motor 2 is enabled Pushing this button acknowledges the fault conditions that have occurred After the fault is acknowledged the start stop button becomes available again When a fault occurs and before it is acknowledged it is only possible to navigate in the Dual control panel page and the Configuration and debug page e To start or stop both motors simultaneously push the start stop both motors button field 12 in Figure 65 This button is enabled only when the motors are both in Idle state or both in RUN state If any of the motors are configured in speed mode when they start a speed ramp with the last values of final motor speed and duration is performed It is possible to stop both mo
120. n must be paid however when connecting the sensors to the proper microcontroller inputs This software library assumes that the positive rolling direction is the rolling direction of a machine that is fed with a three phase system of positive sequence In this case to work correctly the software library expects the Hall sensor signal transitions to be in the sequence shown in Figure 48 for both 60 and 120 displaced Hall sensors For these reasons it is suggested to follow the instructions given below when connecting a Hall sensor equipped PM motor to your board 1 Turn the rotor by hand in the direction assumed to be positive and look at the B emf induced on the three motor phases For this purpose if the real neutral point is not available it can be reconstructed by means of three resistors for instance 2 Connect the motor phases to the hardware respecting the positive sequence Let Phase A Phase B and Phase C be the motor phases driven by TIM1 CH1 TIM1_CH2 and TIM1 CH3 respectively for example when using the MB459 board a positive sequence of the motor phases could be connected to J5 2 1 and 3 3 Turn the rotor by hand in the direction assumed to be positive look at the three Hall sensor outputs H1 H2 and H3 and connect them to the selected timer on channels 1 2 and 3 respectively making sure that the sequence shown in Figure 48 is respected 4 Measure the delay in electrical degrees between the ma
121. ng the command Buffered commands commands that do not execute instantaneously but are stored in a buffer and become active when the state machine is in a specified state These commands are not discarded until they become active unless other delayed commands are sent to the buffer thus clearing the previous one Detailed information can be found in the Motor Control Application source documentation doxygen compiled html Help file User commands bool MCI StartMotor CMCI oMCI starts the motor It is mandatory to set the target control mode speed control torque control and initial reference before executing this command otherwise the behavior in run state is unpredictable Use one of these commands to do this MCI ExecSpeedRamp MCI_ExecTorqueRamp or MCI_SetCurrentReferences bool MCI_StopMotor CMCI oMCT stops the motor driving and it disables PWM outputs bool MCI_FaultAcknowledged CMCI oMCI this function must be called after a system fault to tell the Motor Control Interface that the user has acknowledged the occurred fault When a malfunction overcurrent overvoltage is detected by the application the motor is stopped and the internal state machine goes to the Fault state see Figure 59 The API is locked it no longer receives commands The API is unlocked and the state machine returns to Idle when the user sends this MCI_FaultAcknowledged bool MCI_EncoderAlign CMCI oMCT this function is only used when an enco
122. nt to read or set parameters of the speed PI controller 1 Make sure that the Motor Control Application is already booted and objects oMCI and oMCT are available you can receive them through functions GetMCIList or GetMCTList 2 Declare a PIspeed automatic variable of the type CPI PI class type definition at line 85 3 Obtain the speed PI object which is actually a pointer by calling the function MCT GetSpeedLoopPID prototype at line 203 4 Set the KP gain by calling the function PI SetKP prototype at line 659 The resulting C code could be something like include MCTuningClass h f CPI PIspeedMotor2 PIspeedMotor2 MCT_GetSpeedLoopPID oMCT 1 PI SetKP PIspeedMotor2 NewKpGain Note To reduce flash and RAM occupation you can disable the MC Tuning section of the MC application This is done by commenting define MC_TUNING_INTERFACE in the source file MCTask c line 80 If you do this disable the LCD UI and Serial Communication UI too Doc ID 18458 Rev 2 74 122 MC application programming interface API UM1052 7 3 How to create a user project that interacts with the MC API This section explains how to integrate the Motor Control Application with a user project thus replacing the provided demonstrative one in order to take advantage of its API 1 A timebase is needed to clock the MC Application the demonstration timebase c can be considered as an example or used as it is It uses the Systick timer and
123. nterface UM1052 91 122 The current controller page shown in Figure 67 is used to send commands and get feedback related to current controllers from the active motor There are five control groups in this page listed in th e table below Table 25 Control groups Control group Description Set point Used to set the current references and read measured currents lq PID gains S Used to change in real time the speed controllers gains Id PID gains Measured speed with start stop button Composed of two controls that are also present in the current controllers page and in the sensorless tuning page this provides for fast access to the measured speed and to the motor start stop function Option selection Selects options Figure 67 Current controllers page PMSM FOC ver 3 0 Current controllers Set points Iq ref Iq Id ref Id Iq PID Gai KP 1000 KIT 500 Motor selected 1 Measured speed 1500 rpm Start Stop KP 1000 KI 500 If the firmware is configured as dual motor drive is possible to know which is the active motor reading the label at the bottom of the page To change the active motor the motor field in the configuration and debug page has to be changed Figure 67 field 1 Table 26 lists the actions that can be performed using this page Table 26 Current controllers page controls Control lq re
124. ntrol Application starts its operations the booting process begins objects are created from the Motor Control Library according to system configuration specified in parameter files and the application is up and represented by two objects oMCI and oMCT whose type is respectively CMCI and CMCT type definition can be obtained by including MCInterfaceClass h and MC TuningClass h Methods of MCInterfaceClass must be addressed to the oMCI object oMCT addresses methods of MC TuningClass oMCI and oMCT are two arrays each of two elements so that oMCI 0 and oMCT 0 refers to Motor 1 oMCI 1 and oMCT 1 refer to Motor2 Function GetMCIList to be called if necessary after MCboot returns a pointer to the CMCI oMCI vector instantiated by MCboot The vector has a length equal to the number of motor drives Function GetMCT List to be called if necessary after MCboot returns a pointer to the CMCT oMCT vector instantiated by MCboot The vector has a length equal to the number of motor drives Doc ID 18458 Rev 2 70 122 MC application programming interface API UM1052 7 1 71 122 MCinterfaceClass Commands of the MCInterfaceClass can be grouped in two different typologies User commands commands that become active as soon as they are called If the state machine is not in the expected state the command is discarded and the method returns FALSE The user must manage this by resending the command until it is accepted or discardi
125. o the PMSM FOC drive shows that rotor position speed measurement has a crucial role in PMSM field oriented control Hall sensors or encoders are broadly used in the control chain for that purpose Sensorless algorithms for rotor position speed feedback are considered very useful for various reasons to lower the overall cost of the application to enhance the reliability by redundancy and so on Refer to Section 5 1 The sensorless algorithm Section 5 2 Hall sensor feedback processing and Section 5 3 Encoder sensor feedback processing for further detail The selection of speed position feedback can be performed through correct settings in the h parameter files generated by the ST MC Workbench GUI used to initialize the MC Application during its boot stage The sensorless algorithm This firmware library provides a complete solution for sensorless detection of rotor position speed feedback which is based on the state observer theory The implemented algorithm is applicable to both SM PM and IPM synchronous motors as explained in 5 Appendix Section A 1 References A theoretical and experimental comparison between the implemented rotor flux observer and a classical VI estimator 6 Appendix Section A 1 References has pointed out the observer s advantage which turns out to be a clearly reduced dependence on the stator resistance variation and an overall robustness in terms of parameter variations A state observer in control theo
126. o the first motor The control present in group B relates to the second motor Group C does not depend on speed torque settings The control present in this group is related to both motors Figure 65 shows an example in which the first motor is set in torque mode and the second motor is set in speed mode The controls present in this page are used as follows To set the I reference field 1 in Figure 65 This is related to motor 1 and is only present if motor 1 is set in torque mode reference is expressed in s16A In this page the current references are always expressed as Cartesian coordinates lo la Figure 65 Dual control panel page PMSM FOC ver 3 0 Dual control panel Torque mode Speed mode Iq ref Speed 2500 015088 rom 15008 1500f rpm Id ref Ramp duration a roof g T Fault ack P Fault ack Start Stop both motors Exec simultanous Ramps te Release 1 6 MS19358V1 To set the ly reference field 3 in Figure 65 This is related to motor 1 This control is only present if motor 1 is set in torque mode Id reference is expressed in s16A In this page the current references are expressed always as Cartesian coordinates lasla To convert current expressed in Amps to current expressed in digit is possible to use the formula Current s16A Current Amp 65536 Rshunt Aop Vdd micro Set the final motor speed of a speed ramp field 6 in Figure 65 This is related to mot
127. ol screens and functionalities are described in depth at Section 8 This option can be selected via a setting in the ST MC Workbench GUI See Section 6 2 In this case the LCD UI software single or dual drive configuration is downloaded in the microcontroller in a reserved area located at the end of addressable flash memory Unless you erase it or change the configuration from single drive to dual drive or vice versa there is no need to download it again Even disabling the option with the GUI does not mean you need to flash it again when you reenable the option The latest STM3210B MCKIT Motor Control starter kits come with Motor Control Library V3 0 and LCD UI software single drive pre flashed If your Motor Control kit has a previous version of Motor Control Library you do not have the Motor Control kit but you are using one of the mentioned evaluation boards or you are changing configuration single dual you should follow one of the two procedures explained below to download the LCD UI Doc ID 18458 Rev 2 66 122 Working environment UM1052 67 122 Option 1 This option is straightforward and the preferred one 1 Use the STM32 and STM8 Flash loader demonstrator PC software package This is available from the ST web site http www st com internet com SOFTWARE RESOURCES SW COMPONENT SW DEMO um0462 zip and in the Installation folder Utilities Flash loader The User Manual UM0462 included in the package ful
128. option 2 Table 7 resources are allocated or saved accordingly Figure 32 Boundary between two space vector sectors Il mM Vo Vi K m at B 1 1V4 1 l I 1 l I T3 1 i i Ti 1 1 i i 1 I 1 1 1 1 1 1 1 1 i 1 1 1 1 V5 Ve ai15137 Similarly for a low modulation index the three duty cycles assume approximately the same value In this case the seven subperiods are reduced to three subperiods During all three 4 Doc ID 18458 Rev 2 42 122 Current sampling UM1052 4 2 1 43 122 subperiods the current through the shunt resistor is zero This means that it is not possible to sense any current when the imposed voltage vector falls in the gray area of the space vector diagram represented in Figure 33 Figure 33 Low modulation index ul 1 Li T2 T3 iShunt Definition of the noise parameter and boundary zone TRise is the time required for the data to become stable in the ADC channel after the power device has been switched on or off The duration of the ADC sampling is called the sampling time Thin is the minimum time required to perform the sampling and Tain TRise Sampling time dead time Dm is the value of Ty expressed in duty cycle percent It is related to the PWM frequency as follows Dyin Tmin x Fpwm x 100 Doc ID 18458 Rev 2 ky UM1052 Current sampling Figure 34 Definition of noise paramete
129. or 2 This control is only present if motor 2 is set in speed mode Motor speed is expressed in RPM The value set in this control is not automatically sent to the motor Doc ID 18458 Rev 2 1677 UM1052 LCD user interface 8 2 5 control related object but it is used to perform a speed ramp execution See the Exec button description field 9 in Figure 65 Set the duration of a speed ramp field 8 in Figure 65 This is related to motor 2 This control is only present if motor 2 is set in speed mode Duration is expressed in milliseconds The value set in this control is not automatically sent to the motor control related object but it is used to perform a speed ramp execution See the Exec button description field 9 in Figure 65 It is possible to set a duration value of O to program a ramp with an instantaneous change in the speed reference from the current speed to the final motor speed field 6 in Figure 65 e Execute a speed ramp by pushing the Exec button field 9 in Figure 65 This is related to motor 2 This control is only present if motor 2 is set in speed mode The Exec speed ramp command is sent to the motor control related object together with the final motor speed and duration currently selected field 6 and 8 in Figure 65 The Exec speed ramp command performs a speed ramp from the current speed to the final motor speed in a time defined by duration The command is buffered and takes effect only when the motor is i
130. p freertos org a00114 html CMSIS Doc ID 18458 Rev 2 Cortex Microcontroller Software Interface Standard v1 30 58 122 Working environment UM1052 6 1 59 122 Table 11 File structure continued File Subfile STMF10x_StdPeriph_Driver Description STMF10x Standard Peripherals Library Drivers V3 3 0 System amp Drive Params Contains default parameter files unpacked at installation time referring to the STM32 MC Kit or those generated by the ST MC workbench GUI according to user s system Utilities Contains code needed for specific functions of ST evaluation boards LCD drivers I O pin assignment port expanders and the ST Flash loader demonstrator V2 2 0 Project Contains source files of the demonstration user layer application and configuration files for IDEs In addition inside each IDE folder in MC library Compiled exe compiled MC library is provided in case of web distribution or created modified by the IDE in case of confidential distribution for single and dual motor drive FreeRTOS Project Contains source files of the demonstration user layer application based on FreeRTOS and configuration files for IDEs In addition inside each IDE folder in MC library Compiled exe compiled MC library is provided in case of web distribution or created modified by the IDE in case of confidential distribution for single and dual motor drive
131. peed optional Feed Forward high performance current regulation algorithm optional SVPWM generation Centered PWM pattern type Adjustable PWM frequency Torque control mode speed control mode on the fly switching capability Brake strategies optional Dissipative DC link brake resistor handling Motor phases short circuiting with optional hardware over current protection disabling When running Dual FOC any combination of the above mentioned speed feedback current sampling control mode optional algorithm Optimized I PMSM and SM PMSM drive Programmable speed ramps parameters duration and final target Programmable torque ramps parameters duration and final target Real time fine tuning of PID regulators Sensorless algorithm Flux weakening algorithm Start up procedure in case of sensorless Fault conditions management Over current Over voltage Over temperature Speed feedback reliability error FOC algorithm execution overrun Doc ID 18458 Rev 2 8 122 UM1052 9 122 e Easy customization of options pin out assignments CPU clock frequency through ST MC Workbench GUI C language code Compliant with MISRA C 2004 rules Conforms strictly with ISO ANSI Object oriented programming architecture User project and interface features There are two available options FreeRTOS based user project for STM32 performance line only e e
132. peration has not been successfully completed by the firmware The payload of this Error Acknowledgment frame is always 1 The list of error codes are shown in Table 36 List of error codes Figure 86 Revup sequence Iq ref Iq ref q Stage 0 Duration Stage 0 time Stage 0 Stage 1 Stage 2 Set revup data frame The set revup data frame Figure 87 is sent by the master to modify the revup parameters Revup sequence is a set of commands performed by the motor control firmware to drive the motor from zero speed up to run condition It is mandatory for sensorless configuration The sequence is split into several stages For each stage a duration final speed and final torque actually reference can be set up See Figure 86 Figure 87 Set revup data frame Set revup data frame PC ms 0x09 0x09 Stage Fs FT LB FT HB DR LB DR HB CRC Data Acknowledgment frame No errors BOARD gt 0x0 0x00 crc OR Set revup data frame PC umm 009 0x09 Stage FS_ x FT_LB FT_HB DR_LB DR_HB CRC Error Acknowledgment frame BOARD gt oFF ox ERROR_CODE CRC MS19380V1 The Master sends the requested stage parameter Doc ID 18458 Rev 2 ky UM1052 Serial communication class overview Note 10 7 The payload length is always 9 Stage is the revup stage that will b
133. pport ST STM32F10x Libraries STM32F10x_StdPeriph Driver inc SAMC library interface common S MC Application interface S System amp Drive Params Project Doc ID 18458 Rev 2 ky UM1052 MC application programming interface API 4 4 include libraries if in single motor drive Compi if in dual motor drive Compi MC Library led Exe MC_Library_single_drive a MC Library led Exe MC_Library_dual_drive a MC Application Compiled Exe MC Application a is the path where the MC Library is the path where MC Application 5 define symbols USE STDPERIPH DRIVER STM32F10X MD STM32F10X HD STM32F10X MD VL N STM32 part IDE project is located IDE project is located according to 6 Set the STM32 NVIC Nested Vectored Interrupt Controller priority group configuration the default option is NVIC PriorityGroup 3 The alternative option left to user choice is NVIC PriorityGroup 2 NVIC PriorityGroupConfig NVIC PriorityGroup 3 Table 14 shows preemption priorities used by the MC application user priorities should be lower higher number Table 14 MC application preemption priorities IRQ TIM1 UPDATE Preemption priority TIM8 UPDATE F103HD XL only DMA ojojo ADC1_2 F103 only ADC3 F103HD XL only ADC1 F100 only USART UI library TIMx GLOBAL spee
134. refer to space vector sector 4 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 Where e DT is dead time Thy 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 Ts is the sampling time of the Root part number 1 A D converter the following consideration is made under the hypothesis that Ts lt DT Ty Refer to the Root part number 1 reference manual for more detailed information This case typically occurs when SVPWM with low lt 60 modulation index is generated see Figure 25 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 26 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 Root part number 1 A D converter pins for both Phase B and C the time base is lower than the PWM period Figure 25 Low side switch gate signals low modulation indexes 100 90 80 70 60 50 40 30 20 10 0 0 30 60 Phase A Phase B Phase C Doc ID 18458 Rev 2 1677 UM1052 Current sampling Note that these current feedbacks are constant in the view in Figure 26 because it is assumed that commut
135. regulating the motor currents through their components igg and igs FOC manages to regulate the PMSM torque and flux current regulation is achieved by means of what is usually called a synchronous frame CR PWM Doc ID 18458 Rev 2 ky UM1052 Overview of the FOC and other implemented algorithms 3 4 PMSM maximum torque per ampere MTPA control The electromagnetic torque equation of an IPMSM is Tce 3 Vi Pi L 3 ca i EE e7 5P ds qs 7 qslds E 5P ds ds qs mlqs 7 qs qslas 5 BARE 3_ Paa Te 5P Pnlqs 5PLas Laslaslas The first term in this expression is the PM excitation torque The second term is the so called reluctance torque which represents an additional component due to the intrinsic salient magnetic structure Besides since Ly lt Lg typically reluctance and excitation torques have the same direction only if ig lt 0 Considering the torque equation it can be pointed out that the current components igs and igs both have a direct influence on torque generation The aim of the MTPA maximum torque per ampere control is to calculate the reference currents igs igs which maximize the ratio between produced electromagnetic torque and copper losses under the following condition 2 a2 I Nlas lds In Therefore given a set of motor parameters pole pairs direct and quadrature inductances Lg and Lg magnets flux linkage nominal current the MTPA trajectory is identified as the locus of igs
136. rface objects See Section 9 2 User interface configuration Once initialized the UI object is able to Get and set the selected motor control drive that the UI operates on UI_GetSlectedMC UI_SelectMC For example Ul SelectMC is required in the case of dual motor control in order to select the active drive to which commands are applied for example Set Get register start motor Get and set registers Ul SetReg Ul GetReg A register is a relevant MC quantity that can be exported from or imposed to MC objects through MCI MCT The list of this quantity MC PROTOCOL REG xxx is exported by UserlnterfaceClass h See STM32 FOC PMSM FW library v3 O developer Help file chm For example To set up the proportional term of the speed controller of the second motor Obtain the oMCT and oMCI object through GetMCIList GetMCTList functions exported by MCTasks h The oMCI and oMCT are two arrays of objects CMCI oMCI MC_NUM CMCT oMCT MC_NUM GetMCIList oMCI GeMCTList oMCT Instantiate and initialize a CUI object oUI UI_NewObject MC NULL UI Init oUI MC NUM oMCI oMCT MC NULL Select the motor drives UI_SelectMC oUI 2 Set the MC PROTOCOL REG SPEED KP register value UI SetReg oUI MC PROTOCOL REG SPEED KP lt Desired values A similar sequence can be used to get values from MC objects replacing the UI SetReg method with Ul GetReg method Execute a MC command Ul ExecCmd The list of available MC co
137. rive or dual motor drive by selecting SINGLE_DRIVE or DUAL_DRIVE from the combo box callout 2 Figure 54 Classes of the MC Library can create new objects resorting to dynamic memory allocation or statically allotting them from predefined size pools This is a matter of preference Modifying the header file MCLibraryConf h to choose the allocation callout 3 Figure 54 To activate dynamic allocation uncomment line 45 define MC_CLASS_DYNAMIC To activate static allocation comment this line Once all these settings have been configured and checked build the library callout 4 Figure 54 If SINGLE DRIVE was selected the output file MC Library single drive a is created in Installation folder Project EWARM MC Library Compiled Exe or Installation folder FreeRTOS Project EWARM MC Library Compiled Exe If DUAL DRIVE was selected the output file MC_Library_dual_drive a is created in Installation folder Project EWARM MC Library Compiled Exe or Installation folder FreeRTOS Project EWARM MC Library Compiled Exe Compliancy with MISRA C rules 2004 can be checked using IAR EWARM The test is performed by uncommenting line 35 define MISRA C 2004 BUILD in the header file Installation folder MC Library Interface Common MC_type h The compiler should be configured in Strict ISO ANSI standard C mode MISRA C 2004 rule 1 1 Motor control application project As explained in previous section
138. rotor electrical angle information For this purpose the latest available speed measurement see Section 7 4 Measurement units in dpp format adjusted as described above is added to the present electrical angle software variable value any time the FOC algorithm is executed See Section 7 4 Measurement units 5 2 3 Setting up the system when using Hall effect sensors Hall effect sensors are devices capable of sensing the polarity of the rotor s magnetic field they provide a logic output which is 0 or 1 depending on the magnetic pole they face and thus on the rotor position Typically in a three phase PM motor three Hall effect sensors are used to feed back the rotor position information They are usually mechanically displaced by either 120 or 60 and the presented firmware library was designed to support both possibilities As shown in Figure 48 the typical waveforms can be visualized at the sensor outputs in case of 60 and 120 displaced Hall sensors More particularly Figure 48 refers to an electrical period that is one mechanical revolution in the case of one pole pair motor ky Doc ID 18458 Rev 2 54 122 Rotor position speed feedback UM1052 55 122 Figure 48 60 and 120 displaced Hall sensor output waveforms 3 sensors 120 3 sensors 60 ai14826 Because the rotor position information they provide is absolute there is no need for any initial rotor prepositioning Particular attentio
139. rovided by the MC API rotor angle is expressed in s16degrees see Section 7 4 Measurement units ky Doc ID 18458 Rev 2 56 122 Rotor position speed feedback UM1052 5 3 1 57 122 Figure 50 Encoder output signals counter operation forward jitter backward jitter forward TH aaa Aag aa Aa ag ee aaa l a COUNTER up down up eel Ce Ag tai In addition the rotor angular velocity can be easily calculated as a time derivative of the angular position Setting up the system when using an encoder Extra care should be taken over what is considered to be the positive rolling direction this software library assumes that the positive rolling direction is the rolling direction of a machine that is fed with a three phase system of positive sequence 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 apply the following procedure 1 Turn the rotor by hand in the direction assumed to be positive and look at the B emf induced on the three motor phases For this purpose a neutral point may need to be reconstructed with three resistors if the real one is not available 2 Connect the motor phases to the hardware respecting the positive sequence for instance when using the M
140. rque reference for the active motor and active rev up controller stage The value set in this control is automatically sent to motor control related object and becomes active on next motor start up allowing the tuning of rev up sequence Final torque reference is expressed in Id current and becomes active on next motor start up To convert current expressed in Amps to current expressed in digits use the formula Current s16A Current Amp 65536 Rshunt Aop Vdd micro Stage Field 8 in Figure 70 To set the active rev up stage that receives the Duration F Speed and Final torque reference Iq new values set in Fields 5 6 and 7 It is possible to set the active rev up stage field 6 in Figure 72 Figure 71 shows an example of rev up sequence a Doc ID 18458 Rev 2 UM1052 User Interface class overview 9 User Interface class overview The STM32 FOC motor control firmware is arranged in software layers Figure 73 Each level can include the interface of the next level with the exception that the STM32 Std Library can be included in every level Figure 73 Software layers Level increasing STM32 Std Library This section describes the details of the User interface layer This is the highest software level present in the released STM32 PMSM FOC Library v3 0 The user interface class CUI manages the interaction between the user and the motor control library MC Libra
141. rs Ts switched off To switched on 3 iShunt i Sampling time e End of noise start of sampling e End of sampling start of conversion ai15139 The voltage demand vector lies in a region called the Regular region when the three duty cycles calculated by space vector modulation inside a PWM pattern differ from each other by more than Dyin This is represented in Figure 35 Figure 35 Regular region ai15140 The voltage demand vector lies in a region called Boundary 1 when two of the duty cycles differ from each other by less than Dyn and the third is greater than the other two and differs from them by more than Dyin This is represented in Figure 36 ky Doc ID 18458 Rev 2 44 122 Current sampling UM1052 Figure 36 Boundary 1 ai15141 The voltage demand vector lies in a region called Boundary 2 when two duty cycles differ from each other by less than Dyn and the third is smaller than the other two and differs from them by more than Dyjn This is represented in Figure 37 Figure 37 Boundary 2 ai15142 The voltage demand vector lies in a region called Boundary 3 when the three PWM signals differ from each other by less than Dyn This is represented in Figure 38 45 122 Doc ID 18458 Rev 2 ky UM1052 Current sampling 4 3 Figure 38 Boundary 3 ma KO HG
142. rty 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 features 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
143. ry is a system that provides an estimation of the internal state of a real system given its input and output measurement In our case the internal states of the motor are the back emfs and the phase currents while the input and output quantities supplied are the phase voltages and measured currents respectively see Figure 11 DC bus voltage measurement is used to convert voltage commands into voltage applied to motor phases Doc ID 18458 Rev 2 48 122 Rotor position speed feedback UM1052 5 1 1 49 122 Figure 41 General sensorless algorithm block diagram a a PAA J ghunts Va b c lap s The observed states are compared for consistency with the real system via the phase currents and the result is used to adjust the model through a gain vector K1 K2 The motor back emfs are defined as e Papa cos pat e5 PnP ASIN pat As can be seen they hold information about the rotor angle Then back emfs are fed to a block which is able to reconstruct the rotor electrical angle and speed This latter block can be a PLL Phase Locked Loop or a CORDIC COordinate Rotation Digital Computer depending on the user s choice In addition the module processes the output data and by doing so implements a safety feature that detects locked rotor condition or malfunctioning Figure 42 shows a scope capture taken while the motor is running in field oriented control positive rollin
144. ry via the motor control application layer MC Application In the current implementation the user interaction can be performed by any of the following devices digital to analog converter DAC LCD display plus joystick serial communication For each of these devices one or more derived class of Ul object have been implemented see Figure 74 e LCD Manager Class CLCD_UI is used to interact with the LCD color display It has been implemented over the LCD graphical library STMFC written in C language e Motor control protocol CMCP Ul is used to manage serial communications The serial communication is implemented over the Frame communication protocol class CFCP Transport layer The CFCP is in turn implemented over a physical layer communication class CCOM Physical layer Daughter classes of CCOM are CUSART_COM Cl2C_COM and CSPI_COM Presently only the CUSART_COM that implements the physical serial communication using USART channel has been implemented and only with PC master microcontroller slave configuration DAC manager CDAC_UI is used to manage the DAC outputs using a real DAC peripheral This is the default setting when DAC output is enabled using the STM32F100 Value line or STM32F103xE High density devices Doc ID 18458 Rev 2 98 122 User Interface class overview UM1052 9 1 99 122 Figure 74 User interface block diagram MCP Init CDACS Ul M519367V1 The DAC manager CDACT
145. s the Motor Control Application project is the Motor Control application program 1 Access the project using IAR IDE by opening the MC workspace of choice FreeRTOS based or not and clicking its name in the workspace tabbed browser callout 1 Doc ID 18458 Rev 2 ky UM1052 Working environment Figure 55 IDE toolbars and commands always refer to the active project the one whose tab is engraved Figure 55 displays the logical arrangement of files similar arrangement is in folders Figure 55 Motor control application project X IAR Embedded Workbench IDE File Edit View Project Simulator Tools Window Help Dae ew RELEASE A Files 4 SAPIN ANA ITEY O i file MCInterfaceClass c C HANG Reece RELEASE kd author IMS Systems Lab and Technical Mar LE Cy interface version Betai 0 date 03 Feb 2011 15 57 private brief This file contains interface of M EH i HLELLELLELELLELLLLELLELLEL EEL ELLER LELERLESLE LI ibrary lt br gt interface Ha O System amp Drive Params 3 Ha DI Motori E Control stage parameters h F Drive parameters h F Parameters conversion h E BI PMSM motor parameters h L_ F Power stage parameters h Ha DI Motor2 zh2pecenterrecopy COPYRIGHT 2011 SIMicroe E Control stage parameters motor 2 h i W4 E E Drive parameters motor 2 h El Parameters conversion motor 2 h E El PMSM motor 2 parameters h E Power stage parameters motor 2 h
146. s 6 The four bytes FS x represent the final speed expressed in rpm least significant byte and most significant byte DR LB and DR HB represent the duration expressed in milliseconds respectively least significant byte and most significant byte The Acknowledgment frame can be of two types e Data Acknowledgment frame if the operation has been successfully completed the payload of this Data Acknowledgment frame will be zero e Error Acknowledgment frame if the operation has not been successfully completed by the firmware The payload of this Error Acknowledgment frame is always 1 The list of error codes are shown in Table 36 List of error codes Doc ID 18458 Rev 2 ky UM1052 Serial communication class overview 10 5 Figure 84 Speed ramp Speed rpm 4 Final speed Actual speed ime s f Duration Exec Ramp command MS19377V1 Get revup data frame The get revup data frame Figure 85 is sent by the master to retrieve the current revup parameters Revup sequence is a set of commands performed by the motor control firmware to drive the motor from zero speed up to run condition It is mandatory for sensorless configuration The sequence is split into several stages and a duration final speed and final torque actually reference can be set up for each stage See Figure 86 Figure 85 Get revup data frame Get revup data frame PC map 0x08 0x01 Stag
147. s PLL State observer plus CORDIC Welcome message After the STM32 evaluation board is powered on or reset a welcome message displays on the LCD screen to inform the user about the firmware code loaded and the version of the release See Figure 63 Figure 63 STM32 Motor Control demonstration project welcome message ee PMSM FOC ver 3 0 HA R HO Firmware code Use the joystick to work with the application UP DOWN to move between enabled controls LEFT RIGTH to move between application pages LCD manager a SEL to interact with the selected control version aa ii oo AA Release version ky Release 1 0 The page shows a brief help on the operation of the demonstration program You can navigate to the next page by pressing the joystick RIGHT or go back to the previous page by pressing the joystick LEFT Pressing the KEY button at any time starts or stops the motor If you are using a dual motor control pressing KEY stops both motors Configuration and debug page Press the joystick RIGHT from the welcome page to enter the configuration and debug page To navigate between focusable controls on the page press the joystick UP DOWN Use the configuration and debug page shown in Figure 64 to select the active motor drive field 1 in Figure 64 This control is present only for dual motor control applications This combo box enables you to select the active motor drive Once the active motor is
148. s a running motor Used with a motor start a speed ramp with the last values of final motor speed and duration is performed If a fault condition occurs at any time the motor is stopped if running and the configuration and debug page displays Speed PID gain KP field 6 in Figure 66 This sets the proportional coefficient of the speed controller for the active motor The value set in this control is automatically sent to motor control related object allowing the run time tuning of the speed controller Speed PID gain KI field 7 in Figure 66 This sets the integral coefficient of the speed controller for the active motor The value set in this control is automatically sent to motor control related object allowing the run time tuning of speed controller Bus o field 8 in Figure 66 This sets the maximum percentage quantity of DC bus that can be utilized for a flux weakening operation for the active motor This control is present only if the flux weakening feature is enabled in the firmware This value should be a trade off between bus voltage exploitation higher bus means greater speed can be achieved and control margin the remaining bus voltage from that value to 100 is available for current regulation used by current regulators If it is too low control is no longer possible The value set in this control is automatically sent to the motor control related object allowing the run time tuning of flux weakening controll
149. served motor speed This variable is present only if a state observer plus PLL sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs Ibeta PLL Obs Bemf a PLL Observed beta component of motor phase s current expressed in alpha beta reference This variable is present only if a state observer plus PLL sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Observed alpha component of motor BEMF expressed in alpha beta reference This variable is present only if a state observer plus PLL sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs Bemf b PLL Obs El Ang CR Observed beta component of motor BEMF expressed in alpha beta reference This variable is present only if a state observer plus PLL sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Observed motor electrical angle This variable is present only if a state observer plus CORDIC sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs Rot Spd CR Observed motor speed This variable is present only if a state observer plus CORDIC sensor is configured as primary or auxiliary speed sensor and it is relative to this sensor Obs lalpha CR Observed alpha component of motor phase s current expressed in alpha beta reference This var
150. shunt current reading used resources single drive F103 F100 LD MD Adv timer Aux timer DMA ISR ADC Note TIM1 TIM3 DMA1 CH93 TIM1 UP ADC1 LD device configuration CH4 DMA1_CH4 DMA1_CH4_TC Rep gt 1 RC DAC cannot be used TIM4 DMA1_CH5 TIM1 UP i i TIM1 5 i ADC1 MD f t CH3 DMA1_CH4 DMA1_CH4_TC Reps1 42 device configuration Doc ID 18458 Rev 2 ky UM1052 Current sampling Table 7 Single shunt current reading used resources single or dual drive F103HD Adv timer AUX DMA ISR ADC Note timer Option1 used by the first motor configured TIM1 TIM5 DMA2 CH1 TIM1 UP ADC3 in single shunt or the CH4 DMA1 CH4 DMA1_CH4_TC Rep gt 1 second motor when the first is not single shunt Option1 used by the second motor DMA1 CH5 TIM P configured in single TIM8 npa Ay Hista TC Reps1 ADC1 shunt when the first CH2 TC Rep gt 1 motor is also configured in single shunt Option2 used by the first motor configured TIM8 TIM5 DMA2 CH1 TIM8 UP ADC3 in single shunt or by CH4 DMA2 CH2 DMA2_CH2_TC Rep gt 1 the second motor when the first is not single shunt Option2 used by the second motor figured in single TiM4 DMA1_CHS5 TIM1_UP ven TIM1 Pi ADC1 shunt when the first CH3 DMA1_CH4 DMA1_CH4_TC Rep gt 1 motorisalso configured in single shunt Using F103HD in single drive it is possible to choose between option 1 and
151. system efficiency q torque regulation for speed regulation torque f rotor speed of the system Where Errorsys Error of the system observed at time t T Errorsys Error of the system observed at time t T Tsampling T f X7 Kp x Errorsys K X YErrorsys Kg x Errorsys EffOrsys 1 0 NG a Derivative term can be disabled Equation 1 corresponds to a classical PID implementation where K is the proportional coefficient e Kis the integral coefficient Kg is the differential coefficient Regulator sampling time setting 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 12 the sampling time is directly part of the integral coefficient thus avoiding an extra multiplication Figure 13 describes the link between the time domain and the discrete system Doc ID 18458 Rev 2 ky UM1052 Overview of the FOC and other implemented algorithms Figur
152. t order system and the dynamics of the system can be assigned using a proper value of K See Figure 17 27 122 Doc ID 18458 Rev 2 ky UM1052 Overview of the FOC and other implemented algorithms Figure 17 Block diagram of closed loop system after pole zero cancellation Target current ai14853 It is important to note that the parameters used inside the PI algorithms must be integer numbers so calculated KI and KP values have to be expressed as fractions dividend divisor Moreover the PI algorithm does not include the PI sampling time T in the computation of the integral part See the following formula t n n kj e t dt kT Se kT K X e kT 0 kal k 1 Since the integral part of the controller is computed as a sum of successive errors it is required to include T in the K computation So the final formula can be expressed as Kp Le 2S KpDIV BARU Gp KjDIV LT AB AB 5 VBusDC Re hunt Aop 3 3 Usually it is possible to set ap the bandwidth of the closed loop system to 1500 rad s to obtain a good trade off between dynamic response and sensitivity to the measurement noise Doc ID 18458 Rev 2 28 122 Overview of the FOC and other implemented algorithms UM1052 3 9 29 122 Space vector PWM implementation Figure 18 shows the stator voltage components V and Vp while Figure 19 illustrates the corresponding PWM for each of the six space vector sectors Figure 18 V
153. thms sensorless position speed detection flux weakening MTPA feed forward current regulation Please contact your nearest ST sales office or support team to obtain the documentation you are interested in if it was not already included in the software package you received or available on the ST web site www st com Doc ID 18458 Rev 2 ky UM1052 Documentation architecture 2 2 Related documents Available from www arm com Cortex M3 Technical Reference Manual available from http infocenter arm com help topic com arm doc ddi0337e DDI0337E_cortex_m3_r1p 1 trm pdf Available from www st com or your STMicroelectronics sales office STM32F103xx datasheet STM32F100xx datasheet STM32F103xx user manual RM0008 STM32F100xx user manual RM0041 STM32F103xx AC induction motor IFOC software library V2 0 UM0483 STM32 and STM8 Flash Loader demonstrator UM0462 Doc ID 18458 Rev 2 14 122 Overview of the FOC and other implemented algorithms UM1052 3 3 1 15 122 Overview of the FOC and other implemented algorithms Introduction to the PMSM FOC drive This software library is designed to achieve the high dynamic performance in AC permanent magnet synchronous motor PMSM control offered by the well established field oriented control FOC strategy With this approach it can be stated that by controlling the two currents igg and igs Which are mathematical transformations of the stator currents it
154. tion and debug page Table 28 lists the actions that can be performed using this page Table 28 Sensorless tuning STO amp PLL page controls Control Description To modify the G1 gain parameter in real time The value set in this control is G1 field 1 in automatically sent to the motor control related object allowing the run time Figure 70 tuning of state observer object This value is proportional to the K1 observer g gain and is equal to C2 STO object parameter See STM32 FOC PMSM FW library v3_0 developer Help file chm To modify the G2 gain parameter in real time The value set in this control is a automatically sent to motor control related object allowing the run time tuning G2 field 2 in F f h Figure 70 of state observer object This value is proportional to the K2 observer gain and is equal to C4 STO object parameter See STM32 FOC PMSM FW library v3_0 developer Help file chm PLL KP field 3 in Figure 70 To set the proportional coefficient of the PLL for the active motor The value set in this control is automatically sent to motor control related object allowing the run time tuning of the current controller This control is only present if the state observer PLL object is set as the primary or auxiliary speed and position sensor and if the PLL tuning option is enabled in the firmware PLL KI field 4 in Figure 70 To set the integral coefficient of the PLL for the active motor The value set in this
155. too low prescaler direction prescaler direction Store capture prescalondirectan Prescaler Prescaler Time out TRUE MS19555V1 Electrical angle extrapolation implementation As shown in Figure 46 the speed measurement is not the only task performed in TIMx_IRQHandler As well as the speed measurement the high to low or low to high transition of the XORed signal also gives the possibility of synchronizing the software variable that contains the present electrical angle Synchronization is performed avoiding abrupt changes in the measured electrical angles In order to do this the difference between the expected electrical angle computed from the last speed measurement and the real electrical angle coming from the Hall sensor signals see Figure 66 is computed The new speed measurement is adjusted with this information in order to compensate the difference As can be seen in Figure 47 any Hall sensor transition gives very precise information about rotor position Doc ID 18458 Rev 2 ky UM1052 Rotor position speed feedback Figure 47 Hall sensor output transitions 3 sensors 120 ai14847 Furthermore the utilisation of the FOC algorithm implies the need for a good and constant rotor position accuracy including between two consecutive falling edges of the XORed signal which occurs each 60 electrical degrees For this reason it is clearly necessary to interpolate
156. tors at any time by pushing the KEY button e To execute simultaneous speed ramps on both motors push the Exec simultaneous ramps button field 13 in Figure 65 This button is disabled when at least one of the two motors is configured in torque mode The Exec speed ramp command is sent to both motor control objects together with related final motor speed and duration currently selected The Exec speed ramp command performs a speed ramp from the current speed to the final motor speed in a time defined by duration for each motor The commands are buffered and take effect only when the related motor is in RUN state Speed controller page This page is only present if the control mode set in ctrl mode field 3 in Figure 64 is speed mode To enter the speed controller page press the joystick RIGHT from the configuration and debug page or from dual control panel page if the firmware is configured in dual motor drive Doc ID 18458 Rev 2 88 122 LCD user interface UM1052 89 122 It is possible to navigate between focusable controls present in the page pressing joystick UP DOWN The speed controller page shown in Figure 66 is used to send commands and get feedback related to speed controller from the active motor There are four groups of control in this page list in the table below Table 23 Control groups Control group Set point Description Used to configure and execute a speed ramp PID gains Use
157. ure 42 1 1 tee 50 File SUUCTUIG 4 2050 cat Sates NGA Slaw aren dead ba eae a eal RE aE nae 58 Project coniiguralonS sperta areri nekenkia eee 66 Integrating the MC Interface in a user project nuuanu uaaa 75 MC application preemption priorities tenes 76 Priority configuration overall non FreeRTOS cee eee eee 76 Priority configuration overall FreeRTOS 000000 ee 77 Joystick actions and conventions 00 0 0 cee eee 79 List of controls used in the LCD demonstration program eee eae 81 Definitions s BAG Bet eee hee eee aad ba eee ee a wal ee ee aie ee 83 List of DAC variables 0 0 ccc teen teens 84 DAC variables related to each state observer sensor when two state observer speed sensors are selected 85 Fault conditions list a nG GA ONG ee pede ea be ee a PARA 86 Control QrOupS wines tse pies Backus Boo Ole ee ele E a Sha Lee 89 Speed controllers page controls 1 2 0 000 cece eae 89 Control groups a iaei oE E aa teas 91 Current controllers page controls a anaua 91 Control QrOupS s sia gesik pa nalo ppa eee di NG ba wid a E a a A a Ea bees Sad aa aE AS 93 Sensorless tuning STO amp PLL page controls a n anaua aae 94 Control groups 2 6 ee 96 Sensorless tuning STO amp PLL page controls 000 0 eee eee 96 User interface configuration Sensor codes a na sasaaa teens 102 User interface configuration CFG bit descript
158. v 2 ky UM1052 LCD user interface sa Table 20 List of DAC variables Variable name Description la Measured phase A motor current Ib Measured phase B motor current lalpha Measured alpha component of motor phase s current expressed in alpha beta P reference bata Measured beta component of motor phase s current expressed in alpha beta reference lq Measured q component of motor phase s current expressed in q d reference ld Measured d component of motor phase s current expressed in q d reference lq ref Target q component of motor phase s current expressed in q d reference ld ref Target d component of motor phase s current expressed in q d reference Vq Forced q component of motor phase s voltage expressed in q d reference Vd Forced d component of motor phase s voltage expressed in q d reference Walaa Forced alpha component of motor phase s voltage expressed in alpha beta p reference Vbeta Forced beta component of motor phase s voltage expressed in alpha beta reference Measured motor electrical angle This variable is present only if a real sensor Meas El Angle encoder Hall is configured as primary or auxiliary speed sensor and it is relative to this sensor Measured motor speed This variable is present only if a real sensor encoder Meas Rotor nn Higa Speed Hall is configured as primary or auxiliary speed sensor and it is relative to this sensor Observed
159. ximum of the B emf induced on Phase A and the first rising edge of signal H1 Enter it in the MC_hall_param h header file HALL_PHASE_SHIFT For your convenience an example with HALL PHASE SHIFT equal to 90 C is illustrated in Figure 49 Doc ID 18458 Rev 2 ky UM1052 Rotor position speed feedback Figure 49 Determination of Hall electrical phase shift Bemf Bemf Bemf H1 H2 120 H3 ge H2 60 Lo H3 HALL_PHASE_SHIFT 5 3 Encoder sensor feedback processing 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 the rotor absolute angle is known too For this reason it is always necessary when processing the encoder feedback to perform a rotor prepositioning before the first startup after any fault event or microcontroller reset Quadrature encoders have two output signals represented in Figure 50 as TI1 and T12 With these and with the Root part number 1 F100xx standard timer in encoder interface mode once the said alignment procedure has been executed it is possible to get information about the actual rotor angle and therefore rolling direction by simply reading the counter of the timer used to decode encoder signals For the purpose of MC Library and as information p
160. zn i P Ji oa Lis Lms 3 where e rc is the stator phase winding resistance e LL is the stator phase winding leakage inductance Lys is the stator phase winding magnetizing inductance in case of an IPMSM self and mutual inductances have a second harmonic component Lo proportional to cos 20 k x 27 3 with k 0 1 in addition to the constant component L neglecting higher order harmonics e O is the rotor electrical angle Gris the flux linkage due to permanent magnets The complexity of these equations is apparent as the three stator flux linkages are mutually coupled and what is more as they are dependent on the rotor position which is time varying and a function of the electromagnetic and load torques The reference frame theory simplifies the PM motor equations by making a change of variables that refers the stator quantities abc that can be visualized as directed along axes each 120 apart to qg components directed along a 90 apart axes rotating synchronously with the rotor and vice versa The d direct axis is aligned with the rotor flux while the q quadrature axis leads at 90 degrees in the positive rolling direction ky Doc ID 18458 Rev 2 18 122 Overview of the FOC and other implemented algorithms UM1052 3 3 1 19 122 The motor voltage and flux equations are simplified to rel Vas Islas dag Vas Islas at 7 thas Na Laslas Nga Laslas Pm
Download Pdf Manuals
Related Search
Related Contents
Edimax Technology EW-7206GAb Network Card User Manual Notice - Krups GUÍA DEL USUARIO Medidor de luz blanca de LED Modelo LT40 Transferir o manual de utilização LUVIT Portal MANUAL DE INSTRUÇÕES D2.1 User Needs Analysis Veeco Nanoman Atomic Force Microscope Montageanleitung Copyright © All rights reserved.
Failed to retrieve file