📄 stm32f10x_svpwm_1shunt.c
字号:
{
// First point
if ((hDutyV[2] - hDutyV[1] - TDEAD)>= MAX_TRTS)
{
dvDutyValues.hTimeSmp1 = (hDutyV[1] + hDutyV[2] + TDEAD) >> 1;
}
else
{
dvDutyValues.hTimeSmp1 = hDutyV[2] - TBEFORE;
}
// Second point
dvDutyValues.hTimeSmp2 = PWM_PERIOD - HTMIN + TSAMPLE;
}
if (bStatorFluxPos == BOUNDARY_3) //
{
// First point
dvDutyValues.hTimeSmp1 = hDutyV[0]-TBEFORE; // Dummy trigger
// Second point
dvDutyValues.hTimeSmp2 = PWM_PERIOD - HTMIN + TSAMPLE;
}
}
else
{
bInverted_pwm_new = INVERT_NONE;
bStatorFluxPos = REGULAR;
}
// Update DMA buffer Ch 1,2,3,4 (These value are required before update event)
// This buffer is updated using DMA burst
hCCRBuff[0] = dvDutyValues.hTimePhA;
hCCRBuff[1] = dvDutyValues.hTimePhB;
hCCRBuff[2] = dvDutyValues.hTimePhC;
hCCRBuff[3] = dvDutyValues.hTimeSmp1;
/*******************************************************************************
* Function Name : SVPWM_1ShuntNoPreloadAdj
* Description : Set the preload variables for PWM mode Ch 1,2,3,4
* Input : None
* Output : None
* Return : None
*******************************************************************************/
//SVPWM_1ShuntNoPreloadAdj();
// Set the preload vars for PWM mode Ch 1,2,3,4 (these value are required
// inside update event handler
switch (bInverted_pwm_new)
{
case INVERT_A:
// Preloads for CCMR
hPreloadCCMR1Set = hPreloadCCMR1Disable | CH1TOGGLE | CH2NORMAL;
hPreloadCCMR2Set = hPreloadCCMR2Disable | CH3NORMAL | CH4TOGGLE;
break;
case INVERT_B:
// Preloads for CCMR
hPreloadCCMR1Set = hPreloadCCMR1Disable | CH1NORMAL | CH2TOGGLE;
hPreloadCCMR2Set = hPreloadCCMR2Disable | CH3NORMAL | CH4TOGGLE;
break;
case INVERT_C:
// Preloads for CCMR
hPreloadCCMR1Set = hPreloadCCMR1Disable | CH1NORMAL | CH2NORMAL;
hPreloadCCMR2Set = hPreloadCCMR2Disable | CH3TOGGLE | CH4TOGGLE;
break;
default:
// Preloads for CCMR
hPreloadCCMR1Set = hPreloadCCMR1Disable | CH1NORMAL | CH2NORMAL;
hPreloadCCMR2Set = hPreloadCCMR2Disable | CH3NORMAL | CH4NORMAL;
break;
}
// Limit for update event
// The following instruction can be executed after Update handler
// before the get phase current (Second EOC)
// Set the current sampled
if (bStatorFluxPos == REGULAR) // Regual zone
{
switch (bSector)
{
case SECTOR_1: // Fisrt after C, Second after B
csCurrentSampled.sampCur1 = SAMP_NIC;
csCurrentSampled.sampCur2 = SAMP_IA;
break;
case SECTOR_2: // Fisrt after C, Second after A
csCurrentSampled.sampCur1 = SAMP_NIC;
csCurrentSampled.sampCur2 = SAMP_IB;
break;
case SECTOR_3: // Fisrt after A, Second after C
csCurrentSampled.sampCur1 = SAMP_NIA;
csCurrentSampled.sampCur2 = SAMP_IB;
break;
case SECTOR_4: // Fisrt after A, Second after B
csCurrentSampled.sampCur1 = SAMP_NIA;
csCurrentSampled.sampCur2 = SAMP_IC;
break;
case SECTOR_5: // Fisrt after B, Second after A
csCurrentSampled.sampCur1 = SAMP_NIB;
csCurrentSampled.sampCur2 = SAMP_IC;
break;
case SECTOR_6: // Fisrt after B, Second after C
csCurrentSampled.sampCur1 = SAMP_NIB;
csCurrentSampled.sampCur2 = SAMP_IA;
break;
}
}
if (bStatorFluxPos == BOUNDARY_1) // Two small, one big
{
switch (bSector)
{
case SECTOR_1: // Phase B is adjusted
case SECTOR_2:
csCurrentSampled.sampCur1 = SAMP_NIC;
csCurrentSampled.sampCur2 = SAMP_IB;
break;
case SECTOR_3: // Phase C is adjusted
case SECTOR_4:
csCurrentSampled.sampCur1 = SAMP_NIA;
csCurrentSampled.sampCur2 = SAMP_IC;
break;
case SECTOR_5: // Phase A is adjusted
case SECTOR_6:
csCurrentSampled.sampCur1 = SAMP_NIB;
csCurrentSampled.sampCur2 = SAMP_IA;
break;
}
}
if (bStatorFluxPos == BOUNDARY_2) // Two big, one small
{
switch (bSector)
{
case SECTOR_2: // Phase A is adjusted
case SECTOR_3:
csCurrentSampled.sampCur1 = SAMP_IB;
csCurrentSampled.sampCur2 = SAMP_IA;
break;
case SECTOR_4: // Phase B is adjusted
case SECTOR_5:
csCurrentSampled.sampCur1 = SAMP_IC;
csCurrentSampled.sampCur2 = SAMP_IB;
break;
case SECTOR_6: // Phase C is adjusted
case SECTOR_1:
csCurrentSampled.sampCur1 = SAMP_IA;
csCurrentSampled.sampCur2 = SAMP_IC;
break;
}
}
if (bStatorFluxPos == BOUNDARY_3)
{
if (bInverted_pwm_new == INVERT_A)
{
csCurrentSampled.sampCur1 = SAMP_OLDB;
csCurrentSampled.sampCur2 = SAMP_IA;
}
if (bInverted_pwm_new == INVERT_B)
{
csCurrentSampled.sampCur1 = SAMP_OLDA;
csCurrentSampled.sampCur2 = SAMP_IB;
}
}
#ifdef CURRENT_COMPENSATION
// Check for distortion compensation entering Boudary2
if ((bStatorFluxPosOld == REGULAR) && (bStatorFluxPos == BOUNDARY_2) && (State == RUN))
{
bReadDelta = 1;
}
else
{
bReadDelta = 0;
}
#endif
// Deleting Delta if Stator Pos is no more BOUDARY_2
if ((bStatorFluxPosOld == BOUNDARY_2) && (bStatorFluxPos != bStatorFluxPosOld)
&& (State == RUN))
{
hDeltaA = 0;
hDeltaB = 0;
hDeltaC = 0;
}
// Limit for the Get Phase current (Second EOC Handler)
}
/*******************************************************************************
* Function Name : SVPWM_1ShuntGetPhaseCurrentValues
* Description : This function computes current values of Phase A and Phase B
* in q1.15 format starting from values acquired from the A/D
* Converter peripheral.
* Input : None
* Output : Stat_Curr_a_b
* Return : None
*******************************************************************************/
Curr_Components SVPWM_1ShuntGetPhaseCurrentValues(void)
{
Curr_Components Local_Stator_Currents;
s32 wAux;
s16 hCurrA = 0, hCurrB = 0, hCurrC = 0;
u8 bCurrASamp = 0, bCurrBSamp = 0, bCurrCSamp = 0;
if (csCurrentSampled.sampCur1 == SAMP_OLDA)
{
hCurrA = hCurrAOld;
bCurrASamp = 1;
}
if (csCurrentSampled.sampCur1 == SAMP_OLDB)
{
hCurrB = hCurrBOld;
bCurrBSamp = 1;
}
// 触发一次AD转换可以不间断采样B相电流2次,结果分别在ADC1->JDR1和ADC1->JDR2中。
// 第一个采样值 *2 ,因为(hPhaseOffset)为2倍的零电流值
wAux = (s32)(ADC1->JDR2 << 1) - (s32)(hPhaseOffset); // (hPhaseOffset)为2倍的零电流值
switch (csCurrentSampled.sampCur1)
{
case SAMP_IA:
case SAMP_IB:
case SAMP_IC:
break;
case SAMP_NIA:
case SAMP_NIB:
case SAMP_NIC:
wAux = -wAux;
break;
default:
wAux = 0;
}
// Check saturation
if (wAux < S16_MIN)
{
wAux = S16_MIN;
}
else if (wAux > S16_MAX)
{
wAux = S16_MAX;
}
else
{
wAux = (s16)(wAux);
}
switch (csCurrentSampled.sampCur1)
{
case SAMP_IA:
case SAMP_NIA:
hCurrA = (s16)(wAux);
bCurrASamp = 1;
break;
case SAMP_IB:
case SAMP_NIB:
hCurrB = (s16)(wAux);
bCurrBSamp = 1;
break;
case SAMP_IC:
case SAMP_NIC:
hCurrC = (s16)(wAux);
bCurrCSamp = 1;
break;
}
// 触发一次AD转换可以不间断采样B相电流2次,结果分别在ADC1->JDR1和ADC1->JDR2中。
//第二个采样值 *2 ,因为(hPhaseOffset)为2倍的零电流值
wAux = (s32)(ADC1->JDR1 << 1) - (s32)(hPhaseOffset);
switch (csCurrentSampled.sampCur2)
{
case SAMP_IA:
case SAMP_IB:
case SAMP_IC:
break;
case SAMP_NIA:
case SAMP_NIB:
case SAMP_NIC:
wAux = -wAux;
break;
default:
wAux = 0;
}
// Check saturation
if (wAux < S16_MIN)
{
wAux = S16_MIN;
}
else if (wAux > S16_MAX)
{
wAux = S16_MAX;
}
else
{
wAux = (s16)(wAux);
}
switch (csCurrentSampled.sampCur2)
{
case SAMP_IA:
case SAMP_NIA:
hCurrA = (s16)(wAux);
bCurrASamp = 1;
break;
case SAMP_IB:
case SAMP_NIB:
hCurrB = (s16)(wAux);
bCurrBSamp = 1;
break;
case SAMP_IC:
case SAMP_NIC:
hCurrC = (s16)(wAux);
bCurrCSamp = 1;
break;
}
// Computation of the third value
if (bCurrASamp == 0)
hCurrA = -hCurrB -hCurrC;
if (bCurrBSamp == 0)
hCurrB = -hCurrA -hCurrC;
if (bCurrCSamp == 0)
hCurrC = -hCurrA -hCurrB;
// hCurrA, hCurrB, hCurrC values are the sampled values
#ifdef CURRENT_COMPENSATION
if (bReadDelta == 1)
{
hDeltaA = hCurrAOld - hCurrA;
hDeltaB = hCurrBOld - hCurrB;
hDeltaC = hCurrCOld - hCurrC;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -