📄 bldczc.c
字号:
};
return (PASS);
}
/*--------------------[ bldczcHndlrInit - End ]----------------------------*/
/****************************************************************************************************
*
* MODULE: bldczcHndlrStop ( bldczc_sStates *pStates )
*
* DESCRIPTION: function bldczcHndlrStop() sets data structures for the command
* interface bldczcHndlr() to stop commutations .
* Refer to SDK documentation for detailes.
*
* RETURNS: The function returns the PASS (0)
*
* ARGUMENTS: The function has three arguments: out - pointer to bldczc_sStates structure that
* contains the status variables for all
* BLDC motor BEMF Zero Crossing algorithms
*
* RANGE ISSUES: NONE
*
* SPECIAL ISSUES: NONE
*
****************************************************************************************************/
/*--------------------[ bldczcHndlrStop - Begin ]--------------------------*/
Result bldczcHndlrStop ( bldczc_sStates *pStates )
{
pStates->State_General.Cmd_General.W16 = 0;
pStates->State_Comput.Cmd_Comput.W16 = 0;
pStates->State_Cmt.Cmd_Cmt.W16 = 0;
pStates->State_ZCros.Cmd_ZCros.W32 = 0;
return (PASS);
}
/*--------------------[ bldczcHndlrStop - End ]----------------------------*/
/****************************************************************************************************
*
* MODULE: bldczcComput ( bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes )
*
* DESCRIPTION: function bldczcComput computs the time intervals for
* BLDC motor BEMF Zero Crossing commutation control
* From:
* - T_Cmt0 - commutation time
* - T_ZCros - zero crossing time
* - T_ZCros0 - previous zero crossing time
* The following time periods are computed acording to status
* of bldczc_sStateComput structure:
* - Per_CmtPreset - commutation preset period
* - Per_ZCros - time period between BEMF Zero Crossings
* - Per_ZCros0 - previous time period between BEMF Zero Crossings
* - Per_ZCrosFlt - filtered time period between BEMF Zero Crossings
* (average from Per_ZCros and Per_ZCros0 time periods)
* - Per_HlfCmt - time period from BEMF Zero Crossing to required commutation
* - Per_Toff - time period after commuttaion, where BEMF Zero Crossing is not sensed
* Refer to SDK documentation for detailes.
*
* RETURNS: The function returns the PASS (0)
*
* SUBMODULES USED: PresetCalculation (bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes)
* SetCalculation (bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes)
*
* ARGUMENTS: The function has two arguments: in/out - pointer to bldczc_sStateComput structure that
* contains the status variables for
* BLDC motor BEMF Zero Crossing
* Computation algorithms
* in/out - pointer to bldczc_sTimes structure that
* contains the time variables for all
* BLDC motor BEMF Zero Crossing algorithms
*
*
* 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 saturaion mode is set or not .
*
****************************************************************************************************/
/* Computing Commutation Time
* function does one of following actions
* - if Commutation done Comput Rq
* { if (Zero Cross get Computed = 0)
* { T_ZCros = T_Cmt0
* SetCalculation();
* }
* PresetCalculation
* CmtDone_Comput_RqFlag = 0
* }
*
* - if Commutation done Comput Rq = 0
* { if ZCOKGet_Comput_RqFlag = 1
* {SetCalculation
* CmtComp_CmdFlag = 1}
* else if (ZCMiss_Comput_RqFlag)
* { T_ZCros = T_Cmt0 + Per_Toff
* SetCalculation
* CmtComp_CmdFlag = 1;
* ZCMiss_Comput_RqFlag = 0;
* }
* }
*-------------------------------------------------------------------------*/
/*--------------------[ bldczcComput - Begin ]-----------------------------*/
Result bldczcComput ( bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes )
{
/* temporary registers - unions for 16bit MSB,LSB or 32 bit acces */
uReg32 Temp1F32;
uReg32 Temp2F32;
/* Removed UWord16 TempOMR; */
if (pState_Comput->Cmd_Comput.B.CmtDone_Comput_RqFlag)
{
if (!pState_Comput->Cmd_Comput.B.ZC_ComputFlag)
{
/* -------------------[ noZCCalculation - Begin ]--------------------------*/
pTimes->T_ZCros = pTimes->T_Cmt0;
SetCalculation (pState_Comput, pTimes);
/* -------------------[ noZCCalculation - End ]----------------------------*/
};
/*-----------------------------------------------------------------------75*/
PresetCalculation (pState_Comput, pTimes);
pState_Comput->Cmd_Comput.B.CmtDone_Comput_RqFlag = 0;
}
else /* pCmd_Comput->B.CmtDone_Comput_RqFlag = 0 */
{
if ( pState_Comput->Cmd_Comput.B.ZCOKGet_Comput_RqFlag)
{
/* -------------------[ ZCOKGetCalculation - Begin ]-----------------------*/
SetCalculation (pState_Comput, pTimes);
pState_Comput->Cmd_Comput.B.CmtComp_CmdFlag = 1;
/* -------------------[ ZCOKGetCalculation - End ]-------------------------*/
pState_Comput->Cmd_Comput.B.ZCOKGet_Comput_RqFlag = 0;
pState_Comput->Cmd_Comput.B.ZCMiss_Comput_RqFlag = 0;
}
else
{
if (pState_Comput->Cmd_Comput.B.ZCMiss_Comput_RqFlag)
{
/* -------------------[ soonZCCalculation - Begin ]------------------------*/
/* pTimes->T_ZCros = pTimes->T_Cmt0 + pTimes->Per_Toff,
16 bits rest, no saturation
- loose MSB part - for timer capture register UWord16!!! */
Temp1F32.RegParts.MSBpart = 0;
Temp1F32.RegParts.LSBpart = pTimes->T_Cmt0;
Temp2F32.RegParts.MSBpart = 0;
Temp2F32.RegParts.LSBpart = pTimes->Per_Toff;
Temp2F32.Reg32bit = L_add( Temp1F32.Reg32bit, Temp2F32.Reg32bit );
pTimes->T_ZCros = Temp2F32.RegParts.LSBpart;
/* asm(move OMR,TempOMR); */ /* store OMR status */
/* archSetNoSat(); */ /* switch saturation off */
/* pTimes->T_ZCros = pTimes->T_Cmt0 + pTimes->Per_Toff; */
/* asm(move TempOMR,OMR); */ /* restore OMR status */
SetCalculation (pState_Comput, pTimes);
pState_Comput->Cmd_Comput.B.CmtComp_CmdFlag = 1;
/* -------------------[ soonZCCalculation - End ]--------------------------*/
pState_Comput->Cmd_Comput.B.ZCMiss_Comput_RqFlag = 0;
pState_Comput->Cmd_Comput.B.ZCOKGet_Comput_RqFlag = 0;
};
}
}
return (PASS);
}
/*--------------------[ bldczcComput - End ]-------------------------------*/
/*--------------------[ PresetCalculation - Begin ]------------------------
Presetting of next Commutation Time
* Per_CmtPreset = Coef_CmtPrecomp*Per_ZCrosFlt
* (usually coefficient Coef_CmtPrecomp = 2)
* if Coef_CmtPrecomp*Per_ZCrosFlt>Max_PerCmt
* then result is limited at Max_PerCmt
* pCmd_Comput->B.ZC_ComputFlag = 0;
* pCmd_Comput->B.CmtPreComp_CmdFlag = 1;
* ------------------------------------------------------------------------*/
inline static Result PresetCalculation (bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes)
{
/* temporary registers - unions for 16bit MSB,LSB or 32 bit acces */
uReg32 Per_ZCrosFltF32;
uReg32 Per_CmtPresetF32;
/* if ( pState_Comput->Coef_CmtPrecomp * pTimes->Per_ZCrosFlt <= pState_Comput->Max_PerCmt )
Coef_CmtPrecomp has 2 parts Coef_CmtPrecompFrac and Coef_CmtPrecompLShft */
Per_ZCrosFltF32.RegParts.MSBpart = 0;
Per_ZCrosFltF32.RegParts.LSBpart = pTimes->Per_ZCrosFlt;
Per_CmtPresetF32.Reg32bit = L_mult_ls ( Per_ZCrosFltF32.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;
};
pState_Comput->Cmd_Comput.B.ZC_ComputFlag = 0;
pState_Comput->Cmd_Comput.B.CmtPreComp_CmdFlag = 1;
return (PASS);
}
/*--------------------[ PresetCalculation - End ]--------------------------*/
/*--------------------[ SetCalculation - Begin ]---------------------------
Setting of next Commutation Time
* Per_ZCros = T_ZCros - T_ZCros0
* Per_ZCrosFlt = (1/2*Per_ZCros+1/2*Per_ZCros0)
* Per_HlfCmt = Per_ZCrosFlt * Coef_HlfCmt
* (usually coeficient Coef_HlfCmt = 1/4)
* Per_Toff = Per_ZCrosFlt*Coef_Toff and Const_PerProcCmt minimum
* (usually coeficient Coef_Toff = 1/4)
* Per_ZCros0 = Per_ZCros
* T_ZCros0 = T_ZCros
* pCmd_Comput->B.ZC_ComputFlag = 1;
* pCmd_Comput->B.ToffComp_CmdFlag = 1;
* ------------------------------------------------------------------------*/
inline static Result SetCalculation (bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes)
{
/* temporary registers - unions for 16bit MSB,LSB or 32 bit acces */
uReg32 Temp1F32;
uReg32 Temp2F32;
uReg32 Temp3F32;
/* Removed UWord16 TempOMR; */
/* Removed asm(move OMR,TempOMR); */ /* store OMR status */
/* Removed archSetNoSat(); */ /* switch saturation off */
/* Removed pTimes->Per_ZCros = pTimes->T_ZCros - pTimes->T_ZCros0; */
/* Removed asm(move TempOMR,OMR); */ /* restore OMR status */
/* pTimes->Per_ZCros = pTimes->T_ZCros - pTimes->T_ZCros0,
16 bits rest, no saturation */
Temp1F32.RegParts.MSBpart = 0;
Temp1F32.RegParts.LSBpart = pTimes->T_ZCros;
Temp2F32.RegParts.MSBpart = 0;
Temp2F32.RegParts.LSBpart = pTimes->T_ZCros0;
Temp2F32.Reg32bit = L_sub( Temp1F32.Reg32bit, Temp2F32.Reg32bit );
pTimes->Per_ZCros = Temp2F32.RegParts.LSBpart;
/* 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);
/* pTimes->Per_HlfCmt = pTimes->Per_ZCrosFlt * pState_Comput->Coef_HlfCmt
* fractional multiply! */
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -