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

📄 bldczc.c

📁 菲斯卡尔无传感器无刷控制方案。具体说明文档和程序都在压缩包内。
💻 C
📖 第 1 页 / 共 3 页
字号:
    {
		/* Init Commutation time precomputation Coeficient */
		pState_Comput->Coef_CmtPrecompLShft = pComputInit->Coef_CmtPrecompLShft;  
                                                         
		/* Init Commutation time precomputation Coeficient */
		pState_Comput->Coef_CmtPrecompFrac = pComputInit->Coef_CmtPrecompFrac;  

		/* Init Half commutation Coeficient */
		pState_Comput->Coef_HlfCmt = pComputInit->Coef_HlfCmt;

		/* Init Zero Crossing Toff Coeficient */
		pState_Comput->Coef_Toff = pComputInit->Coef_Toff;
	}

	if (pComputInit->Mode_StateComputInit == BLDCZC_SET_DEFAULT)
	{     
		/* Init Zero Crossing Computed Flag
		   Prepare flags noZCCalculation before PresetCalculation */
		/* Warning: this flag will be set below if 
		   pComputInit->Mode_TimesInit == BLDCZC_SET_DEFAULT*/
		pState_Comput->Cmd_Comput.ZC_ComputFlag = 0;
	}
    
	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;
		pTimes->Per_ZCrosFlt = (pTimes->Per_ZCros/2 + pTimes->Per_ZCros0/2);
        pTimes->Per_HlfCmt = L_mult_ls ( (Word32) pTimes->Per_ZCrosFlt, (Word32) pState_Comput->Coef_HlfCmt);
		pTimes->Per_Toff = pComputInit->Per_ToffStart;

		/* Zero Crossing Computed Flag 
		   Prepare flags for PresetCalculation without noZCCalculation */
		pState_Comput->Cmd_Comput.ZC_ComputFlag = 1;
                                          
		/* Possibly pTimes->Per_ZCros_m1 = pTimes->Per_ZCros0; */
		pTimes->Per_ZCros0 = pTimes->Per_ZCros;
		pTimes->T_ZCros0 = pTimes->T_ZCros;

        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;
		};

	};

	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
*
* RETURNS       : The function returns the PASS (0)
*
* ARGUMENTS     : 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 variable should be inside <MIN_STEP_CMT, MAX_STEP_CMT>
                  interval
*
* SPECIAL ISSUES: NONE.
*
****************************************************************************************************/
Result bldczcCmtServ ( bldczc_sStateCmt *pStateCmt )
{
	if ( pStateCmt->Cmd_Cmt.CmtDone_CmtServ_RqFlag)
	{
		if ( !pStateCmt->Cmd_Cmt.DIRFlag )
		{
			if (pStateCmt->Step_Cmt < MAX_STEP_CMT) pStateCmt->Step_Cmt++ ;
			else pStateCmt->Step_Cmt = MIN_STEP_CMT;
		}
		else
		{
			if ( pStateCmt->Step_Cmt  != MIN_STEP_CMT ) pStateCmt->Step_Cmt-- ;
			else pStateCmt->Step_Cmt = MAX_STEP_CMT;
		}
	
		pStateCmt->Cmd_Cmt.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     : 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,
                       UWord16 Start_Step_Cmt,
                       bldczc_eDirection Direction )
{ 
	if ( Direction == BLDCZC_ABC )
	{
		pStateCmt->Cmd_Cmt.DIRFlag = 1;                      /* Init  motor direction Flag */
	}
	else
	{
		pStateCmt->Cmd_Cmt.DIRFlag = 0;                      /* Init  motor direction Flag */
	}

	pStateCmt->Step_Cmt = Start_Step_Cmt;

	return (PASS);
}
/*--------------------[ bldczcCmtInit - End ]------------------------------*/

/****************************************************************************************************
*
* MODULE        : bldczcZCrosEdgeIntAlg (bldczc_sStateZCros *pState_ZCros,
*                                        UWord16 *T_ZCros,
*                                        UWord16 T_ZCSample,
*                                        Frac16 U_ZCPhaseX)
*
* DESCRIPTION   : Function bldczcZCrosEdgeIntAlg serves BEMF Zero Crossing sensing. It
*                 should be called when Zero Crossing edge appears (Zero Crossing Edge Interrupt)
*
* RETURNS       : The function returns the PASS (0)
*
* ARGUMENTS     : in/out - pointer to bldczc_sStateZCros structure that contains the
*                 status variables for BEMF Zero Crossing algorithms
*                 out    - pointer(reference) to BEMF Zero Crossing Time moment
*                          Zero Crossing time
*                 in     - T_ZCSample - 16bit range Time of detected Zero Crossing sample
*                 in     - U_ZCPhaseX - 16bit range - free phase for BEMF Zero Crossing signed 
*                          voltage for Zero Crossing recognition
*
* RANGE ISSUES  : NONE.
*
* SPECIAL ISSUES: NONE
*
****************************************************************************************************/
/* -------------------[ bldczcZCrosEdgeIntAlg - Begin ]------------------------*/
Result bldczcZCrosEdgeIntAlg (bldczc_sStates *pStates, bldczc_sTimes *pTimes, UWord16 T_ZCSample)
{
    /* Only if Zero Cross sense is enabled and no Zero Cross sensed in this period */
	if ( (!pStates->State_ZCros.Cmd_ZCros.ZC_ToffFlag) && (!pStates->State_ZCros.Cmd_ZCros.ZC_GetFlag) )
	{
        /* Copy last received time sample to T_ZCross (Variable of last Zero Crossing time) */
        pTimes->T_ZCros = T_ZCSample;

        /* Mark that the ZeroCrossing is sensed */
        pStates->State_ZCros.Cmd_ZCros.ZC_GetFlag = 1;

        /* Because correct ZC sample is received, increase Cntr_ZCrosOK by 1. */
        pStates->State_ZCros.Cntr_ZCrosOK++;

        /* Because correct ZC sample is received, reset Cntr_ZCrosErr variable to its maximum value */
        pStates->State_ZCros.Cntr_ZCrosErr = pStates->State_ZCros.Max_ZCrosErr;

        /* Disable ZCrosInt_EnblFlag, to disable another zero cross sensing */
        pStates->State_ZCros.Cmd_ZCros.ZCrosInt_EnblFlag = 0;

        /* Because Zero Cross is detected, calculate new time values, to be applied for next commutation */
        SetCalculation (&pStates->State_Comput, pTimes);          

        /* Calculate next commutation time from last zero cross time and half period calculated in SetCalculation */
        /* pTimes->T_Next = pTimes->T_ZCros + pTimes->Per_HlfCmt; */
        pTimes->T_Next = L_add ( (Word32) pTimes->T_ZCros, (Word32) pTimes->Per_HlfCmt);

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

        pStates->State_General.Cmd_General.Cmt_TimedFlag = 1;
    }

	return (PASS);
}
/* -------------------[ bldczcZCrosEdgeIntAlg-End ]----------------------------*/

/****************************************************************************************************
*
* MODULE        : bldczcZCrosInit ( bldczc_sStateZCros *pState_ZCros,
*                                   bldczc_sStateCmt *pStateCmt, 
*                                   Word16 Min_ZCrosOKStart_Ini, 
*                                   Word16 Max_ZCrosErr_Ini )
*
* DESCRIPTION   : Function bldczcZCrosInit initializes data structures for BEMF Zero 
*                 Crossing sensing for bldczcZCrosEdgeIntAlg() function.
*
* RETURNS       : The function returns the PASS (0)
*
* ARGUMENTS     : in/out - pointer to bldczc_sStateZCros structure that contains the
*                          status variables for BEMF Zero Crossing algorithms
*                 in/out - pointer to bldczc_sStateCmt structure that contains the
*                          status variables for BLDC motor commutation algorithm
*                 in     - Min_ZCrosOKStart_Ini - 16bit range - minimal number of
*                          correctly received BEMF Zero Crossings to set 
*                          pState_ZCros->Cmd_ZCros.B.EndStart_ZCrosServ_CmdFlag
*                          (command flag to leave starting stage and enter running stage)
*                 in     - Max_ZCrosErr_Ini - 16bit range - maximal number of wrong
*                          BEMF Zero Crossings to set
*                          pState_ZCros->Cmd_ZCros.B.MaxZCrosErr_ZCrosServ_CmdFlag
*                          (Error commutations command flag)
*
* RANGE ISSUES  : NONE.
*
* SPECIAL ISSUES: bldczcZCrosEdgeServ function is intended to cooperate with bldczcZCrosEdgeIntAlg
*                 function. bldczcZCrosEdgeServ should be called from main SW.
*                 When bldczcZCrosIntAlg should be called as an Interrupt Algorithm.
*
****************************************************************************************************/
/*--------------------[ bldczcZCrosInit - Begin ]--------------------------*/
Result bldczcZCrosInit ( bldczc_sStateZCros *pState_ZCros,
                         bldczc_sStateCmt *pStateCmt, 
                         Word16 Min_ZCrosOKStart_Ini, 
                         Word16 Max_ZCrosErr_Ini )
{ 
     pState_ZCros->Index_ZC_Phase = ZC_Phase_Tab [ pStateCmt->Step_Cmt ]; 
     pState_ZCros->Cmd_ZCros.Expect_ZCInp_PositivFlag = Expect_ZCInpFlag_Tab [ pStateCmt->Step_Cmt ] [ pStateCmt->Cmd_Cmt.DIRFlag ];      

     pState_ZCros->Cmd_ZCros.ZCInpSet_DrvRqFlag = 1;

     pState_ZCros->Cmd_ZCros.ZC_GetFlag = 0;
     pState_ZCros->Min_ZCrosOKStart = Min_ZCrosOKStart_Ini;
     pState_ZCros->Cntr_ZCrosOK = 0;
     pState_ZCros->Max_ZCrosErr = Max_ZCrosErr_Ini;
     pState_ZCros->Cntr_ZCrosErr = pState_ZCros->Max_ZCrosErr;

    return (PASS);
}
/*--------------------[ bldczcZCrosInit - End ]----------------------------*/

#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

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