⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bldczc.c

📁 菲斯卡尔无传感器无刷控制方案。具体说明文档和程序都在压缩包内。
💻 C
📖 第 1 页 / 共 3 页
字号:
* ARGUMENTS     : in/out - pointer to bldczc_sStates structure that contains the status
*                          variables for all BLDC motor BEMF Zero Crossing algorithms
*                 in/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     - Start_PerProcCmt - 16bit range Starting commutation
*                          proceeding Periode
*                 in     - Starting_Mode - enum BLDCZC_SET_DEFAULT, BLDCZC_DO_NOT_EFFECT
*                                               
* 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 .
*
****************************************************************************************************/
/*--------------------[ bldczcHndlrInit - Begin ]--------------------------*/
Result bldczcHndlrInit ( bldczc_sStates *pStates,
                         bldczc_sTimes *pTimes,
                         UWord16 T_Actual,
                         UWord16 Start_PerProcCmt,
                         bldczc_eStartingMode Starting_Mode )
{
    if (Starting_Mode == BLDCZC_STARTING_M)
    {
        pStates->State_General.Cmd_General.StartMode_HndlrFlag = 1;

        /* Init Zero Crossing Computed Flag 
           Prepare flags noZCCalculation before PresetCalculation */
        /* Warning: this flag may be set by bldczcComputInit if 
           pComputInit->Mode_TimesInit == BLDCZC_SET_DEFAULT*/
        pStates->State_Comput.Cmd_Comput.ZC_ComputFlag = 0;  

        /* Disable Event Timer update in next possible oppourtunity */
        pStates->State_General.Cmd_General.Timer_DrvRqFlag = 0;

        /* Init End Start Mode Flag */
        pStates->State_General.Cmd_General.EndStart_HndlrCmdFlag = 0;

        /* Init Zero Crossing Errors >= maximal Command Flag */
        pStates->State_General.Cmd_General.MaxZCErr_HndlrCmdFlag = 0;

        /*  Init Zero Crossing Time off Timed Flag */  
        pStates->State_General.Cmd_General.ZCToff_TimedFlag = 0;

        /* Init Zero Crossing Interrupt enable Flag*/ 
        pStates->State_ZCros.Cmd_ZCros.ZCrosInt_EnblFlag = 0;

        /* Init Set ZC Input Driver Request Flag */  
        pStates->State_ZCros.Cmd_ZCros.ZCInpSet_DrvRqFlag = 0; 

        /* ?Init Zero crossing Get Flag */
        pStates->State_ZCros.Cmd_ZCros.ZC_GetFlag = 0;
     
        /* ?Init Zero Crossin Toff flag*/
        pStates->State_ZCros.Cmd_ZCros.ZC_ToffFlag = 1;
     
		pStates->State_General.Cmd_General.Cmt_TimedFlag = 0;
     
        /* T_Cmt0 must be set before PrepareProcTiming function */
        pTimes->T_Cmt0 = T_Actual;

        /* Proc timing is prepared according to xxx_CONST_PERPROCCMT constant in bldcadczcdefines.h */
        PrepareToffTiming (&pStates->State_General.Cmd_General, &pTimes->T_Next, pTimes->T_Cmt0, Start_PerProcCmt);
	
        /* ?Commutation Driver Request Flag*/
        pStates->State_Cmt.Cmd_Cmt.Cmt_DrvRqFlag = 1;
 
    }
    else
    {
        pStates->State_General.Cmd_General.StartMode_HndlrFlag = 0;
    };
	
	return (PASS);
}
/*--------------------[ bldczcHndlrInit - End ]----------------------------*/

/****************************************************************************************************
*
* MODULE        : bldczcHndlrStop ( bldczc_sStates *pStates )
*
* DESCRIPTION   : Function bldczcHndlrStop() sets data structures for the command interface
*                 bldczcHndlr() to stop commutations.
*
* RETURNS       : The function returns the PASS (0)
*
* 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 )
{
	/* Clear all bit definitions in States variables */
    pStates->State_General.Cmd_General.Timer_DrvRqFlag          = 0;
    pStates->State_General.Cmd_General.EndStart_HndlrCmdFlag    = 0;
    pStates->State_General.Cmd_General.StartMode_HndlrFlag      = 0;
    pStates->State_General.Cmd_General.Cmt_TimedFlag            = 0;
    pStates->State_General.Cmd_General.ZCToff_TimedFlag         = 0;
    pStates->State_General.Cmd_General.MaxZCErr_HndlrCmdFlag    = 0; 

	pStates->State_Comput.Cmd_Comput.ZC_ComputFlag              = 0;

    pStates->State_Cmt.Cmd_Cmt.CmtDone_CmtServ_RqFlag           = 0;
    pStates->State_Cmt.Cmd_Cmt.Cmt_DrvRqFlag                    = 0;
    pStates->State_Cmt.Cmd_Cmt.DIRFlag                          = 0;

    pStates->State_ZCros.Cmd_ZCros.ZCrosInt_EnblFlag            = 0;
    pStates->State_ZCros.Cmd_ZCros.ZC_GetFlag                   = 0;
    pStates->State_ZCros.Cmd_ZCros.ZC_ToffFlag                  = 0;
    pStates->State_ZCros.Cmd_ZCros.ZCInpSet_DrvRqFlag           = 0;
    pStates->State_ZCros.Cmd_ZCros.Expect_ZCInp_PositivFlag     = 0;

	return (PASS);
}
/*--------------------[ bldczcHndlrStop - 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;
  * ------------------------------------------------------------------------*/
inline static Result PresetCalculation (bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes)
{
Frac32 Per_ZCrosFlt32, Per_CmtPreset32;
 
    Per_CmtPreset32 = L_mult_ls ( (Word32) pTimes->Per_ZCrosFlt, (Word32) pState_Comput->Coef_CmtPrecompFrac);
	
    Per_CmtPreset32 = Per_CmtPreset32 << pState_Comput->Coef_CmtPrecompLShft;
	
	if ( Per_CmtPreset32 <= pState_Comput->Max_PerCmt )
	{
		pTimes->Per_CmtPreset = (Frac16) Per_CmtPreset32;
	}
	else
	{
		pTimes->Per_CmtPreset = pState_Comput->Max_PerCmt;
	}

	pState_Comput->Cmd_Comput.ZC_ComputFlag = 0;
    
	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; */
inline static Result SetCalculation (bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes)
{
Frac32 Temp;

	/* Mainly, this function calculates the following quantities :
	   - pTimer->PerZCros = pTimes->T_ZCros - pTimes->T_ZCros0
	   - pTimes->Per_ZCrosFlt = pTimes->Per_ZCros / 2 +  pTimes->Per_ZCros0 / 2;
	   - pTimes->Per_Toff = min(pTimes->Per_ZCrosFlt * Coef_Toff, pState_Comput->Const_PerProcCmt)
	*/
	
	/* First, calculate ZeroCross Period, from old ZeroCross and new ZeroCross instants */
	/* pTimes->Per_ZCros = pTimes->T_ZCros - pTimes->T_ZCros0 */
    pTimes->Per_ZCros = L_sub ( (Word32) pTimes->T_ZCros, (Word32) pTimes->T_ZCros0);
    
	/* Calculate a ZeroCross filtered, from old and new ZeroCross periods */
	pTimes->Per_ZCrosFlt = (pTimes->Per_ZCros/2 +  pTimes->Per_ZCros0/2);
 
	/* Calculate the Half of Commutation Period */
	/* pTimes->Per_HlfCmt = pTimes->Per_ZCrosFlt * pState_Comput->Coef_HlfCmt, fractional multiply! */
    pTimes->Per_HlfCmt = L_mult_ls ( (Word32) pTimes->Per_ZCrosFlt, (Word32) pState_Comput->Coef_HlfCmt);
    
	/* Calculate and limit Toff period */
	/* Toff period can not be smaller than Const_PerProcCmt */
	/* if ( (pTimes->Per_ZCrosFlt / pState_Comput->Coef_Toff) > pState_Comput->Const_PerProcCmt ) */
    Temp = L_mult_ls ( (Word32) pTimes->Per_ZCrosFlt, (Word32) pState_Comput->Coef_Toff);

	if ( ((UWord32) Temp) > pState_Comput->Const_PerProcCmt)
	{
		pTimes->Per_Toff = Temp;
	}
	else
	{
		pTimes->Per_Toff = pState_Comput->Const_PerProcCmt;     
	}
	
	/* Copy last ZeroCross time and period to old ZeroCross time and period variable */
	/* Possibly pTimes->Per_ZCros_m1 = pTimes->Per_ZCros0; */
	pTimes->Per_ZCros0 = pTimes->Per_ZCros;
	pTimes->T_ZCros0 = pTimes->T_ZCros;
 
	pState_Comput->Cmd_Comput.ZC_ComputFlag = 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
*
* RETURNS       : The function returns the PASS (0)      
*
* 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 constants
*                       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 )
{
Frac32 Per_CmtPreset32;
 
	/* Init Maximal Period of Commutation Proceeding time of motor coil reverse current
	   pState_Comput->Const_PerProcCmt is written here as constant, which will be used
	   for CmtProc in the future */
	pState_Comput->Const_PerProcCmt = pComputInit->Const_PerProcCmt;   

	/* Init Maximal Commutation Period */	
	pState_Comput->Max_PerCmt = pComputInit->Max_PerCmt;

	/* BLDCZC_SET_DEFAULT/BLDCZC_DO_NOT_EFFECT Coef variables */
	if ( pComputInit->Mode_CoefInit == BLDCZC_SET_DEFAULT )        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -