Home
Advanced developers guide for STM32F05xx/STM32F100xx/103xx
Contents
1. Current sensing carried out via a single shunt resistor placed on the DC bus link and implemented on an STM32F0Oxx It only supports a single motor drive 6 2 Speed and position feedback CSPD and its derived classes This class carries out the speed position sensor handling for both physical or FW emulated sensors Any object of this class must be linked to a derived class object Access to hardware peripherals if there is any is asked to derived classes which are differentiated according to type of speed position sensor In the STM32 PMSM FOC FW library v3 3 hall sensors quadrature encoder and sensorless are supported 4 Doc ID 18459 Rev 4 25 42 STM32 PMSM FOC FW library v3 3 class list UM1053 Table 3 Speed and position feedback CSPD and its derived classes Class ENCODER CENC_SPD Definition This derived class supports quadrature encoder and can be used with any STM32F05x STM32F100x STM32F103x STM32F2x STM32F40x or STM32F41x MCU By default index signal is not handled HALL CHALL SPD This derived class supports three hall sensors It can be used with any STM32F05x STM32F100x STM32F103x STM32F2x STM32F40x or STM32F41x MCU STO CSTO_SPD This derived class implements sensorless rotor position reconstruction based on current feedbacks bus voltage and applied motor phase voltages information The sensorless algorithm consists of a Luenberger state observer and a PLL
2. C77 UM1053 YZ User manual Advanced developers guide for STM32F05xx STM32F100xx 103xx STM32F2xx STM32F4xx MCUs PMSM single dual FOC library Introduction This manual describes the Motor Control Software Development Kit generically called software library designed for and to be used with STM32F05xx 100xx 103xx STM2F2xx 4xx microcontrollers 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 M cores the Cortex MO for STM32F05xx the Cortex M3 for STM32F1xx and STM32F2xx and the Cortex M4 for STM32F4xx 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 spac
3. STO_CORDIC CSTOC_SPD This derived class implements sensorless rotor position reconstruction based on current feedbacks bus voltage and applied motor phase voltages information The sensorless algorithm consists of a Luenberger state observer and an iterative algorithm for trigonometric arctg function computation Virtual speed sensor This derived class is mainly used during ramp up if an object of one of the sensorless speed position classes CSTO_SPD or CSTOC_SPD is used as a main speed sensor Used in conjunction with a rev up controller and a speed and torque controller it allows customizing ramp up An object of this class CVSS_SPD g emulates a real sensor during motor rev up by returning on demand a virtual angle and or a virtual speed in accordance with the time base and the acceleration set by derived class specific method VSPD_SetMecAcceleration 6 3 Field oriented control drive CFOC and its derived classes This class implements Field Oriented Control FOC and additional methods that may be required by internal permanent magnet motors for example Any object of this class must be linked to a derived class object The key methods for this class are e FOC_CurrController which carries out the current regulation field orientation and must be called at PWM frequency or an integer sub multiple e FOC_CalcCurrRef which updates the reference stator current components lgre and laret With the
4. Advantages of object oriented programming 3 3 1 3 2 3 3 3 4 Advantages of object oriented programming This section describes the fundamental concepts and features of OOP and the benefits of this type of approach with particular reference to STM32 FOC PMSM SDK v3 3 Efficient multiple motor control OOP makes it possible to create multiple instances of objects for example two object encoders without duplicating the footprint of the Flash memory necessary to handle them This efficiency of OOP in terms of code size is even more marked when exploiting inheritance Taking the example discussed in the previous section as a reference the GetElSpeedDpp method is linked in the executable only once no matter how many instances have been created of the derived classes encoder hall or state observer Increased safety through data hiding Object variables are bound to the object and only accessible through the object methods This prevents the object variables from being accidentally modified improving robustness for the final applications fuel pumps electric traction or applications related to human safety for example Modularity The source code for a class implementation can be written and maintained separately from other classes This means that new versions of classes may be released separately from the others on the condition that the class interface and the method behavior are not modified Abstraction You on
5. Demonstrative LCD user interface Demonstrative serial communication protocol User manual UM1053 Advanced developers guide for STM32F05xx STM32F 1 00xx 103xx STM32F2xx STM32F4xx MCUs PMSM single dual FOC library 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 STM32F10x STM32F2x or STM32F4x 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 algorithms 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 a
6. It always returns a constant programmable temperature Digital Output CDOUT class This class is used to abstract the concept of digital output driving from its hardware dependent implementation With particular reference to motor control this class can be used to drive in rush current limiter devices or handle resistive brake turn on and turn off for example Encoder Alignment Controller CEAC class This class is only used if a quadrature encoder is used as a main or auxiliary sensor In conjunction with a virtual speed sensor a speed and torque controller and FOC drive objects this class handles the initial encoder calibration which comprises a rotor alignment in a given position necessary to make the information coming from a quadrature encoder absolute See Section 6 3 for more information about the alignment procedure In case of a dynamic allocation the object may be destroyed after the alignment has been executed and created only when necessary Rev up controller CRUC class This class is only used if an object of one of the sensorless classes is used as a main speed position sensor Used in conjunction with a speed and torque controller and a virtual speed sensor this class enables a complete customization of the motor phase current waveforms during motor ramp up In the present implementation the rev up is divided into smaller portions called phases where both speed and current amplitude can vary linea
7. STM32F4xx or STM32F05xx peripherals functions is only required for customizing existing modules and for adding new ones for a complete application development Table 1 lists the microcontrollers concerned by this user manual Table 1 Applicable products Type Applicable products Microcontrollers STM32F05xx STM32F100xx STM32F103xx STM32F2xx STM32F4xx November 2012 Doc ID 18459 Rev 4 1 42 www st com Contents UM1053 Contents 1 Documentation architecture 000 eee ee 7 1 1 Where to find the information you need aa 7 1 2 Related documents 00 cece eee eee eens 8 2 Object oriented programming OOP 000ee ee ee ee eens 9 3 Advantages of object oriented programming 2 00085 11 3 1 Efficient multiple motor control 2 0 ee 11 3 2 Increased safety through data hiding eee eee eee 11 3 3 Modularity 225 5502 es0baw AA AA 11 3 4 ASADO see 85 a nha ere wt Ace ie abo SALE ng Da eae eee he aa 11 4 STM32 PMSM FOC FW library C implementation of OOP 12 4 1 Generic classes source files organization and content 12 4 2 Inheritance implementation 00 0 ee 16 4 3 Derived classes source file organization and content 17 4 4 Motor control library related interrupt handling 21 5 How to create a user defined class 000 c cece 23 6 STM32 PMSM FOC FW library v3 3 class l
8. In order to function correctly the priority of this task must be set as the highest priority available in the application Doc ID 18459 Rev 4 37 42 Description of tasks UM1053 8 4 38 42 Figure 11 High frequency task flow diagram Only if auxiliary sensor is emulated Eros sTo _CR classes Only if mainsensor is emulated STO or STO_CR classes _ Yes Only incase of dual motor control M519391V1 Safety task The safety task executes the safety checks bus voltage and temperature for example related to each of the drives in sequence The actions to be taken in case of an over voltage are managed here These tasks are e turning on low side switches turning off PWM or turning on the brake resistor depending on the ON OVER VOLTAGE definition in Drive parameters h The default execution rate for this task is 2 kHz Figure 12 shows the safety task flow diagram Doc ID 18459 Rev 4 SY UM1053 Description of tasks Figure 12 Safety task flow diagram MS19392V1 1577 Doc ID 18459 Rev 4 39 42 Bibliography UM1053 9 40 42 Bibliography 1 Armstrong The Quarks of Object Oriented Development In descending order of popularity the quarks are Inheritance Object Class Encapsulation Method Message Passing Polymorphism Abstraction ag 2 Pierce Benjamin 2002 MIT Press ISBN 0 262 16209 1 section 18 1 What is Object Oriented Pr
9. KG KANAN KEKED AA 41 ky Doc ID 18459 Rev 4 3 42 List of tables UM1053 List of tables Table 1 Table 2 Table 3 Table 4 Table 5 Table 6 Table 7 Table 8 4 42 Applicable products aaa eee rinka Fae eee KAKA be ea a ere 1 Derived classes 0 0 00 eee 24 Speed and position feedback CSPD and its derived classes 26 Field Oriented Control drive CFOC and its derived classes 27 Bus voltage sensor CVBS and its derived classes 0 0 000 27 Bus voltage sensor CVBS and its derived classes eee 28 State machine STM class available states 0 cc eens 29 Document revision history 0 ct eee 41 Doc ID 18459 Rev 4 ky UM1053 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 Generic class structure 2 2 eae 16 Derived class object private structure eee 17 Motor control interrupt handling 0 cee eee 22 State machine flow diagram 0000 c ett 30 Field orientation speed and torque regulation 1 1 0 0 0 eee ee 31 Motor ramp up procedure neta 32 Rotor alignment for encoder calibration 0 0 0 0 c ee eee 33 Stator current orientation convention and amplitude temporal variation 34 Low frequency task flow diagram
10. KKK KKK KKK KK KKK ek kt rk rr L file ExampleClass c author IMS Systems Lab and Technical Marketing MC Team version V0 0 1 brief This file contains interface of Example class kkxkxkxkxkxkxkkkkkkkkkkkkkkkkkkkkkkkkkkkkxkkkkxkkkkkkkkkkkkkkkkkkkkkkkkkkkxk WU include Mm G ixampleClass h include ExamplePrivate h include MCLibraryConf h include MC_type h ifdef MC CLASS DYNAMIC include else _CEXMP_t unsigned endif brief param structure stdlib h Used for dynamic allocation EXMPpool MAX_EXMP_NUM char EXMP Allocated Ou Creates an object of the class Example pExampleParams pointer to an Example parameters retval CEXMP new instance of Example object 7 CEXMP O CEXMP EXMP_NewObject pExampleParams_t pExampleParams EXMP ifdef MC_CLASS_DYNAMIC OEXMP else CEXMP calloc lu sizeof CEXMP t if EXMP Allocated lt MAX EXMP NUM _OEXMP amp EXMPpool EXMP Allocatedt t else f _OEXMP MC NULL endif OEXMP 5pParams str pParams_t pExampleParams return CEXMP oEXMP 4 Doc ID 18459 Rev 4 15 42 STM32 PMSM FOC FW library C implementation of OOP UM1053 4 2 16 42 brief Example of public method of the class Example param this related object of class CEXMP retval none void EXMP_Fu
11. _CEXMP this gt DerivedClass gt DVars_str derived_Vars 0u brief Example of private method of the class Derived to implement an MC IRQ function param this related object param flag used to distinguish between various IRQ sources retval none j static void DRV IRQHandler void this unsigned char flag f if flag 1u f DCDRV EXMP _CEXMP this gt DerivedClass gt DVars_str derived_Vars 4 4 Motor control library related interrupt handling The implementation of certain classes such as speed or current sensors may require the execution of specific program lines referenced below as MC IRQ Handler when a specific event occurs exploiting the related Interrupt Service Routine ISR The same ISR must also be available at the User project level see also UM1052 to permit the customization of an application software by adding personal code lines in the same ISR In order to keep the motor control library and the user project layers separate it is necessary to implement a mechanism that enables triggering the execution of MC IRQ Handlers bundled within a given class without permitting any explicit reference to the motor control library objects from the user layer With this mechanism the stm32fxxx_MC_it c module containing the definitions of all the IRQ Handlers that require certain MC code lines to be executed is put at the disposal of the user by including it at the user project lev
12. case of FreeRTOS based applications for example User commands such as run or stop motor are also processed in this task Refer to UM1052 for more information about user commands that can be provided to the MC application layer Figure 9 shows the low frequency task flow diagram Note that the IDLE_ALIGNMENT state is only available if the encoder is being used either as a main or an auxiliary sensor Figure 9 Low frequency task flow diagram Case IDLE ALIGNMENT pete feedback Case ANY STOP MSIE Doc ID 18459 Rev 4 35 42 Description of tasks UM1053 8 2 8 3 36 42 Medium frequency task The medium frequency task executes the tasks related to each of the drives in sequence It executes certain control duties depending on the state of the related state machine Duties requiring a specific timing such as speed controller are executed with a default task refresh rate of 500 Hz To function correctly the priority of this task must be higher that the low frequency task priority Figure 10 shows the medium frequency task flow diagram Figure 10 The medium frequency task flow diagram Case START Sensor edspeed 3 Sensor less speed posilontesdiank heres EERE tae ay ee eae position feedback Goin START RUN state Update main auxiliary average speed Switch State Only if encoder main or aux speed position feedback Case START_RUN Case ALIGNMENT Initializations N
13. class object is cast to the public derived class type CDRV_EXMP and returned KEKE KKK KKK KKK KKK KKK KKK KEKE KK KKK KEKE KK KKK KEKE K KEKE KK KKK KK KKK KKK KKK KKK KKEKK file Derived_ExampleClass c author IMS Systems Lab and Technical Marketing MC Team version V0 0 1 x brief This file contains private implementation of Derived class kkxkxkxkxkxkxkkxkxkkkxkkkkkkkkkkkkkkkkxkkkkkkxkkkkxkkkkkkkkkkkkkkkkkkkkkkkkkkkk ed include ExampleClass h include ExamplePrivate h include Derived ExampleClass h 4 Doc ID 18459 Rev 4 19 42 STM32 PMSM FOC FW library C implementation of OOP UM1053 include Derived_ExamplePrivate h include MCLibraryConf h include MC_type h include MCIRQHandlerPrivate h lt Only if derived class implementation requires to be triggered by an interrupt ifdef MC CLASS DYNAMIC include stdlib h Used for dynamic allocation else DCDRV EXMP t DRV_EXMPpool MAX DRV EXMP NUM unsigned char DRV EXMP Allocated 0u endif static void DRV VFunc CEXMP this brief Creates an object of the class Derived param pExampleParams pointer to an Example parameters structure param pDerivedParams pointer to an Derived parameters structure retval CDRV_EXMP new instance of Derived object x CDRV EXMP DRV NewObject pExampleParams t pExampleP
14. derived class implementation and required electrical torque This class does not contain references to peripherals and is thus hardware independent Derived classes are differentiated according to required additional methods 26 42 Doc ID 18459 Rev 4 ky UM1053 STM32 PMSM FOC FW library v3 3 class list Table 4 Field Oriented Control drive CFOC and its derived classes Class Description Derived class designed for driving surface mounted motors No additional SM CSM_FOC methods have been implemented here Derived classes used for surface magnet motors SM PMSM when flux SMF CSMF_FOC weakening is required Derived classes used for internal permanent magnet motors I PMSM IMF CIMF_FOC Maximum Torque Per Ampere MTPA and flux weakening additional methods are available for this class Derived classes used for internal permanent magnet motors I PMSM high end drives Maximum Torque Per Ampere MTPA flux weakening additional methods and auxiliary feed forward current regulator are available for this class IMFF CIMFF_FOC 6 4 Bus voltage sensor CVBS and its derived classes This class implements either a virtual or a real bus voltage depending on the sensor availability Any object of this class must be linked to a derived class object If any the access to MCU peripherals is delegated to the derived classes so that the base class implementation is kept hardware independent Der
15. 7 State machine STM class available states State Description Persistent state The following state can be IDLE IDLE STARDJ if a start motor command has been given IDLE ALIGNMENT if a start alignment command has been given Pass through state The code to be executed only once between IDLE and ALIGNMENT states is executed here The following state is usually IBLELAUIGNMENT ALIGNMENT but it can also be ANY STOP if a stop motor command has been given ALIGNMENT Persistent state The following state is ANY STOP Pass through state The code to be executed only once between IDLE and IDLE START START states is executed here The following state is usually START but it can also be ANY STOP if a stop motor command has been given Persistent state where the motor start up is intended to be executed The START following state is usually START RUN as soon as the first validated speed has been detected ANY STOP is also possible if a stop motor command has been executed Pass through state The code to be executed only once between START START RUN and RUN states is executed here The following state is usually RUN but it can also be ANY STOP if a stop motor command has been given RUN Persistent state with running motor The following state is usually ANY STOP when a stop motor command has been executed ANY STOP Pass through state The code to be executed only once between any state E and STOP is executed here The following state is usually S
16. 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 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 2012 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 42 42 Doc ID 18459 Rev 4 ky
17. TOP Persistent state The following state is usually STOP_IDLE as soon as the STOP ne i aie conditions required by the application are detected STOP IDLE Pass through state The code to be executed only once between STOP and IDLE is executed here The following state is usually IDLE Doc ID 18459 Rev 4 29 42 STM32 PMSM FOC FW library v3 3 class list UM1053 Table 7 State machine STM class available states continued State FAULT_NOW Description Persistent state The state can be moved from any condition directly to this state by the STM_FaultProcessing method As soon as all the fault conditions have disappeared the state is moved into FAULT_OVER FAULT_OVER Persistent state where the application is intended to stay after all the fault conditions have disappeared The following state is usually STOP_IDLE The state is moved as soon as the user has acknowledged the fault event Figure 4 State machine flow diagram IDLE FAULT_NOW a IDLE_ALIGNMENT IDLE_START ALIGNMENT T Permanent states 4 Pass trough states STO P y FAULT_OVER START START_RUN i EEN RUN 4 ANY_STOP 4 STOP_IDLE lt M5180851 6 11 PI CPI and PID CPID controller classes PI and PID controller classes realize PI and PID regulators respectively The PID class is seen as a derived class from PI by adding the particular functionality of the deriva
18. _ExampleClass h author IMS Systems Lab and Technical Marketing MC Team version V0 0 1 brief This file contains interface of Derived class KEKE KKK KKK KKK KKK KKK KKK KEKE KKK KKK KEK KEK KKK KKK KEKE KKK KKK KKK KEK KKK KKK KK KKK KEKKE x include MC type h ky Doc ID 18459 Rev 4 17 42 STM32 PMSM FOC FW library C implementation of OOP UM1053 18 42 brief Public Derived class definition xJ typedef struct CDRV_EXMP_t CDRV_EXMP brief Derived class parameters definition x typedef const struct f unsigned int parami lt Example of parameter DerivedParams_t pDerivedParams_t brief Creates an object of the class Derived param pExampleParams pointer to an Example parameters structure param pDerivedParams pointer to a Derived parameters structure retval CDRV_EXMP new instance of Derived object Kg CDRV EXMP DRV NewObject pExampleParams t pExampleParams pDerivedParams t pDerivedParams brief Example of public method of the class Derived param this related object of class CDRV_EXMP retval none y void DRV_Func CDRV_EXMP this Derived_ExamplePrivate h Located in MC library inc available only for confidential distribution of STM32 FOC PMSM SDK v3 3 this is a class private header file that contains private definitions required for the derived class implementation It contai
19. a single motor drive has been instanced R3 F2XX CR3F2XX PWMC Current sensing carried out via three shunt resistors placed below low side switches on the three inverter legs and implemented on an STM32F2xx MCU Although it is designed to support dual motor drive it can also be used when a single motor drive has been instanced ICS F2XX CIF2XX_PWMC Current sensing carried out through isolated current sensors and implemented on an STM32F2xx MCU Although it is designed to support dual motor drive it can also be used when a single motor drive has been instanced R1 F4XX CR1F4XX PWMC Current sensing carried out via a single shunt resistor placed on the DC bus link and implemented on an STM32F40x or STM32F41x MCU Although it is designed to support dual motor drive it can also be used when a single motor drive has been instanced R3 F4XX CR3F4XX PWMC Current sensing carried out via three shunt resistors placed below low side switches on the three inverter legs and implemented on an STM32F40x or STM32F41x MCU Although it is designed to support dual motor drive it can also be used when a single motor drive has been instanced ICS F4XX CIF4XX PWMC Current sensing carried out through isolated current sensors and implemented on an STM32F40x or STM32F41x MCU Although it is designed to support dual motor drive it can also be used when a single motor drive has been instanced R1 FOXX CR1FOXX PWMC
20. al distribution Contact your nearest ST sales office or support team for further information Current reading and PWM generation CPWMC and its derived classes This class implements both the functionality of the current reading sensor and PWM generator Any object of this class must be linked to a derived class object In order to increase the modularity of the library the access to the MCU peripherals has been moved to the derived classes which have been additionally differentiated by the hardware current sensing topology The derived classes are Table 2 Derived classes Class Definition Current sensing carried out via a single shunt resistor placed on the DC bus link and implemented on an STM32F100x MCU value line devices It only supports a single motor drive R1_VL1 CR1VL1_PWMC Current sensing carried out via a single shunt resistor and implemented on an STM32F103x MCU where x 4 6 8 B performance line low and medium density devices It only supports a single motor drive R1_LM1 CR1LM1 PWMC Current sensing carried out via a single shunt resistor and implemented on R1 HD2 an STM32F103x MCU where x C D E performance line high density CR1HD2 PWMC devices Although it is designed to support dual motor drive it can also be used when a single motor drive has been instanced Current sensing carried out via three shunt resistors placed below low side R3 LM1 switches on the three inverter le
21. ameter structure typedef ExampleParams_t Params_t pParams_t brief Virtual methods container x typedef struct f void pIRQ Handler void this unsigned char flag lt Only if class implementation requires to be triggered by an interrupt void pVFunc CEXMP this lt Example of virtual function pointer Methods_t pMethods_t brief Private Example class definition mj typedef struct f Methods t Methods str lt Virtual methods container Vars t Vars str lt Class members container pParams t pParams str lt Class parameters container void DerivedClass lt Pointer to derived class CEXMP t _CEXMP If either the base or derived class implementation requires the execution of program lines to be triggered by an interrupt a pointer to those program lines pIRQ Handler is also defined See Section 4 4 Motor control library related interrupt handling for more information about MC library IRQ handler management ExampleClass c Located in MC library src available only for confidential distribution of STM32 FOC PMSM SDK v3 3 this is the source file that contains the implementation of class methods This file includes both the interface and the private definitions of the same class The Example_NewObject method merits some explanation This method creates objects of Example class CEXMP on demand Two different implementations of Ex
22. ample NewObject are proposed depending on the availability of the MC CLASS DYNAMIC in MCLibraryCont h definition If MC_CLASS_DYNAMIC is defined the dynamic RAM allocation is enabled and objects are created through calloc standard library subroutine resulting in an efficient exploitation of the RAM memory This approach is not compatible with MISRA C 2004 rules compliancy because of the potential risks of memory leaks and memory corruption introduced by the dynamic memory allocation On the contrary the dynamic memory allocation is disabled when the user comments the MC_CLASS_DYNAMIC definition In this case an array of objects is statically and previously allocated in the RAM The list of objects that are reserved for each of the classes is defined in MCLibraryConf h for both single motor and dual motor MAX_EXMP_NUM and similar In order to prevent the compiler from reserving RAM memory for objects that will never be created you can edit pool dimension accordingly to the final application Doc ID 18459 Rev 4 ky UM1053 STM32 PMSM FOC FW library C implementation of OOP Pool dimension tailoring is only permitted in STM32 FOC PMSM SDK v3 3 confidential distribution In case of a web distribution no additional objects can be instanced by the user Only the following exceptions are allowed up to 3 PID objects up to 5 PI objects up to 5 digital output objects KEKE KKK KKK KEK KKK KKK KKK KKK KEK KKK KKK KK KKK KEK KKK KK KEK
23. ance is the process through which a class inherits the member and the methods of another class This type of relationship is called child parent or derived base class Derived child classes are a more specialized version of the base parent class as they inherit attributes and behavior from the base parent class but can also introduce their own For example a class speed sensor might have subclasses called encoder hall and state observer Supposing that speed sensor classes define a method called GetEISpeedDpp that exports the related internal variable all of its derived classes inherit this method and the related internal variable so that the programmer only needs to write it once and to link to it once In addition to speed sensor class methods encoder hall and state observer can have their own method IsObserverConverged for example and their own implementation of base class methods through the so called virtual functions This way the user can always call a base class method CalcElectricalAngle for example without knowing the implementation done in the derived class Doc ID 18459 Rev 4 9 42 Object oriented programming OOP UM1053 Interface Objects define their interaction with the outside world through the methods that they expose The list of methods exported to the application level that operate on that object class constitute the only interface of that object class 10 42 Doc ID 18459 Rev 4 ky UM1053
24. arams pDerivedParams_t pDerivedParams f CEXMP _oExample DCDRV_EXMP _oDerived oExample _CEXMP EXMP_NewObject pExampleParams ifdef MC_CLASS DYNAMIC _oDerived DCDRV EXMP calloc lu sizeof DCDRV EXMP t else if DRV EXMP Allocated lt MAX DRV EXMP NUM oDerived amp DRV_EXMPpool DRV_EXMP_Allocated oDerived MC_NULL endif ODerived 5pDParams str pDerivedParams _oExample gt DerivedClass void oDerived oExample gt Methods_str pVFunc amp DRV_VFunc _oExample gt Methods_str pIRQ Handler amp DRV_IRQHandler Set IRQ Handler pDerivedParams 5IRQno _CMCIRQ _oExample return CDRV_EXMP _oExample brief Example of private method of the class Derived to implement a virtual a 20 42 Doc ID 18459 Rev 4 UM1053 STM32 PMSM FOC FW library C implementation of OOP x function of class Example param this related object of class CEXMP retval none x static void DRV VFunc CEXMP this f _DCDRV_EXMP CEXMP this 5 DerivedClass gt DVars_str derived_Vars 0u brief Example of public method of the class Derived param this related object of class CDRV EXMP retval none void DRV_Func CDRV_EXMP this _DCDRV_EXMP
25. ass portions as shown in Figure 2 Figure 2 Derived class object private structure Base class structure Virtual methods Variables Parameters Pointer to derived class object MS19383V1 The derived class portion of a derived class object is always accessed through its base class portion which represents the public entry point for both base and derived class specific members 4 3 Derived classes source file organization and content In order to complete the picture of derived class source files templates are shown here for the Derived class derived from the base class Example Derived_ExampleClass h Located in MC library interface this is the public header file that contains the interface of the Derived_Example class As for ExampleClass h this header file contains everything necessary to work with the related class This file contains methods specific of the derived class the public definition of the derived class type and the type structure that contains the constant parameters required to create the derived class object In addition and only if necessary this file contains definitions of certain types required for using methods Creating a new instance of a derived class object requires pointers to both base and derived classes parameter structures see also Derived ExampleClass c KEK KKK KKK KKK KKK KKK KK KEK KEK KKK KK KEKE KEK KKK KKK KEKE KEK KKK KKK KKK KKK KKK KEK KE KKKEKEKE file Derived
26. celeration is set equal to O oEAC also configures the speed and torque controller in STC_TORQUE_MODE and commands the start of a ramp with proper duration and final current amplitude The STC_CalcTorqueReference method clocked at MF works as a ramp generator and its output is fed through the FOC_SetCurrRef method to the oFOC object previously set in EXTERNAL mode As soon as the alignment duration is finished oEAC initializes the speed position sensor electrical angle correctly using the SPD_SetMechanicalAngle method Figure 8 illustrates the temporal lq current amplitude variation and the convention used for the current orientation Doc ID 18459 Rev 4 33 42 Class interaction UM1053 34 42 Figure 8 Stator current orientation convention and amplitude temporal variation MS19388 1 a Doc ID 18459 Rev 4 UM1053 Description of tasks 8 8 1 Description of tasks This section describes the four tasks that are necessary for each motor in order to manage the motor drives correctly Low frequency task The low frequency task executes the tasks related to each of the drives in sequence It includes those duties that do not require a very precise timing and or that need a low refresh rate such as a stop state permanency time or boot capacitors charge time counting The default refresh rate is 100 Hz and the priority should be set just above the background main priority tskIDLE_PRIORITY 1 in the
27. d Figure 6 illustrates how motor rev up is handled when STO_SPD or STOC_SPD objects are used as a main sensor As already mentioned the rev up is divided into portions also called phases or stages during which both the applied electrical frequency and the amplitude of the phase motor current change linearly Every time a new rev up phase begins the RUC_Exec method configures both the virtual speed sensor and the speed and torque controller in order to get the right electrical frequency and amplitude increases throughout the phase The electrical frequency increase is carried out by the virtual speed sensor which at the MF clock rate default value 500Hz updates the applied electrical frequency by integrating the acceleration set by RUC via the VSPD_SetMecAcceleration method The electrical angle is updated at the same time as the HF clock rate the default value is the PWM frequency by integrating the applied electrical frequency As the oSPD held by the FOC drive object has been previously set to be equal to the virtual speed sensor object oVss using the SPD_SetSpeedSensor method the oVss electrical angle is then used to orient correctly the stator current components and lg In the meantime the motor phase current target amplitude is also changed This is handled by the STC_CalcTorqueReference method clocked by MF clock on the oSTC object previously configured in STC TORQUE MODE for this purpose The current com
28. e vector modulation energy efficiency optimizations as well as sensor reading 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 STM32F2xx or STM32F4xx devices the PMSM FOC library allows 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 UART 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 MC Workbench allows a complete and easy customization of the PMSM FOC library In conjunction with the ST motor control starter kits 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 this programming In depth know how of STM32F100xx STM32F103xx STM32F2xx
29. ee tenes 35 The medium frequency task flow diagram eee 36 High frequency task flow diagram tees 38 Safety task flow diagram cette 39 Doc ID 18459 Rev 4 5 42 UM1053 6 42 About this document This document provides important information about the STM32 FOC PMSM FW library v3 3 with specific focus on its object oriented programming implementation and its task organized structure It provides An overview of object oriented programming highlighting the advantages of this kind of approach e A description of objects classes and relationships that have been implemented in C language in the FW library e A brief description for each of the implemented classes and the interaction between them for certain procedures e A description of the motor control tasks Doc ID 18459 Rev 4 ky UM1053 Documentation architecture 1 1 Documentation architecture Where to find the information you need Technical information about the MC SDK is organized by topic The following is a list of the documents that are available and the subjects they cover User manual UM1052 STM32F05xx STM32F 1 00xx STM32F 103xx STM32F2xx STM32F4xx PMSM single dual FOC SDK v3 3 provides the following Features Architecture Workspace Customization processes Overview of algorithms implemented FOC current sensors speed sensors MC API Demonstrative user project
30. el Both the stm32fxxx_MC_it c and the motor control libraries include a module MCIRQHandlerClass which privately holds a motor Doc ID 18459 Rev 4 21 42 STM32 PMSM FOC FW library C implementation of OOP UM1053 22 42 control vector table MC_IRQTable that contains the set of objects that need to be triggered by an ISR The filling of a given position in the table is performed when the corresponding object is created inside the related XXX_New_Object method by means of the Set_IRQ_Handler function call Figure 3 illustrates this process Figure 3 Motor control interrupt handling area Bi TB aa EE A E O E EOE OE E naan eee PEEP E E AA EN PA E E E E EN AE E T E E E E XXX_NewObjed Set IRQ Handler Position1 Object1 return Object static void XXX IRQHandlerghis flag void Peripheral_X_IRQ Handler void Set IRQ HandlerpIRQAddr CMCIRQ oIRQ MC_IRQ Table bIRQAdkir ol RQ IfPerip hera Flag1 Clear Flag Peripheral 1 Flag g Exec IRQ HandlerPositiont Flag1 Exec IRQ Handler bIRQAddr flag MC_IRQ Table bI RQAddr gt pIROQ Handlerf void MC IRQTab e bIRQAdar flag When an interrupt event occurs the related ISR Peripheral_X_IRQHandler is accessed After clearing the proper interrupt flag and optionally executing user defined code lines the Exec IRQ Handler function is called if it is required to execute an MC IRQ Handl
31. ents Iqdref are computed internally by the FOC_CalcCurrRef method at the rate specified by medium frequency MF clock which is 500Hz by default This internal computation is performed in two steps 1 The reference torque Teref is computed by the STC class method STC_CalcTorqueReference running speed PI regulator when in speed mode for example 2 From Teref loret and laret are computed by the FOC drive derived class method CalcCurrRef which implements MTPA and or flux weakening if they are available Doc ID 18459 Rev 4 31 42 Class interaction UM1053 7 2 32 42 Field orientation is executed at the rate specified by the High Frequency HF clock equal to PWM frequency by default using the FOC_CurrRegulator method This method interacts with different objects oPIq oPId OPWMC oSPD and computes the phase voltages to be applied to the motor with the purpose of achieving and ly regulation As a result of the computation the object members Vqd Va lo lab Iqd hEIAngle are also updated Procedure for motor ramp up for sensorless algorithms Figure 6 Motor ramp up procedure RUC_Init MF clock HF clock 5 RUGE SPD_CalcElAngle ee 8 o 3 NG VSPD SetMecAcceleration 0VSS tS STC_ExecRamp 0STC SPD_CalcAvrgMecSpeed01Hz k FOC_CurrRegulator 3 STC SetControlMode sa F FOC_SetSpeedSensor SPD_GetEIAngle oSPD KG MF clock e CATO R E FOC_SetCurrRef NG i Other class metho
32. er In order to identify the MC IRQ Handler to be executed the MC_IRQTable position that corresponds to the proper object is passed as a function parameter so stm32fxxx_MC_it c does not require object interface knowledge Furthermore as an MC IRQ Handler can be generally accessed from more than one interrupt a flag that identifies the triggering event is also passed else if Peri pheral1 Flag2 Clear Flag Peripheral 1 Flag1 E Exec IRQ HandlerfPosition1 Flag2 return Object MS19384 1 Once the object owner of the MC IRQ Handler to be executed has been identified by accessing the MC IRQ Table in the position passed to Exec_IRQ_Handler this function can finally jump to the MC IRQ Handler itself The entire process considering the program flow from the Peripheral X IR Handler to the MC IRQ Handler only requires two jumps to Exec IRQ Handler and then to the MC IRQ Handler In this way the overhead introduced by the SW architecture is minimized This is achieved by making the addresses of both the object and its related MC IRQ Handler which is located in the first element of the class structure as already shown in ExamplePrivate h template the same Doc ID 18459 Rev 4 ky UM1053 How to create a user defined class 5 Note How to create a user defined class Users can create their own classes and add them to the motor control library To do this use the te
33. erived class members container pDParams_t pDParams_str lt Derived class parameters container 7 _DCDRV_EXMP_t _DCDRV_EXMP Derived_ExampleClass c Located in MC library src available only for confidential distribution of STM32 FOC PMSM SDK v3 3 this is the source file that contains the implementation of both derived class specific methods and base class virtual methods It includes both base and derived classes interface and private definitions If the derived class requires the execution of program lines to be triggered by an interrupt the MC RQHandlerPrivate h file is also included refer to Section 4 4 Motor control library related interrupt handling for further information about interrupt handling The DRV_NewObject method merits mentioning This method creates objects of the Derived_Example class CDRV_EXMP on demand and requires the pointers to both parameters structure of base and derived classes as input The creation of a derived class object encloses the creation of the related base class object The two objects are then merged by initializing the base class pointer to the derived class object _oExample gt DerivedClass with the address of the newly created derived class object _oDerived The base class pointers to the virtual methods and if any to the MC IRQ Handler are also initialized with pointers to derived class private functions The address of the base class portion of the derived
34. gs and implemented on an STM32F103x CR3LM1 PWMC MCU where x 4 6 8 B performance line low and medium density devices It only supports a single motor drive Current sensing carried out via three shunt resistors placed below low side switches on the three inverter legs and implemented on an STM32F103x MCU where x C D E performance line high density devices Although it is designed to support dual motor drive it can also be used when a single motor drive has been instanced R3_HD2 CR3HD2 PWMC Current sensing carried out through isolated current sensors and ICS LM1 implemented on an STM32F103x MCU where x 4 6 8 B performance CILM1_PWMC line low and medium density devices It only supports a single motor drive Doc ID 18459 Rev 4 ky UM1053 STM32 PMSM FOC FW library v3 3 class list Table 2 Derived classes continued Class ICS_HD2 CIHD2 PWMC Definition Current sensing carried out through isolated current sensors and implemented on an STM32F 103x MCU where x C D E performance line high density devices Although it has been specifically designed to support dual motor drive it can also be used when a single motor drive has been instanced R1 F2XX CR1F2XX PWMC Current sensing carried out via a single shunt resistor placed on the DC bus link and implemented on an STM32F2xx MCU Although it is designed to support dual motor drive it can also be used when
35. implemented by derived class param this related object of class CEXMP retval none void EXMP VFunc CEXMP this It is worth noticing that CEXMP class type is a pointer to a void structure whose type is CEXMP _t This prevents the user of the class from accessing object members and hidden data ExamplePrivate h Located in MC library inc available only for confidential distribution of STM32 FOC PMSM SDK v3 3 this is a class private header file that contains private definitions required by the class implementation It contains definitions of object data structure type object variable elements of this structure virtual methods container structure only for classes with derived see next paragraph parameters class private re definition and the private class definition KEKE KKK KK KKK KKK KKK KE KKK KKK KKK KKK KEKE KKK KKK KE KK KKK KEK KKK KKK KKK KKK KEKKKEEKEK file ExamplePrivate h author IMS Systems Lab and Technical Marketing MC Team version V0 0 1 x brief This file contains private definition of Example class kkxkxkxkxkxkxkkkkkkkkkkkkkkkkkkkkkkkkkkkkxkkkkxkkkkkkkkkkkkkkkkkkkkkkkkkkkxk a brief Example class members definition 7 typedef struct unsigned int base_vars lt Example of member Vars_t pVars_t Doc ID 18459 Rev 4 13 42 STM32 PMSM FOC FW library C implementation of OOP UM1053 14 42 x brief Redefinition of par
36. ist 24 6 1 Current reading and PWM generation CPWMC and its derived classes 24 6 2 Speed and position feedback CSPD and its derived classes 25 6 3 Field oriented control drive CFOC and its derived classes 26 6 4 Bus voltage sensor CVBS and its derived classes 27 6 5 Temperature sensor CTSNS and its derived classes 27 6 6 Digital Output CDOUT class 4 744 wa namna hahaa web iwe ANA 28 6 7 Encoder Alignment Controller CEAC class 28 6 8 Rev up controller CRUC class eee eee 28 6 9 Speed and torque controller CSTC class 29 6 10 State machine STM class 0 c eee eee 29 6 11 PI CPI and PID CPID controller classes 30 2 42 Doc ID 18459 Rev 4 ky UM1053 Contents 7 Class interaction i access AA ae ni ie ean al AA 31 7 1 Field orientation speed and torque control procedures 31 7 2 Procedure for motor ramp up for sensorless algorithms 32 7 3 Rotor alignment for encoder calibration 0 0 0c eee eee 33 8 Description of tasks ccc eee 35 8 1 Low frequency task 0 eee ee 35 8 2 Medium frequency task 002 c eee ee 36 8 3 High frequency task 4 a mGA KUKRE de 54a a GG et eee es 36 8 4 Sale lash AA AA 38 9 Bibliography Ka KARNE NN NAKA NADER AKEN Ka GA AGA 40 10 Revision history asana Ga EBA KANAN A
37. ived classes are differentiated according to the type of physical sensor if any Table 5 Bus voltage sensor CVBS and its derived classes Class Description Derived class which can handle all types of real voltage sensor with Rdivider CAVES VBS analog output For example hardware resistive voltage partitioning Derived class which emulates a voltage sensor when no real sensors are Mittal CyVeS YES available It always returns a constant programmable voltage 6 5 Temperature sensor CTSNS and its derived classes This class implements either a virtual or real temperature sensor depending on the sensor availability Any object of this class must be linked to a derived class object If any the access to MCU peripherals is delegated to the derived classes so that the base class implementation is kept hardware independent Derived classes are differentiated according to the type of physical sensor if any ky Doc ID 18459 Rev 4 27 42 STM32 PMSM FOC FW library v3 3 class list UM1053 6 6 6 7 6 8 28 42 Table 6 Bus voltage sensor CVBS and its derived classes Class Description Derived class which can handle NTC sensor or more in general analog temperature sensors whose output is related to the temperature by the NTC CNTC_TSNS following for Vout Vo aT T To Derived class which emulates a temperature sensor when no real sensors Virtual CVTS_TSNS are actually available
38. lready included in the software package you received or available on the ST web site www st com Doc ID 18459 Rev 4 7 42 Documentation architecture UM1053 1 2 Related documents Available from www arm com Cortex MO Technical Reference Manual available from http infocenter arm com help topic com arm doc ddi0432c DDI0432C_cortex_m0_r0p 0 trm pdf Cortex M3 Technical Reference Manual available from http infocenter arm com help topic com arm doc ddi0337e DDI0337E_cortex_m3_r1p 1 trm pdf Cortex M4 Technical Reference Manual available from htitp infocenter arm com help topic com arm doc ddi0439c DDI0439C cortex m4 r0p 1 trm pdf Available from www st com or your STMicroelectronics sales office STM32F050x and STM32F051x datasheets STM32F 100xx datasheet STM32F103xx datasheet STM32F20x and STM32F21x datasheets STM32F40x and STM32F41x datasheets STM32F050x and STM32F051x user manual RM0091 STM32F100xx user manual RM0041 STM32F103xx user manual RM0008 STM32F20x and STM32F21x user manual RM0033 STM32F40x and STM32F41x user manual RM0090 STM32F103xx AC induction motor IFOC software library V2 0 UM0483 STM32 and STM8 Flash Loader demonstrator UM0462 8 42 Doc ID 18459 Rev 4 ky UM1053 Object oriented programming OOP 2 Object oriented programming OOP Object Oriented Programming OOP is a programming paradigm whose roots can be traced to the 1960s When the software
39. ly need to know the object interface so you can focus on specific software developments Doc ID 18459 Rev 4 11 42 STM32 PMSM FOC FW library C implementation of OOP UM1053 4 4 1 12 42 STM32 PMSM FOC FW library C implementation of OOP As a result of its desirable characteristics code portability and efficiency ability to access specific hardware addresses low runtime demand on system resources for example the C language is widely used in embedded system applications On the other hand the C language unlike more complex languages such as C and Java does not support object oriented programming For this reason a dedicated implementation of OOP has been developed in C for the STM32 PMSM FOC FW library v3 3 Generic classes source files organization and content Depending on the proposed implementation an Example class is generally composed of three source files ExampleClass h Located in the MC library interface folder this is the public header file that contains the interface of the Example class As mentioned previously the interface of a class exports the definitions of the methods applicable to the objects of that class In general in the STM32 PMSM FOC FW library implementation this file contains everything necessary to work with that class For this purpose this file contains the public definition of the class type CEXMP and the type structure containing the constant parameters required for the object c
40. mplates described in Section 4 1 for base classes and Section 4 3 for derived classes If the newly created class requires the execution of an MC IRQ Handler on an interrupt occurrence the MAX_MC_IRQ_NUM definition in MCIRQHandlerClass c must be incremented and the corresponding MC IRQ table position defined by adding the following line in MCIRQHandlerClass h for example define MC IRQ USER IRQ 4u The first four table positions are reserved for PWMnCurrFdbk first and second instances and SpeednPosFabk first and second instance objects In case of STM32 FOC PMSM SDK v3 3 web distribution the maximum number of elements for the MC IRQ table is limited to 8 elements O to 3 are already reserved and not available for the user elements 4 to 7 are left for the user Add the Exec IRQ Hanaler MC IRQ USER IRQ flag function call in stm32fxxx MC it c in the proper peripheral IRQ handler The flag is the identifier for the interrupt trigger event Doc ID 18459 Rev 4 23 42 STM32 PMSM FOC FW library v3 3 class list UM1053 6 Note 6 1 24 42 STM32 PMSM FOC FW library v3 3 class list This section provides a general view and a short description of the classes used in the MC library For a detailed description of the methods and parameters of each class see STM32 FOC PMSM FW library v3_3 developer Help file chm Source files of the MC library classes are only provided free of charge within STM32 FOC PMSM SDK v3 3 confidenti
41. nc CEXMP this _CEXMP this gt Vars_str base_vars Ou SER brief Example of virtual method of the class Example implemented by derived class param this related object of class CEXMP retval none x void EXMP VFunc CEXMP this f CEXMP this gt Methods_str pVFunc this Inheritance implementation As discussed previously inheritance is one of the fundamental features of object oriented programming This section describes how it has been achieved in the STM32 PMSM FOC SDK v3 3 Figure 1 summarizes the private content of a generic class in the proposed implementation Figure 1 Generic class structure Class structure Virtual methods structure Variables structure Parameters structure Pointer to derived class object M519382V1 Not used in classes with no derived class objects virtual methods structure and pointers to derived classes are keys to understanding inheritance accomplishment Virtual methods structure contains a list of pointers to those functions that once properly initialized in the derived class object creation process link virtual methods exported by base class interface together with their private implementation contained in each of the derived classes Doc ID 18459 Rev 4 ky UM1053 STM32 PMSM FOC FW library C implementation of OOP The pointer to a derived class object allows composing a derived class object by merging both its base and derived cl
42. ns the private definition of an object data structure type object variables are elements of this structure parameter class private redefinition and the private class definition Unlike the related base class private definition header file a derived class structure type does not contain pointers to both further derived classes and virtual method containers This limits the levels of inheritance to one KEK KKK KKK KK KKK KKK KKK KKK KEK KKK KK KEK KKK KK KE KK KKK KEKE KK KKK KEKE KK KKK KKEKKEEK file Derived_ExamplePrivate h author IMS Systems Lab and Technical Marketing MC Team version V0 0 1 brief This file contains private definition of Derived class KEKE KKK KKK KKK KKK KKK KKK KKK KE KK KKK KEKE KKK KKK KEK KKK KK KEK KR k k KKK KEKE KKK KKK KEKEKE td Define to prevent recursive inclusion ifndef _ DERIVED EXAMPLEPRIVATE H define _ DERIVED EXAMPLEPRIVATE H brief Derived class members definition a Doc ID 18459 Rev 4 UM1053 STM32 PMSM FOC FW library C implementation of OOP x typedef struct f unsigned int derived_Vars lt Example of member DVars_t pDVars_t x brief Redefinition of parameter structure typedef DerivedParams_t DParams_t pDParams_t brief Private Derived class definition xJ typedef struct DVars_t DVars_str lt D
43. o RUN state signmen cang izations for Goin ANY STOP state i No Generate No Generate error SW error High frequency task For a given motor and depending on the present state of the related state machine the high frequency task executes the motor control duties that require a high frequency rate and precise timing such as FOC current control loop The high frequency task execution is triggered by the ADC JEOC interrupt which sanctions the end of the related motor phase currents reading Because this trigger is only available in the START START_RUN IDLE_ALIGNMENT and ALIGNMENT states the high frequency task is only executed in these states and it is not triggered in the resting cases Doc ID 18459 Rev 4 1577 UM1053 Description of tasks When being executed the high frequency execution rate is strongly related to the PWM frequency This execution rate can be computed as the corresponding drive PWM frequency divided by the REGULATION_EXECUTION_RATE parameter in Drive parameters h for motor 1 or the REGULATION_EXECUTION_RATE2 parameter n Drive parameters motor 2 h for motor 2 In case of a dual motor control a FIFO mechanism has been put in place in order to execute the FOCs of both the motors in the right sequence The FOC execution related to a given motor is booked inside the TIMxUpdate ISR leading the A D conversions for that motor currents reading by approximately half the PWM period
44. ogramming 3 John C Mitchell Concepts in programming languages Cambridge University Press 2003 SBN 0 521 78098 5 p 278 4 Michael Lee Scott Programming language pragmatics Edition 2 Morgan Kaufmann 2006 ISBN 0 12 633951 1 p 470 5 Abadi Martin Cardelli Luca 1996 A Theory of Objects Springer Verlag New York Inc ISBN 0387947752 Retrieved 2010 04 21 Doc ID 18459 Rev 4 ky UM1053 Revision history 10 sa Revision history Table 8 Document revision history Date Revision Changes 08 Apr 2011 1 Initial release 24 May 2011 2 Added references for web and confidential distributions of STM32 FOC PMSM SDK v3 0 28 Mar 2012 The product range has been expanded from STM32F103xx or STM32F100xx microcontrollers to STM32F100x 103x 2x 40x 41x microcontrollers 14 Nov 2012 Added STM32F05xx to the product range which has impacted the title the Introduction Table 2 Derived classes and Table 3 Speed and position feedback CSPD and its derived classes Replaced STM32F40xx and STM32F41xx by STM32F 4xx in the title Changed the software library version from v3 2 to v3 3 Added Table 1 Applicable products Doc ID 18459 Rev 4 41 42 UM1053 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics NV and its subsidiaries ST reserve the right
45. ponent Doc ID 18459 Rev 4 ky UM1053 Class interaction references lyaret Provided by OSTC is fed to oFOC which is set in EXTERNAL mode so that it can accept such references 7 3 Rotor alignment for encoder calibration Figure 7 Rotor alignment for encoder calibration RUC_Init EAC_Exec IfRemaining Step 0 SPD_SetMecAngle oENC SPD CalcElAngle EAC Start Alignment VSPD set 0V55 0 SPD CalcAyrgMecSpeed01Hz STC_ExecRamp oSTC FOC_CurrRegulator STC_SetControlMode FOC_SetSpeedSensor SPD_GetElAngle oSPD MF clock STC_CalcTorqueReference FOC_SetCurrRef O Other classmethod MS19387V1 The quadrature encoder is a relative position sensor Because absolute information is required for performing a field oriented control it is necessary to establish a 0 position This task is performed by means of an encoder calibration phase which is carried out by default on user demand This phase imposes a null reference flux Id and a torque reference flux Iq with a linearly increasing magnitude and a constant orientation When 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 To perform this task see Figure 7 the Encoder Alignment Controller OEAC configures a virtual speed sensor object in order to provide a constant programmable angle throughout the alignment duration A mechanical ac
46. reation ExampleParams_t In addition and only if necessary definitions of certain types required for using methods are stored in this file RRRKKRKKKKKKEKKKKKKKKERKEKKEK KK RK KERR ef TR re Re Re RK KKK KKK KERR kkk RK KER K KKK KK file ExampleClass h author IMS Systems Lab and Technical Marketing MC Team version V0 0 1 brief This file contains interface of Example class KEK KKK KKK KKK KKK KK KKK KEK KKK KKK KK KKK KEKE KK KEK KK KEK KKK KKK KK KKK KEKE KKK KK KKEKKEEK s Includes include MC_type h brief Public Example class definition typedef struct CEXMP t CEXMP brief Example class parameters definition ol typedef const struct f unsigned int paramA lt Example of parameter JExampleParams t pExampleParams_t Doc ID 18459 Rev 4 ky UM1053 STM32 PMSM FOC FW library C implementation of OOP 4 brief Creates an object of the class Example param pExampleParams pointer to an Example parameters structure retval CEXMP new instance of Example object n9 CEXMP EXMP NewObject pExampleParams t pExampleParams x brief Example of public method of the class Example param this related object of class CEXMP retval none void EXMP_Func CEXMP this brief Example of virtual method of the class Example
47. rly Each phase is characterized by its parameters structure type RUCPhasesParams_t e duration hDurationms e final motor speed hFinalMecSpeed01Hz e final current amplitude hFinalTorque pointer to the next rev up phase parameters structure The Initial angle for the first phase can also be specified See also Section 6 2 for more information about ramp up Doc ID 18459 Rev 4 ky UM1053 STM32 PMSM FOC FW library v3 3 class list 6 9 6 10 sa Speed and torque controller CSTC class The speed and toque controller provides a FOC object with a target electrical torque depending on the control mode speed or torque control and executes target speed and torque ramps When in speed mode the speed and toque controller computes the new target speed reference if a ramp is being executed and then performs the speed regulation loop The return is an electrical torque which is then used by the FOC object to get Iqrer and laret When the speed and toque controller is in torque mode it computes the new target electrical torque if a ramp is being executed and then returns a target electrical torque State machine STM class The state machine class handles transitions between the states of the drive that influence the actions that need to be taken by motor control tasks The following list of available states and a summarizing block diagram are provided for convenience Table
48. started to become more complex researchers studied ways to organize it in units in order to achieve a high level of modularity and code reusability As a result a new way of programming was conceived which is able to decompose programs into self sufficient modules classes each instance object of which containing all the information needed to manipulate its own internal data representing the object state For more information on OOP refer to the abundant literature on the subject and to Section 9 Bibliography A description of OOP fundamental concepts and features is provided here Object An object is a bundle of data structure members and functions methods allowed to operate on the data structure itself The data structure contains both object properties and variables and can also be referenced as the state of the object Class A class can be considered as the factory from which individual objects are created It is the user defined data type that contains variables properties and methods Method A method is an operation that can access the internal state of an object by reading and or writing its variables and properties It is important to point out that only an object method can modify its variables the object internal variables are hidden to object users who can interact with them only through the object methods This fundamental principle of OOP is known as data encapsulation or data hiding Inheritance Inherit
49. tive terms 30 42 Doc ID 18459 Rev 4 ky UM1053 Class interaction 7 Class interaction This section facilitates the understanding of the interactions between classes by describing how objects relate to achieve field orientation speed and torque regulation motor ramp up and alignment 7 1 Field orientation speed and torque control procedures Figure 5 Field orientation speed and torque regulation FOC GetSpdSensorReliability FOC_SetSpeedSensor FOC_Init FOC_CurrRegulator SPD_GetElAngle oSPD PWMC_GetPhaseCurrent oPWMC FOC_CalcCurrRef Pl_contraller oPiq STC_CalcTorqueReference oTSC nA Pl controllerjoPld FOC Derived Class FOC DerivedClass CalcCurrRef VadConditioning 0FOC PWMC_SetPhaseVoltage oPWMC FOC Derived Class DataPostProcess oFOC FOC_SetCurrRef FOC SetDrive Input Boa FOC Getxxx Other classes method MS19386 1 Figure 5 shows how the FOC drive class interacts with other classes in order to achieve both the speed and torque regulation and the field orientation When the FOC drive object oFOC is initialized the set of objects necessary to accomplish its duties are passed and stored in oFOC When the drive input is set to external bDrivelnput EXTERNAL stator current references can be provided from the outside via the FOC_SetCurrRef method When the drive input is set to internal bDrivelnput INTERNAL the stator current reference compon
50. 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 party products or services it shall not be deemed a license grant by ST for the use of such third party products or services or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION OR INFRINGEMENT OF ANY PATENT COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT UNLESS EXPRESSLY APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES ST PRODUCTS ARE
Download Pdf Manuals
Related Search
Related Contents
縦型ポスト - TOEX Previews of FLAAR Report Series on Evaluations of Printers Istruzioni per l`uso Manuel de l`utilisateur Tobii PCEye Manual do usuário User manual Washing Machine ZWG 680P ZWG 6100P Copyright © All rights reserved.
Failed to retrieve file