7STM32 FOC STM32 FOC 32 STM32 PMSM FOC SDK V32 讲座 STM32 PMSM FOC SDK V32_讲座3_第1页
7STM32 FOC STM32 FOC 32 STM32 PMSM FOC SDK V32 讲座 STM32 PMSM FOC SDK V32_讲座3_第2页
7STM32 FOC STM32 FOC 32 STM32 PMSM FOC SDK V32 讲座 STM32 PMSM FOC SDK V32_讲座3_第3页
7STM32 FOC STM32 FOC 32 STM32 PMSM FOC SDK V32 讲座 STM32 PMSM FOC SDK V32_讲座3_第4页
7STM32 FOC STM32 FOC 32 STM32 PMSM FOC SDK V32 讲座 STM32 PMSM FOC SDK V32_讲座3_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Our implementation of OOP It s a C implementation not really object programming Each class is constituted by three source file An interface header file containing only what it necessary to the user to work with that class A private header file containing private definitions e g object variables object data structure type A private c file containing the real implementation of the methods 34 12 06 2014STM32 PMSM FOC SDK v3 2 PUBLIC interface YClass h Z XClass h Y XClass h XClass h HIDDEN implementation XPrivate h XClass c Z XPrivate h Z XClass c Y XPrivate h Y XClass c YPrivate h YClass c XClass obj Z XClass obj Y XClass obj YClass obj Base class objects is a pointer pointing to base classs structure Our implementation of objects relations35 12 06 2014STM32 PMSM FOC SDK v3 2 Base class structure Virtual methods Variables Parameters Pointer to derived class Derived class objects is a pointer always pointing to its base classs structure Base class structure Virtual methods Variables Parameters Pointer to derived class Derived class structure Specific parameters Specific Variables Specific Parameters Private function not in the structure Without derived class With derived class Classes interfaces documentation As the classes interface is the only file may be known by the user it has been documented using doxygen format chm help files are then generated for each class for user convenience as done for the Std peripheral library 36 12 06 2014STM32 PMSM FOC SDK v3 2 Base classes interface BCLASSNAMEClass h The interface header file containing only what it necessary to the user to work with that class 37 12 06 2014STM32 PMSM FOC SDK v3 2 typedef struct CPWMC t CPWMC typedef const struct uint16 t hPWMperiod It contains the PWM period expressed in timer clock cycles unit hPWMPeriod Timer Fclk Fpwm PWMnCurrFdbkParams t pPWMnCurrFdbkParams t void PWMC Init CPWMC this void pDrive uint16 t PWMC CheckOverCurrent CPWMC this void PWMC ADC SetSamplingTime CPWMC this ADConv t ADConv struct Public class definition just a void container to allow data hiding Parameters structure type a structure containing the set of all those constant values necessary and sufficient to characterize an object of that class Class methods the operations on the object internal state are only allowed through these functions Base classes private definitions BCLASSNAMEPrivate h The private header file include BCLASSNAMEClass h and contains private type definitions 38 12 06 2014STM32 PMSM FOC SDK v3 2 define SECTOR 10u typedef struct uint16 t hT Sqrt3 Contains a constant utilized by SVPWM algorithm uint16 t hSector Contains the space vector sector number Vars t pVars t typedef PWMnCurrFdbkParams t Params t pParams t typedef struct void pIRQ Handler void this unsigned char flag uint16 t pPWMC IsOverCurrentOccurred CPWMC this Methods t pMethods t typedef struct Methods t Methods str Virtual methods container Vars t Vars str Class members container pParams t pParams str Class parameters container void DerivedClass Methods str pPWMC GetPhaseCurrents this pStator Currents Inclusion for dynamic memory allocation objected located in heap and created on demand not MISRA compliant Inclusion for static memory allocation fixed number of objects located in static RAM Private constant definition Virtual methods implementation call derived class method Real methods implementation Derived classes interface DCLASSNAME BCLASSNAMEClass h The interface header file containing only what it necessary to the user to work with that class It includes 40 12 06 2014STM32 PMSM FOC SDK v3 2 typedef struct CR1LM1 PWMC t CR1LM1 PWMC typedef const struct uint32 t wADC Clock Divider APB2 clock prescaling factor for ADC peripheral It must be RCC PCLK2 DivX x 2 4 6 8 uint8 t IRQnb MC IRQ number used for TIM1 Update event and for DMA TC event uint16 t hBKINPin R1 LM1Params t pR1 LM1Params t CR1LM1 PWMC R1LM1 NewObject pPWMnCurrFdbkParams t pPWMnCurrFdbkParams pR1 LM1Params t pR1 LM1Params static void R1LM1 StartTimers void Public class definition just a void container Derived class parameters type a structure containing a set of constant values that together with base class parameters are necessary and sufficient to characterize an object of this class Specific derived class methods Derived classes private definitions DCLASSNAME BCLASSNAMEPrivate h The private header file include BCLASSNAMEClass h and contains private type definitions 41 12 06 2014STM32 PMSM FOC SDK v3 2 typedef struct uint16 t hPhaseOffset Offset of current sensing network uint16 t hDmaBuff 2 uint16 t hRegConv DVars t pDVars t typedef R1 LM1Params t DParams t pDParams t typedef struct DVars t DVars str pDParams t pDParams str DCR1LM1 PWMC t DCR1LM1 PWMC Specific derived class variables structure definition Private redefinition of derived class parameter structure Private derived class definition no pointer to further derived classes Derived classes private implementation DCLASS NAME BCLASSNAME c The private derived class implementation file include both base and derived class interface and private header file can then access to both derived and base classes variables and parameters and actually implements real and virtual methods 42 12 06 2014STM32 PMSM FOC SDK v3 2 define ADC1 DR Address 0 x4001244Cu ifdef MC CLASS DYNAMIC include stdlib h Used for dynamic allocation else DCR1LM1 PWMC t R1LM1 PWMCpool MAX R1LM1 PWMC NUM unsigned char R1LM1 PWMC Allocated 0u endif static uint16 t R1LM1 CalcDutyCycles CPWMC this static void R1LM1 GetPhaseCurrents CPWMC this Curr Components pStator Currents CR1LM1 PWMC R1LM1 NewObject pPWMnCurrFdbkParams t pPWMnCurrFdbkParams pR1 LM1Params t pR1 LM1Params static void R1LM1 GetPhaseCurrents CPWMC this Curr Components pStator Currents Private constants definitions Inclusion for dynamic and static memory allocation Private declaration of functions implementing virtual methods Derived class specific methods mplementation Function implementing base class virtual methods New Object implementation base class 43 12 06 2014STM32 PMSM FOC SDK v3 2 define MAX PWMC NUM 1u ifdef MC CLASS DYNAMIC include stdlib h Used for dynamic allocation else CPWMC t PWMCpool MAX PWMC NUM unsigned char PWMC Allocated 0u endif CPWMC PWMC NewObject pPWMnCurrFdbkParams t pPWMnCurrFdbkParams CPWMC oPWMC ifdef MC CLASS DYNAMIC oPWMC CPWMC calloc 1u sizeof CPWMC t else if PWMC Allocated pParams str pParams t pPWMnCurrFdbkParams return CPWMC oPWMC New Object implementation derived class 44 12 06 2014STM32 PMSM FOC SDK v3 2 ifdef MC CLASS DYNAMIC include stdlib h Used for dynamic allocation else DCR1LM1 PWMC t R1LM1 PWMCpool MAX R1LM1 PWMC NUM unsigned char R1LM1 PWMC Allocated 0u endif CR1LM1 PWMC R1LM1 NewObject pPWMnCurrFdbkParams t pPWMnCurrFdbkParams pR1 LM1Params t pR1 LM1Params CPWMC oPWMnCurrFdbk DCR1LM1 PWMC oR1 LM1 oPWMnCurrFdbk CPWMC PWMC NewObject pPWMnCurrFdbkParams ifdef MC CLASS DYNAMIC oR1 LM1 DCR1LM1 PWMC calloc 1u sizeof DCR1LM1 PWMC t else if R1LM1 PWMC Allocated pDParams str pR1 LM1Params oPWMnCurrFdbk DerivedClass void oR1 LM1 oPWMnCurrFdbk Methods str pIRQ Handler Set IRQ Handler pR1 LM1Params IRQnb CMCIRQ oPWMnCurrFdbk oPWMnCurrFdbk Methods str pPWMC Init Base class new object creation Derived class new object creation Derived and base classes objects linking Virtual methods linking Interrupt handling 1 2 Some derived classes e g R1 LM1 class ENC need to execute some code on Interrupt Service Routines ISR The ISR itself can t be moved into objects implementation to allow user adding his own code on the same interrupt A special class MCIRQHandler is created to this purpose This class contains an MC interrupt data table which is filled through Set IRQ Handler method with a set of objects As already seen the pointer to the base class object structure coincides with the address of the MC virtual ISR 45 12 06 2014STM32 PMSM FOC SDK v3 2 Interrupt handling 2 2 46 12 06 2014STM32 PMSM FOC SDK v3 2 void TIM1 UP IRQHandler void Exec IRQ Handler MC IRQ PWMNCURRFDBK 1 0 void Exec IRQ Handler unsigned char bIRQAddr unsigned char flag oMC IRQTable bIRQAddr pIRQ Handler void oMC IRQTable bIRQAddr flag static void R1HD2 IRQHandler void this unsigned char flag define MC IRQ PWMNCURRFDBK 1 0u define MC IRQ PWMNCURRFDBK 2 1u define MC IRQ SPEEDNPOSFDBK 1 2u define MC IRQ SPEEDNPOSFDBK 2 3u CMCIRQ MC IRQTable MAX MC IRQ NUM oR1CurrentSensor oSpeedSensor Derived class objects is a pointer always pointing to its base classs structure object address coincide with ISR pointer address Base class structure Virtual methods Variables Parameters Pointer to derived classDerived class structure Specific parameters Specific Variables Specific Parameters Private function not in the structure MC Library Information flow 47 12 06 2014STM32 PMSM FOC SDK v3 2 EncAlignCtrlClass CEAC SpeednTorqCtrlClass CSTC PIRegulatorClass CPI Speed FOCDriveClass CFOC StateMachineClass CSTM PIRegulatorClass CPI Id PIRegulatorClass CPI Iq DigitalOutputClass CDOUT PWMnCurrFdbkClass CPWMC SpeednPosFdbkClass CSPD Real sensor observer BusVoltageSensorClass CVBS TemperatureSensorClass CTSNS SpeednPosFdbkClass CSPD Virtual sensor RevupCtrlClass CRUC Acceleration Position Torque Reference Torque Reference Torque Reference Rotor angle Rotor angle PWM output Digital output Analog input Digital input Speed and position feedback class 48 12 06 2014STM32 PMSM FOC SDK v3 2 SpeednPosFdbk SPD Init SPD Clear XXX NewObject INIT SPD SetMecAngle SET SPD GetElAngle SPD GetMecAngle SPD GetAvrgMecSpeed01Hz SPD GetElSpeedDpp SPD Check SPD GetS16Speed GET SPD CalcAngle SPD CalcAvrgMecSpeed01Hz CALC HF Input Vars MF S16degree S16degree 01HZ Dpp S16Speed Bool oSpeedSensor XXX Depend on the derived class Current reading and PWM generation class49 12 06 2014STM32 PMSM FOC SDK v3 2 PWMnCurrFdbk PWMC Init XXX NewObject INIT PWMC SetPhaseVoltage PWMC SwitchOnPWM PWMC SwitchOffPWM PWMC TurnOnLowSides PWMC CurrentReadingCalibr PWMC ADC SetSamplingTime SET PWMC GetPhaseCurrents PWMC CheckOverCurrent PWMC ExecRegularConv GET Stator current MC BREAK IN Converted val oCurrSensor Sampling time Valfa beta XXX Depend on the derived class Field oriented control drive class 50 12 06 2014STM32 PMSM FOC SDK v3 2 FOCDrive FOC Init FOC Clear XXX NewObject INIT FOC SetSpeedSensor FOC SetDriveInput FOC SetIqdref FOC SetIdref SET FOC GetIab FOC GetIalphabeta FOC GetIqd FOC GetIqdref FOC GetVqd FOC GetValphabeta FOC GetAvrgMecSpeed01Hz FOC GetMecSpeedRef01Hz FOC GetSpdSensorReliability FOC GetElAngledpp FOC GetTeref FOC GetPhaseCurrentAmplitude FOC GetPhaseVoltageAmplitude FOC GetInstanceNumber GET FOC CurrController FOC CalcCurrRef CALC HF MF Curr cmp Curr cmp Curr cmp Curr cmp Curr cmp Curr cmp 01HZ Bool Dpp S16A Teref 01HZ S16V int oFOC oCurrSensor oSpeedSensor Internal External Iqdref Iqref XXX Depend on the derived class Bus voltage sensor class 51 12 06 2014STM32 PMSM FOC SDK v3 2 BusVoltageSensor VBS Init VBS Clear XXX NewObject INIT SET VBS GetBusVoltage d VBS GetAvBusVoltage d VBS GetAvBusVoltage V VBS CheckVbus GET VBS CalcAvVbus CALC SF u16Volt u16Volt Volt Error oBusSensor Error flag XXX Depend on the derived class RVBS VVBS Temperature sensor class 52 12 06 2014STM32 PMSM FOC SDK v3 2 TemperatureSensor TSNS Init TSNS Clear XXX NewObject INIT SET TSNS GetAvTemp d TSNS GetAvTemp C TSNS CheckTemp GET TSNS CalcAvTemp CALC SF u16Celsius Celsius Error oTemperatureSensor Error flag XXX Depend on the derived class NTC VTS Proportional integral regulator class 53 12 06 2014STM32 PMSM FOC SDK v3 2 PI regulator PI NewObject PI ObjectInit INIT PI SetKP PI SetKI PI SetIntegralTerm PI SetLowerIntegralTermLimit PI SetUpperIntegralTermLimit SET PI GetKP PI GetKI PI GetKPDivisor PI GetKIDivisor GET PI Controller CALC MF HF Kp Gain Kp Gain Kp Divisor PI params S16 Kp GAIN Ki Gain Integral term Lower limit Upper limit Ki Divisor Speed and torque controller class 54 12 06 2014STM32 PMSM FOC SDK v3 2 SpeednTorqCtrl STC NewObject STC Init STC Clear INIT STC SetControlMode STC ExecRamp STC StopRamp SET STC GetMecSpeedRef01Hz STC GetTorqueRef STC GetControlMode STC GetMecSpeedRef01HzDefault STC GetMaxAppPositiveMecSpeed01Hz STC GetMinAppNegativeMecSpeed01Hz GET STC CalcTorqueReference CALC MF 01HZ Iqref Torque Speed STC params Iqref Torque Speed Final speed Duration 01HZ oPI oSPD oPIDSpeed 01HZ 01HZ Encoder alignment controller class 55 12 06 2014STM32 PMSM FOC SDK v3 2 EncAlignCtrl EAC NewObject EAC Init INIT EAC StartAlignment SET GET EAC Exec CALC MF EAC params Completed Ostc oVSS oENC Rev up controller class 56 12 06 2014STM32 PMSM FOC SDK v3 2 RevupCtrl RUC NewObject RUC Init RUC Clear INIT RUC SetPhaseDurationms RUC SetPhaseFinalMecSpeed01Hz RUC SetPhaseFinalTorque SET RUC GetPhaseDurationms RUC GetPhaseFinalMecSpeed01Hz RUC GetPhaseFina

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论