基于 MCSDK5.4.8 电机库修改两电阻采样方法

1. 前言

在当前使用的电机电阻采样方式中分为单电阻,双电阻,三电阻三种方式,其中在 ST MCSDK5.4 库中支持了两种采样方式,单电阻和三电阻,在市面还存在另外一种采样方式,即双电阻采样,本文讨论的是如何修改现有驱动库支持该种采样方式。

2. 电流双电阻采样机理

图1. 双电阻采样结构
图1. 双电阻采样结构

实际使用过程中双电阻采样同三电阻采样有相同的机制,即在 shunt 电阻上进行电流采集,并且根据基尔霍夫定理 Ia+Ib+Ic=0,采集两相电流即可以重构出第三路电流;三电阻电流采集会根据扇区不同分别转换电流采样的两个相线(AB,AC,BC 三种情况);而双电阻采样一般直接对 Ia,Ib 进行采样即可,在 FOC 运算中直接使用这两个量。

3. 操作步骤

3.1. 产生工程

使用 MCSDK workbench 产生工程,如何生成工程可以参考马达培训文档,这边不再详细说明,需要使用三电阻采样方式,注意配置的是 U,V 即对应的 Ia,Ib。
图2. MCSDK workbench 电流采样配置界面
图2. MCSDK workbench 电流采样配置界面
图3. MCSDK workbench 采样信号配置界面
图3. MCSDK workbench 采样信号配置界面

3.2. 文件拷贝

以 STM32G43RBT6 配置为例,生成工程中电流采样使用的是 r3_2_g4xx_pwm_curr_fdbk.c文件, 找到这个文件复制一份,重新命名为 r2_2_g4xx_pwm_curr_fdbk.c,我们会在这个文件中对相关函数进行重新定义。这边有个点要注意,原始的电机库文件函数定义都是__weak 属性,因此在不破坏原始文件的同时,我们可以重新定义我们需要的函数。本案例中我们只需要重新定义两个函数,一个是读取静态电流数值的函数,一个是运行过程中得到三相电流的函数。

__weak void R3_2_CurrentReadingPolarization( PWMC_Handle_t * pHdl )
__weak void R3_2_GetPhaseCurrents( PWMC_Handle_t * pHdl, ab_t * Iab )

图4. 电机库的电流采样文件所在位置
图4. 电机库的电流采样文件所在位置

3.3. 修改读取静态电流函数

因为对于两电阻采样,我们后面只会使用到 PhaseAOffset 和 PhaseBOffset 这两个值,可以将 R3_2_CurrentReadingPolarization 这个函数改为只检测这两个数据,这边也可以不进行修改,第三个 PhaseCOffset 不使用即可,这个函数我们沿用原来的。在打开的r2_2_g4xx_pwm_curr_fdbk.c 文件中,除了包含文件以及 R3_2_GetPhaseCurrents 函数外,其他内容都删除掉。
图5. 电流采样文件保留内容
图5. 电流采样文件保留内容

3.4. 修改电流读取函数

修改 R3_2_GetPhaseCurrents 函数中的电流读取与计算的设定,这边我们需要屏蔽之前三电阻方式按照扇区来区分采样以及采样相线的设定,增加如下程序,注意把__weak 属性删除掉。

#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
 * @brief It computes and return latest converted motor phase currents motor
 * @param pHdl: handler of the current instance of the PWM component
 * @retval Ia and Ib current in Curr_Components format
 */ 
void R3_2_GetPhaseCurrents( PWMC_Handle_t * pHdl, ab_t * Iab )
{
	#if defined (__ICCARM__)
	 #pragma cstat_disable = "MISRAC2012-Rule-11.3"
	#endif /* __ICCARM__ */
	 PWMC_R3_2_Handle_t * pHandle = ( PWMC_R3_2_Handle_t * )pHdl; 
	#if defined (__ICCARM__)
	 #pragma cstat_restore = "MISRAC2012-Rule-11.3"
	#endif /* __ICCARM__ */
	 TIM_TypeDef * TIMx = pHandle->pParams_str->TIMx;
	 uint8_t Sector;
	 int32_t Aux;
	 uint32_t ADCDataReg1;
	 uint32_t ADCDataReg2;
	 
	 Sector = ( uint8_t )pHandle->_Super.Sector;
	 ADCDataReg1 = *pHandle->pParams_str->ADCDataReg1[Sector];
	 ADCDataReg2 = *pHandle->pParams_str->ADCDataReg2[Sector];
	 
	 /* disable ADC trigger source */
	 LL_TIM_SetTriggerOutput(TIMx, LL_TIM_TRGO_RESET);
	/* Current on Phase C is not accessible */
	/* Ia = PhaseAOffset - ADC converted value) */
	Aux = ( int32_t )( pHandle->PhaseAOffset ) - ( int32_t )( ADCDataReg1 );
	/* Saturation of Ia */
	if ( Aux < -INT16_MAX )
	{
		Iab->a = -INT16_MAX;
	}
	else if ( Aux > INT16_MAX )
	{
		Iab->a = INT16_MAX;
	}
	else
	{
		Iab->a = ( int16_t )Aux;
	}
	/* Ib = PhaseBOffset - ADC converted value) */
	Aux = ( int32_t )( pHandle->PhaseBOffset ) - ( int32_t )( ADCDataReg2 );
	/* Saturation of Ib */
	if ( Aux < -INT16_MAX )
	{
		Iab->b = -INT16_MAX;
	}
	else if ( Aux > INT16_MAX )
	{
		Iab->b = INT16_MAX;
	}
	else
	{
		Iab->b = ( int16_t )Aux;
	}
	 pHandle->_Super.Ia = Iab->a;
	 pHandle->_Super.Ib = Iab->b;
	 pHandle->_Super.Ic = -Iab->a - Iab->b;
}

3.5. 限制最大占空比

三电阻可以在任意两相采样电阻上选取可以采样的相线以及采样点,配置较灵活,但如果是双电阻,则需要注意我们若不做特别处理,最大占空比不能做到 100%,因此我们可以根据实际电路以及 PWM 频率等综合考虑进去,对最大调制比进行限制。
图6. 电流采样点位置
比如我们使用的 PWM 周期为 t,tr 为振铃波形时间,tn 为相线干扰波形,ts 为 ADC 采样时间,tc 为 ADC 转换时间,Dt 为死区时间,使用一个 ADC 进行双路电流采样,那么可以估算如下,如果按照中心点触发方式,则有效采样的最小占空比为:

𝑡𝑑𝑢𝑡𝑦 > max(𝑡𝑟,𝑡𝑛) + 𝐷𝑡 且 𝑡𝑑𝑢𝑡𝑦 > 𝑡𝑠 + 𝑡𝑐 + 𝑡𝑠

因此计算完成后需要修改 parameters_conversion.h 中的最大调制比,比如计算后我们只能到 95%的调制比,则调整为如下,关于调制比参数设定见 Workbench 的安装目录:

#define START_INDEX 57
#define MAX_MODULE 31128 // root(Vd^2+Vq^2) <= MAX_MODULE = 32767*95%
#define MMITABLE {\
	32613,32310,32016,31872,31589,31314,31046,30784,30529,30404,\
	30158,29919,29684,29456,29343,29122,28906,28695,28488,28285,\
	28186,27990,27798,27610,27425,27245,27155,26980,26808,26639,\
	26473,26392,26230,26072,25917,25764,25614,25540,25394,25250,\
	25109,24970,24901,24766,24633,24501,24372,24245,24182,24058,\
	23936,23816,23697,23580,23522,23408,23295,23184,23075,23021,\
	22913,22808,22703,22600,22499,22449,22349,22251,22154,22059,\
	21964\
}

C:\Program Files (x86)\STMicroelectronics\MC_SDK_5.4.8\Middlewares\ST\MotorControl\templates 中的parameters_conversion.h.ftl 文件,使用记事本打开即可。

4. 后续升级操作

因为两电阻采样方式,在 shunt 电阻上的振铃电流以及考虑到 ADC 采样转换时间问题,相比较三电阻来说最大占空比不能做到 100%,因此需要进行电流重构等算法以便扩大调制比。

文档中所用到的工具及版本

MCSDK:5.4.8


本文档参考ST官方的《【应用笔记】LAT1334+基于MCSDK5.4.8电机库修改两电阻采样方法》文档。
参考下载地址:https://download.csdn.net/download/u014319604/89036764

  • 18
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
STM32电机控制开发包完全版V5.5.1-5.Y.1,2021年5月3日更新。 STM32 Motor Control Software Development Kit (MCSDK) - FULL source code Main Changes Version 5.Y.1 of the Motor Control Software Development Kit (X-CUBE-MCDSK) is a bug fix release of version 5.Y.0. It fixes the following issues: Some Motor Control examples delivered with MCSDK 5.Y.0 would not configure DMA channels properly to work with the new Motor Control and thus with the Motor Pilot. Also, the baudrate of the UART port configured by examples is set to 1,8 Mbps, the same as ST Motor Pilot's default. ACIM motor based examples do not build on 5.Y.0. They build well on 5.Y.1. The descriptions of EVSPIN32F0x inverter boards delivered with the Workbench had wrong DC & AC voltage supply ranges. These have been corrected as follows: Inverter Wrong AC supply range Corrected AC supply range DC supply range EVSPIN32F02Q1S1, EVSPIN32F0251S1 20 - 120 Vac 15 - 120 Vac 20 - 170 Vdc EVSPIN32F06Q1S1, EVSPIN32F0601S1 50 - 280 Vac 35 - 280 Vac 50 - 400 Vdc EVSPIN32F06Q2S1, EVSPIN32F0602S1 50 - 280 Vac 35 - 280 Vac 50 - 400 Vdc EVSPIN32F06Q1S3, EVSPIN32F0601S3 50 - 280 Vac 35 - 280 Vac 50 - 400 Vdc Six-Step High Voltage examples based on the EVSPIN32F0251S1 inverter board were mistakenly not included into 5.Y.0 version. They are in 5.Y.1. The Pilot would fail to update registers values from the embedded application in some situations. In such a case, information like the motor rotation speed, status and error information would not display. Fixed issues with the DAC output feature. Added many signals to the Datalog and the DAC output features. Among them, the observers, encoder and Hall sensors angles. Running the motor in the negative direction on STM32F0 based designs with 1 shunt and Hall sensor configuration may trigger an overcurrent error. Fixed an issue found on ESC G4 and F3 inverter boards with Motor Control Protocol v2. Contents Components Version License Terms Release Note Utilities/PC_Software/STMotorProfiler 1.3.2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值