基于MCSDK 6.x 的自定義控制板實(shí)現(xiàn)
前言
本文介紹了如何在ST的MCSDK 6.x中,通過撰寫配置文件,以實(shí)現(xiàn)自定義的控制套件。
關(guān)鍵詞:FOC,MCSDK,STM32,STMC Board Manager
準(zhǔn)備
在啟動(dòng)MCSDK后,需要選擇電機(jī),控制器和驅(qū)動(dòng)器。對于Modular,需要分別配置Power Board和Control Board,Inverter只需要配置單個(gè)文件即可。
在主頁面 點(diǎn)擊Tools -> Boards Manager,即可對配置文件進(jìn)行編輯。如圖1所示,可以查看、復(fù)制現(xiàn)有的配置文件,或者創(chuàng)建新配置文件。
創(chuàng)建配置文件
點(diǎn)擊Inverter,點(diǎn)擊右下角的+,創(chuàng)建新的文件。
基礎(chǔ)配置
按照提示,隨便填些參數(shù)
{
"type": "inverter",
"descVersion": 4,
"contentVersion": "1.0",
"name": "my_self_control",
"PN": "0",
"mcu": "STM32",
"clockFrequency": 170,
"clockSource": "1",
"motorDrives": []
}
其中mcu, clockSource, motorDrives的具體參數(shù)我們不知道并且沒提示。
在軟件安裝目錄下\MC_SDK_6.2.1\Utilities\PC_Software\STMCWB\assets\hardware\mcu,有所有支持的mcu配置文件, 我們能配置的MCU型號只能從其中選擇。這里我們選擇STM32G431KBUx。
clockSource可以參考官方wiki 2.3.1 Specific properties 一節(jié),對應(yīng)的有四個(gè)參數(shù):
| Value | Description | supported MCUs |
|---|---|---|
| internal_osc | The source of the clock is the internal oscillator. | All MCUs |
| 8_crystal | The source of the clock is an 8 MHz crystal. | All MCUs |
| 24_crystal | The source of the clock is a 24 MHz crystal. | STM32G4xx and STM32G0xx |
| 48_crystal | The source of the clock is a 48 MHz crystal. | STM32G4xx |
選擇自己驅(qū)動(dòng)板對應(yīng)的即可。
motorDrives
參考別的配置文件,motorDrives配置較為復(fù)雜,還好有部分提示,跟著提示先一步一步填。
Missing property "name". Missing property "maxRatedVoltage". Missing property "minRatedVoltage". Missing property "maxRatedCurrent". Missing property "features".
前4個(gè)參數(shù)填起來輕輕松松,按照實(shí)際電路填寫即可。
"motorDrives": [
{
"name": "M1",
"maxRatedVoltage": 24,
"minRatedVoltage": 8,
"maxRatedCurrent": 2
}]
features則描述了驅(qū)動(dòng)器支持的特性,也是配置文件的核心。相關(guān)介紹見 WIKI: 《3 Features Specification》。
電流采樣模式
首先配置電流采樣模式。電流采樣支持以下幾種模式:
| mode | Description |
|---|---|
ThreeShunt_AmplifiedCurrents |
Three-shunt, amplified current hardware variant |
ThreeShunt_RawCurrents_SingleEnded |
Three-Shunt, Raw Currents, Single Ended OpAmp hardware variant |
ThreeShunt_RawCurrents_Differential |
Three-Shunt, Raw Currents, Differential OpAmp hardware variant |
ThreeShunt_RawCurrents_SingleEnded_ExternalGain |
Three-Shunt, Raw Currents, Single Ended Internal OpAmp with External Gain hardware variant |
ThreeShunt_RawCurrents_SingleEnded_InternalGain |
Three-Shunt, Raw Currents, Single Ended internal OpAmp with Internal Gain hardware variant |
| ...... | ...... |
參數(shù)
我這里使用的是driver帶的電流放大器,因此選擇三電阻,外部放大,即最簡單的ThreeShunt_AmplifiedCurrents。
"features": [
{
"name": "CurrentSensing",
"type": "CurrentSensing",
"tRise": 1000,
"hwVariants": [
{
"type": "ThreeShunt_AmplifiedCurrents"
}]
}]
該模式對應(yīng)如下參數(shù):
Parameters Type Description tNoise Number TNoise parameter of the phase switches. In ns shuntResistor Number Shunt Resistor value in Ohm offsetNetworkAttenuation Number Gain of the offset network opAmpGain Number Gain of the OpAmp amplification polarizationOffset Number Shift voltage added by the Offset network, in Volts, at OpAmp output. amplifyingNetworkImax Number Maximum current that is measurable by the current sensing network. amplifyingNetworkVm Number Voltage reference of the current sensing network amplifyingNetworkPrating Number Rated power (that can go through the shunt resistor)
根據(jù)實(shí)際分壓電路,填寫參數(shù)如下:
"type": "ThreeShunt_AmplifiedCurrents",
"shuntResistor": 0.01,
"amplifyingNetworkImax": 21.429,
"amplifyingNetworkVm": 3.3,
"amplifyingNetworkPrating": 2,
"offsetNetworkAttenuation": 0.885,
"opAmpGain": 8.697,
"polarizationOffset": 1.65
參數(shù)計(jì)算
對于電壓采樣,無論外圍電路如何,最終轉(zhuǎn)換公式均為\(I_{in} = AD_{in} \times
R_s \times Gain\)。MCSDK,會(huì)根據(jù)參數(shù),自動(dòng)計(jì)算出Gain。
對于我們自己的驅(qū)動(dòng)板,很多時(shí)候無法獲取詳細(xì)的參數(shù),此時(shí)我們就可以根據(jù)上述公式,反推出合適的值,代入到配置項(xiàng)中。
引腳配置
signals為引腳配置,編輯器會(huì)提示每個(gè)模式需要配置的引腳,在cubeMX中找到可以使用的ADC腳,填寫上即可。
"signals": {
"CURRENT_AMPL_U": [
{
"name": "PA4",
"help": "",
"cost": 0
}
],
"CURRENT_AMPL_V": [
{
"name": "PA5",
"help": "",
"cost": 0
}
],
"CURRENT_AMPL_W": [
{
"name": "PA6",
"help": "",
"cost": 0
}
]
},
傳感器模式
通過此特性,定義驅(qū)動(dòng)的傳感器模式。通常有反電動(dòng)勢,霍爾,編碼器幾種,這里使用霍爾傳感器配置。
通過CUBEMX查找支持HALL的引腳,填上即可。
{
"name": "SpeedAndPositionSensing",
"type": "SpeedAndPositionSensing",
"hwVariants": [
{
"type": "HallEffectSensor",
"help": "",
"signals": {
"HALLSENSOR_H1": [
{
"name": "PA0",
"help": "",
"cost": 0
}
],
"HALLSENSOR_H2": [
{
"name": "PA1",
"help": "",
"cost": 0
}
],
"HALLSENSOR_H3": [
{
"name": "PA2",
"help": "",
"cost": 0
}
]
}
}
]
}
相電壓生成
此項(xiàng)用于設(shè)定電壓輸出方式,F(xiàn)OC模式下有2種模式,分別是
DrivingHighAndLowSides:輸出6路PWM,分別控制高低半橋;
DrivingHighSidesAndThreeEnables:輸出3路PWM,控制高側(cè)半橋,以及3個(gè)使能信號。
這里使用3路PWM模式。同樣在CUBEMX中查找可用的引腳。
{
"name": "PhaseVoltageGeneration",
"type": "PhaseVoltageGeneration",
"driverName": "Driver or IGBT or MOSFET name",
"driverPN": "Driver or IGBT or MOSFET Part Number",
"minDeadTime": 500,
"maxSwitchingFreq": 100,
"tNoise": 500,
"hwVariants": [
{
"type": "DrivingHighSidesAndThreeEnables",
"help": "How to enable this variant",
"signals": {
"PWM_CHU_H": [
{
"name": "PA8",
"help": "",
"cost": 0
}
],
"PWM_CHV_H": [
{
"name": "PA9",
"help": "",
"cost": 0
}
],
"PWM_CHW_H": [
{
"name": "PA10",
"help": "",
"cost": 0
}
],
"PWM_CHU_EN": [
{
"name": "PA7",
"help": "",
"cost": 0
}
],
"PWM_CHV_EN": [
{
"name": "PA12",
"help": "",
"cost": 0
}
],
"PWM_CHW_EN": [
{
"name": "PB5",
"help": "",
"cost": 0
}
]
},
"highSideSwitchesDrivingPolarity": "Active high",
"enableDrivingPolarity": "Active high",
"deadTime": 550
}
]
},
其他配置
有了以上核心配置,就可以在Motor Control WorkBench中導(dǎo)入自定義控制器了。除了以上功能,還有電路保護(hù)等其他功能可以配置,跟著官方配置照葫蘆畫瓢即可。
導(dǎo)入效果
在Motor Control WorkBench中,新建項(xiàng)目,在inverter中可以看到我們新建的控制板
勾選上,一般情況下便可以生成代碼了。
完整配置文件
{
"type": "inverter",
"descVersion": 4,
"contentVersion": "1.0",
"name": "my_self_control",
"PN": "0",
"mcu": "STM32G431KBUx",
"clockFrequency": 170,
"clockSource": "24_crystal",
"motorDrives": [
{
"name": "M1",
"maxRatedVoltage": 24,
"minRatedVoltage": 8,
"maxRatedCurrent": 2,
"features": [
{
"name": "CurrentSensing",
"type": "CurrentSensing",
"tRise": 1000,
"hwVariants": [
{
"type": "ThreeShunt_AmplifiedCurrents",
"shuntResistor": 0.01,
"amplifyingNetworkImax": 21.429,
"amplifyingNetworkVm": 3.3,
"amplifyingNetworkPrating": 2,
"offsetNetworkAttenuation": 0.885,
"opAmpGain": 8.697,
"polarizationOffset": 1.65,
"signals": {
"CURRENT_AMPL_U": [
{
"name": "PA4",
"help": "",
"cost": 0
}
],
"CURRENT_AMPL_V": [
{
"name": "PA5",
"help": "",
"cost": 0
}
],
"CURRENT_AMPL_W": [
{
"name": "PA6",
"help": "",
"cost": 0
}
]
}
}
]
},
{
"name": "SpeedAndPositionSensing",
"type": "SpeedAndPositionSensing",
"hwVariants": [
{
"type": "HallEffectSensor",
"help": "",
"signals": {
"HALLSENSOR_H1": [
{
"name": "PA0",
"help": "",
"cost": 0
}
],
"HALLSENSOR_H2": [
{
"name": "PA1",
"help": "",
"cost": 0
}
],
"HALLSENSOR_H3": [
{
"name": "PA2",
"help": "",
"cost": 0
}
]
}
}
]
},
{
"name": "PhaseVoltageGeneration",
"type": "PhaseVoltageGeneration",
"driverName": "MP6450",
"driverPN": "MP6450",
"minDeadTime": 500,
"maxSwitchingFreq": 100,
"tNoise": 500,
"hwVariants": [
{
"type": "DrivingHighSidesAndThreeEnables",
"help": "How to enable this variant",
"signals": {
"PWM_CHU_H": [
{
"name": "PA8",
"help": "",
"cost": 0
}
],
"PWM_CHV_H": [
{
"name": "PA9",
"help": "",
"cost": 0
}
],
"PWM_CHW_H": [
{
"name": "PA10",
"help": "",
"cost": 0
}
],
"PWM_CHU_EN": [
{
"name": "PA7",
"help": "",
"cost": 0
}
],
"PWM_CHV_EN": [
{
"name": "PA12",
"help": "",
"cost": 0
}
],
"PWM_CHW_EN": [
{
"name": "PB5",
"help": "",
"cost": 0
}
]
},
"highSideSwitchesDrivingPolarity": "Active high",
"enableDrivingPolarity": "Active high",
"deadTime": 550
}
]
}
]
}
]
}
更多配置項(xiàng)
待補(bǔ)充

浙公網(wǎng)安備 33010602011771號