关于stm32 sdk5.0电机库开源程序的理解
1、这段程序中PWM_PERIOD的意思?2、舍得同步AD采样的的作用和原理?
// ADC Syncronization setting value
if ((u16)(PWM_PERIOD-hTimePhA) > TW_AFTER)
{
hTimePhD = PWM_PERIOD - 1;
}
else
{
hDeltaDuty = (u16)(hTimePhA - hTimePhB);
3、穿越点的定于和原理
// Definition of crossing point
if (hDeltaDuty > (u16)(PWM_PERIOD-hTimePhA)*2)
{
hTimePhD = hTimePhA - TW_BEFORE; // Ts before Phase A
}
else
{
hTimePhD = hTimePhA + TW_AFTER; // DT + Tn after Phase A
if (hTimePhD >= PWM_PERIOD)
{
// Trigger of ADC at Falling Edge PWM4
// OCR update
//Set Polarity of CC4 Low
PWM4Direction=PWM1_MODE;
hTimePhD = (2 * PWM_PERIOD) - hTimePhD-1;
}
void SVPWM_3ShuntCalcDutyCycles (Volt_Components Stat_Volt_Input)
{
s32 wX, wY, wZ, wUAlpha, wUBeta;
u16hTimePhA=0, hTimePhB=0, hTimePhC=0, hTimePhD=0;
u16hDeltaDuty;
wUAlpha = Stat_Volt_Input.qV_Component1 * T_SQRT3 ;
wUBeta = -(Stat_Volt_Input.qV_Component2 * T);
wX = wUBeta;
wY = (wUBeta + wUAlpha)/2;
wZ = (wUBeta - wUAlpha)/2;
// Sector calculation from wX, wY, wZ
if (wY<0)
{
if (wZ<0)
{
bSector = SECTOR_5;
}
else // wZ >= 0
if (wX<=0)
{
bSector = SECTOR_4;
}
else // wX > 0
{
bSector = SECTOR_3;
}
}
else // wY > 0
{
if (wZ>=0)
{
bSector = SECTOR_2;
}
else // wZ < 0
if (wX<=0)
{
bSector = SECTOR_6;
}
else // wX > 0
{
bSector = SECTOR_1;
}
}
/* Duty cycles computation */
PWM4Direction=PWM2_MODE;
switch(bSector)
{
//#define T (PWM_PERIOD * 4)
//#define PWM_PRSC ((u8)0)
/* Resolution: 1Hz */
//#define PWM_PERIOD ((u16) (CKTIM / (u32)(2 * PWM_FREQ *(PWM_PRSC+1))))
//2^17 = 131072
case SECTOR_1:
hTimePhA = (T/8) + ((((T + wX) - wZ)/2)/131072);
hTimePhB = hTimePhA + wZ/131072;
hTimePhC = hTimePhB - wX/131072;
// ADC Syncronization setting value
if ((u16)(PWM_PERIOD-hTimePhA) > TW_AFTER)
{
hTimePhD = PWM_PERIOD - 1;
}
else
{
hDeltaDuty = (u16)(hTimePhA - hTimePhB);
// Definition of crossing point
if (hDeltaDuty > (u16)(PWM_PERIOD-hTimePhA)*2)
{
hTimePhD = hTimePhA - TW_BEFORE; // Ts before Phase A
}
else
{
hTimePhD = hTimePhA + TW_AFTER; // DT + Tn after Phase A
if (hTimePhD >= PWM_PERIOD)
{
// Trigger of ADC at Falling Edge PWM4
// OCR update
//Set Polarity of CC4 Low
PWM4Direction=PWM1_MODE;
hTimePhD = (2 * PWM_PERIOD) - hTimePhD-1;
}
}
}
// ADC_InjectedChannelConfig(ADC1, PHASE_B_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC1->JSQR = PHASE_B_MSK + BUS_VOLT_FDBK_MSK + SEQUENCE_LENGHT;
//ADC_InjectedChannelConfig(ADC2, PHASE_C_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC2->JSQR = PHASE_C_MSK + TEMP_FDBK_MSK + SEQUENCE_LENGHT;
break;
case SECTOR_2:
hTimePhA = (T/8) + ((((T + wY) - wZ)/2)/131072);
hTimePhB = hTimePhA + wZ/131072;
hTimePhC = hTimePhA - wY/131072;
// ADC Syncronization setting value
if ((u16)(PWM_PERIOD-hTimePhB) > TW_AFTER)
{
hTimePhD = PWM_PERIOD - 1;
}
else
{
hDeltaDuty = (u16)(hTimePhB - hTimePhA);
// Definition of crossing point
if (hDeltaDuty > (u16)(PWM_PERIOD-hTimePhB)*2)
{
hTimePhD = hTimePhB - TW_BEFORE; // Ts before Phase B
}
else
{
hTimePhD = hTimePhB + TW_AFTER; // DT + Tn after Phase B
if (hTimePhD >= PWM_PERIOD)
{
// Trigger of ADC at Falling Edge PWM4
// OCR update
//Set Polarity of CC4 Low
PWM4Direction=PWM1_MODE;
hTimePhD = (2 * PWM_PERIOD) - hTimePhD-1;
}
}
}
//ADC_InjectedChannelConfig(ADC1, PHASE_A_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC1->JSQR = PHASE_A_MSK + BUS_VOLT_FDBK_MSK + SEQUENCE_LENGHT;
//ADC_InjectedChannelConfig(ADC2,
// PHASE_C_CHANNEL,1,SAMPLING_TIME_CK);
ADC2->JSQR = PHASE_C_MSK + TEMP_FDBK_MSK + SEQUENCE_LENGHT;
break;
case SECTOR_3:
hTimePhA = (T/8) + ((((T - wX) + wY)/2)/131072);
hTimePhC = hTimePhA - wY/131072;
hTimePhB = hTimePhC + wX/131072;
// ADC Syncronization setting value
if ((u16)(PWM_PERIOD-hTimePhB) > TW_AFTER)
{
hTimePhD = PWM_PERIOD - 1;
}
else
{
hDeltaDuty = (u16)(hTimePhB - hTimePhC);
// Definition of crossing point
if (hDeltaDuty > (u16)(PWM_PERIOD-hTimePhB)*2)
{
hTimePhD = hTimePhB - TW_BEFORE; // Ts before Phase B
}
else
{
hTimePhD = hTimePhB + TW_AFTER; // DT + Tn after Phase B
if (hTimePhD >= PWM_PERIOD)
{
// Trigger of ADC at Falling Edge PWM4
// OCR update
//Set Polarity of CC4 Low
PWM4Direction=PWM1_MODE;
hTimePhD = (2 * PWM_PERIOD) - hTimePhD-1;
}
}
}
//ADC_InjectedChannelConfig(ADC1, PHASE_A_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC1->JSQR = PHASE_A_MSK + BUS_VOLT_FDBK_MSK + SEQUENCE_LENGHT;
//ADC_InjectedChannelConfig(ADC2, PHASE_C_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC2->JSQR = PHASE_C_MSK + TEMP_FDBK_MSK + SEQUENCE_LENGHT;
break;
case SECTOR_4:
hTimePhA = (T/8) + ((((T + wX) - wZ)/2)/131072);
hTimePhB = hTimePhA + wZ/131072;
hTimePhC = hTimePhB - wX/131072;
// ADC Syncronization setting value
if ((u16)(PWM_PERIOD-hTimePhC) > TW_AFTER)
{
hTimePhD = PWM_PERIOD - 1;
}
else
{
hDeltaDuty = (u16)(hTimePhC - hTimePhB);
// Definition of crossing point
if (hDeltaDuty > (u16)(PWM_PERIOD-hTimePhC)*2)
{
hTimePhD = hTimePhC - TW_BEFORE; // Ts before Phase C
}
else
{
hTimePhD = hTimePhC + TW_AFTER; // DT + Tn after Phase C
if (hTimePhD >= PWM_PERIOD)
{
// Trigger of ADC at Falling Edge PWM4
// OCR update
//Set Polarity of CC4 Low
PWM4Direction=PWM1_MODE;
hTimePhD = (2 * PWM_PERIOD) - hTimePhD-1;
}
}
}
//ADC_InjectedChannelConfig(ADC1, PHASE_A_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC1->JSQR = PHASE_A_MSK + BUS_VOLT_FDBK_MSK + SEQUENCE_LENGHT;
//ADC_InjectedChannelConfig(ADC2, PHASE_B_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC2->JSQR = PHASE_B_MSK + TEMP_FDBK_MSK + SEQUENCE_LENGHT;
break;
case SECTOR_5:
hTimePhA = (T/8) + ((((T + wY) - wZ)/2)/131072);
hTimePhB = hTimePhA + wZ/131072;
hTimePhC = hTimePhA - wY/131072;
// ADC Syncronization setting value
if ((u16)(PWM_PERIOD-hTimePhC) > TW_AFTER)
{
hTimePhD = PWM_PERIOD - 1;
}
else
{
hDeltaDuty = (u16)(hTimePhC - hTimePhA);
// Definition of crossing point
if (hDeltaDuty > (u16)(PWM_PERIOD-hTimePhC)*2)
{
hTimePhD = hTimePhC - TW_BEFORE; // Ts before Phase C
}
else
{
hTimePhD = hTimePhC + TW_AFTER; // DT + Tn after Phase C
if (hTimePhD >= PWM_PERIOD)
{
// Trigger of ADC at Falling Edge PWM4
// OCR update
//Set Polarity of CC4 Low
PWM4Direction=PWM1_MODE;
hTimePhD = (2 * PWM_PERIOD) - hTimePhD-1;
}
}
}
//ADC_InjectedChannelConfig(ADC1, PHASE_A_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC1->JSQR = PHASE_A_MSK + BUS_VOLT_FDBK_MSK + SEQUENCE_LENGHT;
//ADC_InjectedChannelConfig(ADC2, PHASE_B_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC2->JSQR = PHASE_B_MSK + TEMP_FDBK_MSK + SEQUENCE_LENGHT;
break;
case SECTOR_6:
hTimePhA = (T/8) + ((((T - wX) + wY)/2)/131072);
hTimePhC = hTimePhA - wY/131072;
hTimePhB = hTimePhC + wX/131072;
// ADC Syncronization setting value
if ((u16)(PWM_PERIOD-hTimePhA) > TW_AFTER)
{
hTimePhD = PWM_PERIOD - 1;
}
else
{
hDeltaDuty = (u16)(hTimePhA - hTimePhC);
// Definition of crossing point
if (hDeltaDuty > (u16)(PWM_PERIOD-hTimePhA)*2)
{
hTimePhD = hTimePhA - TW_BEFORE; // Ts before Phase A
}
else
{
hTimePhD = hTimePhA + TW_AFTER; // DT + Tn after Phase A
if (hTimePhD >= PWM_PERIOD)
{
// Trigger of ADC at Falling Edge PWM4
// OCR update
//Set Polarity of CC4 Low
PWM4Direction=PWM1_MODE;
hTimePhD = (2 * PWM_PERIOD) - hTimePhD-1;
}
}
}
//ADC_InjectedChannelConfig(ADC1, PHASE_B_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC1->JSQR = PHASE_B_MSK + BUS_VOLT_FDBK_MSK + SEQUENCE_LENGHT;
//ADC_InjectedChannelConfig(ADC2, PHASE_C_CHANNEL,1,
// SAMPLING_TIME_CK);
ADC2->JSQR = PHASE_C_MSK + TEMP_FDBK_MSK + SEQUENCE_LENGHT;
break;
default:
break;
}
if (PWM4Direction == PWM2_MODE)
{
//Set Polarity of CC4 High
TIM1->CCER &= 0xDFFF;
}
else
{
//Set Polarity of CC4 Low
TIM1->CCER |= 0x2000;
}
/* Load compare registers values */
TIM1->CCR1 = hTimePhA;
TIM1->CCR2 = hTimePhB;
TIM1->CCR3 = hTimePhC;
TIM1->CCR4 = hTimePhD; // To Syncronyze the ADC
} 第一次用stm32 希望大家赐教 不懂,路过帮顶!ST有专门的电机专家,推广会时候介绍。 ST的库做的太花哨,只能玩玩demo,不实用,要做产品还要用户优化核心算法,如果能做到TI的fast那种效果才可以 carefree1986 发表于 2018-9-17 09:17
ST的库做的太花哨,只能玩玩demo,不实用,要做产品还要用户优化核心算法,如果能做到TI的fast那种效果才可 ...
TI的也是库我用的28027效果 还可以,就是带着负载启动还是差一点 zdczhengdecai 发表于 2018-9-17 12:09
TI的也是库我用的28027效果 还可以,就是带着负载启动还是差一点
TI的fast已经很不错了,已经比很多的商业化产品性能好了 看标题还以为楼主要讲心得呢
页:
[1]