FOC 5.0代碼分析如下:
uint16_t PWMperiod; /**< PWM period expressed in timer clock cycles unit:
* @f$hPWMPeriod = TimerFreq_{CLK} / F_{PWM}@f$ */
#define PWM_PERIOD_CYCLES (uint16_t)(ADV_TIM_CLK_MHz*\
(unsigned long long)1000000u/((uint16_t)(PWM_FREQUENCY)))
#define ADV_TIM_CLK_MHz 72
#define PWM_FREQUENCY 16000
PWM_Handle_M1.PWMperiod = PWM_PERIOD_CYCLES,
__weak uint16_t PWMC_SetPhaseVoltage ( PWMC_Handle_t * pHandle, alphabeta_t Valfa_beta )
{
int32_t wX, wY, wZ, wUAlpha, wUBeta, wTimePhA, wTimePhB, wTimePhC;
wUAlpha = Valfa_beta.alpha * ( int32_t )pHandle->hT_Sqrt3;
wUBeta = -( Valfa_beta.beta * ( int32_t )( pHandle->PWMperiod ) ) * 2 ;
wX = wUBeta;
wY = ( wUBeta + wUAlpha ) / 2 ;
wZ = ( wUBeta - wUAlpha ) / 2 ;
/* Sector calculation from wX, wY, wZ */
if ( wY < 0 )
{
if ( wZ < 0 )
{
pHandle->Sector = SECTOR_5;
wTimePhA = ( int32_t )( pHandle->PWMperiod ) / 4 + ( ( wY - wZ ) / ( int32_t ) 262144 );
wTimePhB = wTimePhA + wZ / 131072 ;
wTimePhC = wTimePhA - wY / 131072 ;
pHandle->lowDuty = wTimePhC;
pHandle->midDuty = wTimePhA;
pHandle->highDuty = wTimePhB;
}
else /* wZ >= 0 */
if ( wX <= 0 )
{
pHandle->Sector = SECTOR_4;
wTimePhA = ( int32_t )( pHandle->PWMperiod ) / 4 + ( ( wX - wZ ) / ( int32_t ) 262144 );
wTimePhB = wTimePhA + wZ / 131072 ;
wTimePhC = wTimePhB - wX / 131072 ;
pHandle->lowDuty = wTimePhC;
pHandle->midDuty = wTimePhB;
pHandle->highDuty = wTimePhA;
}
else /* wX > 0 */
{
pHandle->Sector = SECTOR_3;
wTimePhA = ( int32_t )( pHandle->PWMperiod ) / 4 + ( ( wY - wX ) / ( int32_t ) 262144 );
wTimePhC = wTimePhA - wY / 131072 ;
wTimePhB = wTimePhC + wX / 131072 ;
pHandle->lowDuty = wTimePhB;
pHandle->midDuty = wTimePhC;
pHandle->highDuty = wTimePhA;
}
}
else /* wY > 0 */
{
if ( wZ >= 0 )
{
pHandle->Sector = SECTOR_2;
wTimePhA = ( int32_t )( pHandle->PWMperiod ) / 4 + ( ( wY - wZ ) / ( int32_t ) 262144 );
wTimePhB = wTimePhA + wZ / 131072 ;
wTimePhC = wTimePhA - wY / 131072 ;
pHandle->lowDuty = wTimePhB;
pHandle->midDuty = wTimePhA;
pHandle->highDuty = wTimePhC;
}
else /* wZ < 0 */
if ( wX <= 0 )
{
pHandle->Sector = SECTOR_6;
wTimePhA = ( int32_t )( pHandle->PWMperiod ) / 4 + ( ( wY - wX ) / ( int32_t ) 262144 );
wTimePhC = wTimePhA - wY / 131072 ;
wTimePhB = wTimePhC + wX / 131072 ;
pHandle->lowDuty = wTimePhA;
pHandle->midDuty = wTimePhC;
pHandle->highDuty = wTimePhB;
}
else /* wX > 0 */
{
pHandle->Sector = SECTOR_1;
wTimePhA = ( int32_t )( pHandle->PWMperiod ) / 4 + ( ( wX - wZ ) / ( int32_t ) 262144 );
wTimePhB = wTimePhA + wZ / 131072 ;
wTimePhC = wTimePhB - wX / 131072 ;
pHandle->lowDuty = wTimePhA;
pHandle->midDuty = wTimePhB;
pHandle->highDuty = wTimePhC;
}
}
pHandle->CntPhA = ( uint16_t )wTimePhA;
pHandle->CntPhB = ( uint16_t )wTimePhB;
pHandle->CntPhC = ( uint16_t )wTimePhC;
return ( pHandle-> pFctSetADCSampPointSectX ( pHandle ) );
}