📄 bldc_zc_8013.c
字号:
*
* Description : Setting of constants and coeficients from bldcadczcdefines.h
* file for MotorB (Low Voltage Motor Pittman 2311)
*
* Returns : None
*
* Global Data : mudtStartComputInit - parameters for computation commutation
* at "Starting" stage
* mudtRunComputInit - parameters for computation commutation
* at "Running" stage
* mwwMaxZCrosErr - maximal commutation Zero Crossing errors
* mwwMinZCrosOKStart - minimal commutations with OK Zero Crossing at start
* muwwAlignmentStepCmtABC - Alignment step index for abc rotation direction
* muwwAlignmentStepCmtACB - Alignment step index for acb rotation direction
* muwwAlignmentStepCmt - Alignment step index set to muwwAlignmentStepCmtABC
* muwwConstPerProcCmt - minimal periode of commutation proceeeding
* mfwCurrAlignDesired - desired alignment current
* mfwOmegaMinSysu - minimal angular speed
* muwwPerAlignmentSys - time interval of "Alignment" stage
* mwwPerCmtMin - minimal commutation periode
* mfwMaxSpeed - maximal speed
* mudtSpeedParamsPI - speed PI regulator parameters
* mudtCurAlignParamsPI - alignment alignment current regulator parameters
* mudtCurLimitParamsPI - alignment current limiting regulator parameters
*
* Arguments : None
*
* Range Issues : None
*
*******************************************************************************/
void MotorBSettings(void)
{
mudtStartComputInit = mudtMOTORB_START_COMPUT_INIT;
mudtRunComputInit = mudtMOTORB_RUN_COMPUT_INIT;
muwwPerAlignmentSys = MOTORB_PER_ALIGNMENT_SYS;
mfwCurrAlignDesired = ((long) MOTORB_CURR_ALIGN_DESIRED_sub * 100UL) / (long) mfwMaxCurrent;
mfwOmegaMinSysu = MOTORB_OMEGA_MIN_SYSU;
mfwMaxSpeed = MOTORB_SPEED_ROTOR_MAX_RPM;
mwwPerCmtMin = MOTORB_PER_CMT_MIN;
mwwMaxZCrosErr = MOTORB_MAX_ZCROSERR;
mwwMinZCrosOKStart = MOTORB_MIN_ZCROSOK_START;
muwwConstPerProcCmt = MOTORB_PER_START_PROCCMT;
mfwPwmtoADCSamplingTime = mult_r(MOTORB_PWM_to_ADC_COEF, C_PWM_A_reg_PWM_PWMCM);
/* muwwAlignmentStepCmt = EVM_ALIGNMENT_STEP_CMT; */
muwwAlignmentStepCmtABC = MOTORB_ALIGNMENT_STEP_CMT_ABC;
muwwAlignmentStepCmtACB = MOTORB_ALIGNMENT_STEP_CMT_ACB;
muwwAlignmentStepCmt = muwwAlignmentStepCmtABC;
mfwIDCBusDesiredLimit = ((long) MOTORB_CURR_LIMIT_DESIRED_sub * 100UL) / (long) mfwMaxCurrent;
/* PI Speed Controller setings */
mudtSpeedParamsPI.ProportionalGain = MOTORB_SPEED_PI_PROPORTIONAL_GAIN;
mudtSpeedParamsPI.ProportionalGainScale = MOTORB_SPEED_PI_PROPORTIONAL_GAIN_SCALE;
mudtSpeedParamsPI.IntegralGain = MOTORB_SPEED_PI_INTEGRAL_GAIN;
mudtSpeedParamsPI.IntegralGainScale = MOTORB_SPEED_PI_INTEGRAL_GAIN_SCALE;
mudtSpeedParamsPI.PositivePILimit = VOLTAGE_UP_LIMIT_SYSU;
mudtSpeedParamsPI.NegativePILimit = VOLTAGE_DOWN_LIMIT_SYSU;
mudtSpeedParamsPI.IntegralPortionK_1 = 0;
/* PI Alignment Current Controller setings */
mudtCurAlignParamsPI.ProportionalGain = MOTORB_CURR_PI_PROPORTIONAL_GAIN;
mudtCurAlignParamsPI.ProportionalGainScale = MOTORB_CURR_PI_PROPORTIONAL_GAIN_SCALE;
mudtCurAlignParamsPI.IntegralGain = MOTORB_CURR_PI_INTEGRAL_GAIN;
mudtCurAlignParamsPI.IntegralGainScale = MOTORB_CURR_PI_INTEGRAL_GAIN_SCALE;
mudtCurAlignParamsPI.PositivePILimit = VOLTAGE_UP_LIMIT_SYSU;
mudtCurAlignParamsPI.NegativePILimit = VOLTAGE_DOWN_LIMIT_SYSU;
mudtCurAlignParamsPI.IntegralPortionK_1 = 0;
/* PI Limit Current Controller setings */
mudtCurLimitParamsPI.ProportionalGain = MOTORB_CURRLIMIT_PI_PROPORTIONAL_GAIN;
mudtCurLimitParamsPI.ProportionalGainScale = MOTORB_CURRLIMIT_PI_PROPORTIONAL_GAIN_SCALE;
mudtCurLimitParamsPI.IntegralGain = MOTORB_CURRLIMIT_PI_INTEGRAL_GAIN;
mudtCurLimitParamsPI.IntegralGainScale = MOTORB_CURRLIMIT_PI_INTEGRAL_GAIN_SCALE;
mudtCurLimitParamsPI.PositivePILimit = 32767;
mudtCurLimitParamsPI.NegativePILimit = 0;
mudtCurLimitParamsPI.IntegralPortionK_1 = 0;
}
/*******************************************************************************
*
* Module : CheckRunStopSwitch()
*
* Description : The function provides:
* - Reading of actual position of RUN / STOP switch from GPIO
* - Setting of mApplicationMode according the state of the switch
*
* Returns : None
*
* Global Data : mApplicationMode - State of application state machine
* mSwitchState - Previous state of switch
*
* Arguments : None
*
* Range Issues : None
*
*******************************************************************************/
static void CheckRunStopSwitch(void)
{
/* Run / Stop switch read */
if (ioctl(GPIO_B, GPIO_READ_DATA, NULL) & BIT_3)
{
mSwitchState = RUN;
if (mApplicationMode != FAULT) mApplicationMode = RUN;
}
else
{
if (mSwitchState == RUN) muwwDriveFaultStatus = NO_FAULT;
mSwitchState = STOP;
mApplicationMode = STOP;
}
}
/*******************************************************************************
*
* Module : CheckUpDownSwitches()
*
* Description : The function reads the status of UP / DOWN pushbuttons over GPIO
* and according this status, it increases or decreases
* requested mechanical speed
*
* Returns : None
*
* Global Data : muwwButtonReadPrescaler - Prescaler for button read
* mfwOmegaRequestedMech - Requested speed from user by pushbuttons
* mfwOmegaMinSysu - Minimum speed in fractional
* mSwitchState - Run / Stop switch state
*
* Arguments : None
*
* Range Issues : None
*
*******************************************************************************/
void CheckUpDownSwitches(void)
{
Int16 Temp;
if (muwwButtonReadPrescaler == 0)
{
muwwButtonReadPrescaler = BUTTON_READ_PRESCALER_SCAN;
if (mSwitchState == RUN)
{
if (!(ioctl(GPIO_B, GPIO_READ_DATA, NULL) & BIT_0))
{
Temp = mfwOmegaRequestedMech;
if (Temp == 0) Temp = mfwOmegaMinSysu;
else Temp += OMEGA_INCREMENT_SYSU;
if ((Temp >= OMEGA_UP_LIMIT_SYSU) || (Temp < mfwOmegaRequestedMech))
{
Temp = OMEGA_UP_LIMIT_SYSU;
}
mfwOmegaRequestedMech = Temp;
muwwButtonReadPrescaler = BUTTON_READ_PRESCALER_DEBOUNCE;
}
if (!(ioctl(GPIO_B, GPIO_READ_DATA, NULL) & BIT_1))
{
Temp = mfwOmegaRequestedMech;
if (Temp == 0) Temp = -mfwOmegaMinSysu;
else Temp -= OMEGA_INCREMENT_SYSU;
if ((Temp <= OMEGA_DOWN_LIMIT_SYSU) || (Temp > mfwOmegaRequestedMech))
{
Temp = OMEGA_DOWN_LIMIT_SYSU;
}
mfwOmegaRequestedMech = Temp;
muwwButtonReadPrescaler = BUTTON_READ_PRESCALER_DEBOUNCE;
}
}
}
}
/*******************************************************************************
*
* Module : CommutationControlInit()
*
* Description : The function initializes sensorless BLDC motor commuttaion controller.
*
* Returns : None
*
* Global Data : mStatusCommutation - Sets commutation status Stopped
* mudtBldcAlgoStates - Clears state structure for commutation algorithms BldcZC
* mudtBldcAlgoTimes - Clears times structure for commutation algorithms BldcZC
*
* Arguments : None
*
* Range Issues : None
*
*******************************************************************************/
static void CommutationControlInit(void)
{
mStatusCommutation = STOPPED;
mudtBldcAlgoStates.State_Comput.Cmd_Comput.ZC_ComputFlag = 0;
mudtBldcAlgoStates.State_Comput.Coef_CmtPrecompLShft = 0;
mudtBldcAlgoStates.State_Comput.Coef_CmtPrecompFrac = 0;
mudtBldcAlgoStates.State_Comput.Coef_HlfCmt = 0;
mudtBldcAlgoStates.State_Comput.Coef_Toff = 0;
mudtBldcAlgoStates.State_Comput.Const_PerProcCmt = 0;
mudtBldcAlgoStates.State_Comput.Max_PerCmt = 0;
mudtBldcAlgoStates.State_Cmt.Cmd_Cmt.CmtDone_CmtServ_RqFlag = 0;
mudtBldcAlgoStates.State_Cmt.Cmd_Cmt.Cmt_DrvRqFlag = 0;
mudtBldcAlgoStates.State_Cmt.Cmd_Cmt.DIRFlag;
mudtBldcAlgoStates.State_Cmt.Step_Cmt = 0;
mudtBldcAlgoStates.State_ZCros.Cmd_ZCros.ZCrosInt_EnblFlag = 0;
mudtBldcAlgoStates.State_ZCros.Cmd_ZCros.ZC_GetFlag = 0;
mudtBldcAlgoStates.State_ZCros.Cmd_ZCros.ZC_ToffFlag = 0;
mudtBldcAlgoStates.State_ZCros.Cmd_ZCros.ZCInpSet_DrvRqFlag = 0;
mudtBldcAlgoStates.State_ZCros.Cmd_ZCros.Expect_ZCInp_PositivFlag = 0;
mudtBldcAlgoStates.State_ZCros.Cntr_ZCrosOK = 0;
mudtBldcAlgoStates.State_ZCros.Min_ZCrosOKStart = 0;
mudtBldcAlgoStates.State_General.Cmd_General.Timer_DrvRqFlag = 0;
mudtBldcAlgoStates.State_General.Cmd_General.EndStart_HndlrCmdFlag = 0;
mudtBldcAlgoStates.State_General.Cmd_General.StartMode_HndlrFlag = 0;
mudtBldcAlgoStates.State_General.Cmd_General.Cmt_TimedFlag = 0;
mudtBldcAlgoStates.State_General.Cmd_General.ZCToff_TimedFlag = 0;
mudtBldcAlgoStates.State_General.Cmd_General.MaxZCErr_HndlrCmdFlag = 0;
mudtBldcAlgoTimes.T_Cmt0 = 0;
mudtBldcAlgoTimes.T_Next = 0;
mudtBldcAlgoTimes.T_ZCros = 0;
mudtBldcAlgoTimes.T_ZCros0 = 0;
mudtBldcAlgoTimes.Per_Toff = 0;
mudtBldcAlgoTimes.Per_CmtPreset = 0;
mudtBldcAlgoTimes.Per_ZCros = 0;
mudtBldcAlgoTimes.Per_ZCros0 = 0;
mudtBldcAlgoTimes.Per_ZCrosFlt = 0;
mudtBldcAlgoTimes.Per_HlfCmt = 0;
}
/*******************************************************************************
*
* Module : CommutationControl(void)
*
* Description : The function provides:
* Commutation control according to mudtCmdApplication.uintBldcRunRqFlag
* and mStatusCommutation variable
* if mudtCmdApplication.uintBldcRunRqFlag = 0
* 1. commutation is stopped
* 2. commutation status mStatusCommutation is set to Stopped
* 3. actual commutation direction is set to requested
* 4. alignment step index is set to actual commutation direction
*
* if mudtCmdApplication.uintBldcRunRqFlag
* commutation is running according to mStatusCommutation
*
* mStatusCommutation = RUNNING
* 1.Commutation running proces is provided
*
* mStatusCommutation = STARTING
* if uintEndStartModeHndlrCmdFlag
* 1. Commutation "RUNNING" stage setting is provided
* 2. mStatusCommutation set to RUNNING
* 3. uintRunningStartCmdFlag (can be used mApplicationStateMachine
* to stert speed controlled)
* 4.Commutation running proces (with starting parameters)
* is provided
*
* mStatusCommutation = ALIGNMENT
* 1.if end of alignment interval calibration request is set
* 2.if calibration of phase voltage offset is done
* Commutation "STARTING" stage setting is provided
*
* mStatusCommutation = STOPPED
* 1. Commutation "ALIGNMENT" stage setting is provided
* for alignment step index
*
* Returns : None
*
* Global Data : mudtCmdApplication - Application flags
* mApplicationMode - Application status
Run / Stop / Fault
* mStatusCommutation - Commutation status of drive
Stopped / Alignment / Starting / Running
* mudtBldcAlgoStates - state structure for commutation algorithms BldcZC
* mudtBldcAlgoTimes - times structure for commutation algorithms BldcZC
* muwwAlignmentStepCmtABC - Commutation Step for Alignment abc direction
* muww
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -