📄 bldczc.c
字号:
/* if ( (pTimes->Per_ZCrosFlt / pState_Comput->Coef_Toff)
> pState_Comput->Const_PerProcCmt ) */
Temp1F32.RegParts.MSBpart = 0;
Temp1F32.RegParts.LSBpart = pTimes->Per_ZCrosFlt;
Temp3F32.Reg32bit = L_mult_ls ( Temp1F32.Reg32bit, pState_Comput->Coef_Toff );
if ( ((UWord32)Temp3F32.Reg32bit) > pState_Comput->Const_PerProcCmt)
{
/* pTimes->Per_Toff = (pTimes->Per_ZCrosFlt / pState_Comput->Coef_Toff)
/ pState_Comput->Coef_Toff; */
pTimes->Per_Toff = Temp3F32.RegParts.LSBpart;
}
else
{
pTimes->Per_Toff = pState_Comput->Const_PerProcCmt;
}
/* Possibly pTimes->Per_ZCros_m1 = pTimes->Per_ZCros0; */
pTimes->Per_ZCros0 = pTimes->Per_ZCros;
pTimes->T_ZCros0 = pTimes->T_ZCros;
pState_Comput->Cmd_Comput.B.ZC_ComputFlag = 1;
pState_Comput->Cmd_Comput.B.ToffComp_CmdFlag = 1;
return (PASS);
}
/*--------------------[ SetCalculation - End ]-----------------------------*/
/****************************************************************************************************
*
* MODULE: bldczcComputInit ( bldczc_sStateComput *pState_Comput,
* bldczc_sTimes *pTimes,
* UWord16 T_Actual,
* bldczc_sComputInit *pComputInit )
*
* DESCRIPTION: function bldczcComputInit() initializes the data structures
* for bldczcComput() algorithm (time intervals computation)
* if pComputInit->Mode_CoefInit = BLDCZC_SET_DEFAULT
* then coeficients for time periods computation
* in pState_Comput pointed structure are set
* if pComputInit->Mode_StateComputInit = BLDCZC_SET_DEFAULT
* then status variables in pState_Comput pointed structure
* for time periods computation algorithms bldczcComput()
* are initialized
* if pComputInit->Mode_TimesInit = BLDCZC_SET_DEFAULT
* then the structure pointed by pTimes that contains the time
* variables for all BLDC motor BEMF Zero Crossing algorithms
* is initialized
* Refer to SDK documentation for detailes.
*
* RETURNS: The function returns the PASS (0)
*
* ARGUMENTS: The function has four arguments: out - pointer to bldczc_sStateComput structure that
* contains the status variables for
* BEMF Zero Crossing Computation algorithms
* out - pointer to bldczc_sTimes structure that
* contains the time variables for all
* BLDC motor BEMF Zero Crossing algorithms
* in - T_Actual - 16bit range Actual Time
* in - pointer to bldczc_sComputInit structure
* which contains constantes and coeficients
* for initialization
*
* RANGE ISSUES: All the time variables and components T_x in bldczc_sTimes structure are
* computed as 16 bit rollower registers. It mean that if their results overflows
* 16 bits, they are not saturated, just the overflow bit is ignored and low 16 bits
* word is taken as a result. Then the T_x variables can be used as outputs and inputs
* from a 16 bit past compare timer used as a system clock base!
*
* SPECIAL ISSUES: The function calculates correct results if the saturation mode is set or not .
*
****************************************************************************************************/
/*--------------------[ bldczcComputInit - Begin ]-------------------------*/
Result bldczcComputInit ( bldczc_sStateComput *pState_Comput,
bldczc_sTimes *pTimes,
UWord16 T_Actual,
bldczc_sComputInit *pComputInit )
{
/* temporary registers - unions for 16bit MSB,LSB or 32 bit acces */
uReg32 Temp1F32;
uReg32 Temp2F32;
uReg32 Per_CmtPresetF32;
pState_Comput->Const_PerProcCmt = pComputInit->Const_PerProcCmt;
/* Init Maximal Period of Commutation Proceeding */
/* time of motor coil reverse current */
pState_Comput->Max_PerCmt = pComputInit->Max_PerCmt; /* Init Maximal Commutation Period */
if ( pComputInit->Mode_CoefInit == BLDCZC_SET_DEFAULT ) /* BLDCZC_SET_DEFAULT/BLDCZC_DO_NOT_EFFECT Coef variables */
{
pState_Comput->Coef_CmtPrecompLShft = pComputInit->Coef_CmtPrecompLShft;
/* Init Commutation time precomputation Coeficient */
pState_Comput->Coef_CmtPrecompFrac = pComputInit->Coef_CmtPrecompFrac;
/* Init Commutation time precomputation Coeficient */
pState_Comput->Coef_HlfCmt = pComputInit->Coef_HlfCmt; /* Init Half commutation Coeficient */
pState_Comput->Coef_Toff = pComputInit->Coef_Toff; /* Init Zero Crossing Toff Coeficient */
}
if (pComputInit->Mode_StateComputInit == BLDCZC_SET_DEFAULT)
{
pState_Comput->Cmd_Comput.B.ZCOKGet_Comput_RqFlag = 0; /* Zero Cross OK Get Comput Request Flag */
pState_Comput->Cmd_Comput.B.ZCMiss_Comput_RqFlag = 0; /* Zero Cross Missed Comput Request Flag */
pState_Comput->Cmd_Comput.B.ZC_ComputFlag = 0; /* Init Zero Crossing Computed Flag
Prepare flags noZCCalculation before PresetCalculation */
/* Warning: this flag will be set below if
pComputInit->Mode_TimesInit == BLDCZC_SET_DEFAULT*/
}
if ( pComputInit->Mode_TimesInit == BLDCZC_SET_DEFAULT )
{
pTimes->T_Cmt0 = T_Actual;
pTimes->T_ZCros = T_Actual;
pTimes->Per_ZCros = pComputInit->Per_CmtStart;
pTimes->Per_ZCros0 = pComputInit->Per_CmtStart;
/* Possibly pTimes->Per_ZCros_m1 = pComputInit->Per_CmtStart; */
/* Possibly Temp2F32.Reg32bit = (UWord32)pTimes->Per_ZCros + (UWord32)pTimes->Per_ZCros0 \
+ (UWord32)pTimes->Per_ZCros_m1;
pTimes->Per_ZCrosFlt = L_mult_ls (Temp2F32.Reg32bit,FRAC16(1.0/3.0)); */
pTimes->Per_ZCrosFlt = (pTimes->Per_ZCros/2 + pTimes->Per_ZCros0/2);
/* Removed pTimes->Per_HlfCmt = pTimes->Per_ZCrosFlt / pState_Comput->Coef_HlfCmt
16 bits rest, no saturation */
Temp1F32.RegParts.MSBpart = 0;
Temp1F32.RegParts.LSBpart = pTimes->Per_ZCrosFlt;
Temp2F32.Reg32bit = L_mult_ls ( Temp1F32.Reg32bit, pState_Comput->Coef_HlfCmt );
pTimes->Per_HlfCmt = Temp2F32.RegParts.LSBpart;
pTimes->Per_Toff = pComputInit->Per_ToffStart;
pState_Comput->Cmd_Comput.B.ToffComp_CmdFlag = 1;
/* ?Toff period Computed Information Flag */
pState_Comput->Cmd_Comput.B.ZC_ComputFlag = 1;
/* Zero Crossing Computed Flag
Prepare flags for PresetCalculation without noZCCalculation */
/* Possibly pTimes->Per_ZCros_m1 = pTimes->Per_ZCros0; */
pTimes->Per_ZCros0 = pTimes->Per_ZCros;
pTimes->T_ZCros0 = pTimes->T_ZCros;
/* if ( pState_Comput->Coef_CmtPrecomp * pTimes->Per_ZCrosFlt <= pState_Comput->Max_PerCmt )
Coef_CmtPrecomp has 2 parts Coef_CmtPrecompFrac and Coef_CmtPrecompLShft */
Temp1F32.RegParts.MSBpart = 0;
/* Temp1F32.RegParts.LSBpart = pTimes->Per_ZCrosFlt; */
Temp1F32.RegParts.LSBpart = pTimes->Per_ZCrosFlt;
Per_CmtPresetF32.Reg32bit = L_mult_ls ( Temp1F32.Reg32bit, pState_Comput->Coef_CmtPrecompFrac );
/* scale */
Per_CmtPresetF32.Reg32bit = Per_CmtPresetF32.Reg32bit << pState_Comput->Coef_CmtPrecompLShft;
if ( ((UWord32)Per_CmtPresetF32.Reg32bit) <= pState_Comput->Max_PerCmt )
{
/* pTimes->Per_CmtPreset = pState_Comput->Coef_CmtPrecomp * pTimes->Per_ZCrosFlt */
pTimes->Per_CmtPreset = Per_CmtPresetF32.RegParts.LSBpart;
}
else
{
pTimes->Per_CmtPreset = pState_Comput->Max_PerCmt;
};
};
return (PASS);
}
/*--------------------[ bldczcComputInit - End ]---------------------------*/
/****************************************************************************************************
*
* MODULE: bldczcCmtServ ( bldczc_sStateCmt *pStateCmt )
*
* DESCRIPTION: function bldczcCmtServ sets BLDC motor commutation.
* It should be called from main SW before motor commuted.
* It changes Cmd_Cmt command and the next commutation step variable
* Step_Cmt_Next according to pState_Cmt->Cmd_Cmt.B.DIRFlag
* Refer to SDK documentation for detailes.
*
* RETURNS: The function returns the PASS (0)
*
* ARGUMENTS: The function has one argument: in/out - pointer to bldczc_sStateCmt structure that
* contains the status variables for
* BLDC motor BEMF Zero Crossing
* Commutation algorithm
*
* RANGE ISSUES: The pStateCmt->Step_Cmt_Next varible is inside <MIN_STEP_CMT, MAX_STEP_CMT> interval
*
* SPECIAL ISSUES: NONE.
*
****************************************************************************************************/
/*--------------------[ bldczcCmtServ ]------------------------------------*/
Result bldczcCmtServ ( bldczc_sStateCmt *pStateCmt )
{
if ( pStateCmt->Cmd_Cmt.B.CmtDone_CmtServ_RqFlag)
{
if ( !pStateCmt->Cmd_Cmt.B.DIRFlag )
{
if (pStateCmt->Step_Cmt_Next < MAX_STEP_CMT)
{
pStateCmt->Step_Cmt_Next++ ;
}
else
{
pStateCmt->Step_Cmt_Next = MIN_STEP_CMT;
}
}
else /* pStateCmt->Cmd_Cmt.B.DIRFlag = 1 */
{
if ( pStateCmt->Step_Cmt_Next != MIN_STEP_CMT )
{
pStateCmt->Step_Cmt_Next-- ;
}
else
{
pStateCmt->Step_Cmt_Next = MAX_STEP_CMT;
}
}
pStateCmt->Cmd_Cmt.B.CmtServ_CmdFlag = 1;
pStateCmt->Cmd_Cmt.B.CmtPreset_DrvRqFlag = 1;
pStateCmt->Cmd_Cmt.B.CmtDone_CmtServ_RqFlag = 0;
}
return (PASS);
}
/* -------------------[ bldczcCmtServ-End ]--------------------------------*/
/****************************************************************************************************
*
* MODULE: bldczcCmtInit ( bldczc_sStateCmt *pStateCmt,
* UWord16 Start_Step_Cmt,
* bldczc_eDirection Direction )
*
* DESCRIPTION: function bldczcCmtInit initializes the data structures
* for bldczcCmt() algorithm to Start_Step_Cmt and Direction.
*
* RETURNS: The function returns the PASS (0)
*
* ARGUMENTS: The function has three argument: in/out - pointer to bldczc_sStateCmt structure that
* contains the status variables for
* BLDC motor BEMF Zero Crossing
* Commutation algorithm
* in - Start_Step_Cmt - 16bit range Starting Step value
* in - Direction - BLDCZC_ACB/BLDCZC_ABC
* required commutation direction
*
* RANGE ISSUES: NONE.
*
* SPECIAL ISSUES: NONE.
*
****************************************************************************************************/
/*--------------------[ bldczcCmtInit - Begin ]----------------------------*/
Result bldczcCmtInit ( bldczc_sStateCmt *pStateCmt,
UWo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -