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

📄 bldc_zc_8013.c

📁 菲斯卡尔无传感器无刷控制方案。具体说明文档和程序都在压缩包内。
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (mudtCmdApplication.uintSpeedCtrlEnblFlag)
    {
        if (--mwwSpeedPrescaler == 0)
        {
            mwwSpeedPrescaler = mwwPerSpeedSys;

            /* Calculate mechanical angular frequency by the help of commutation period */
            /* Where mfwOmegaActualMech = EVM_PER_CMT_MIN / mudtBldcAlgoTimes.Per_ZCrosFlt */
            if (mudtBldcAlgoTimes.Per_ZCrosFlt > MAX_16)    TempSpeedCalc = MAX_16;
            else                                            TempSpeedCalc = mudtBldcAlgoTimes.Per_ZCrosFlt;

            if (TempSpeedCalc < mwwPerCmtMin) TempSpeedCalc = mwwPerCmtMin;

            mfwOmegaActualMechSum += div_s(mwwPerCmtMin, TempSpeedCalc);
            mfwOmegaActualMech = mfwOmegaActualMechSum >> SPEED_FILT_INDEX;
            mfwOmegaActualMechSum -= mfwOmegaActualMech;
                        
            mfwOmegaRequiredMech = RampGetValue (mfwOmegaIncrementUp, mfwOmegaIncrementDown, \
                                                 &mfwOmegaRequiredMech, &mfwOmegaDesiredMech);
            
            if (mfwOmegaDesiredMech > mfwOmegaMinSysu)
            {
                if (mfwOmegaRequiredMech < mfwOmegaMinSysu)
                {
                    mfwOmegaRequiredMech = mfwOmegaMinSysu;
                }
            }

            /* Calculate PI controller for speed requlation */
	        miwUDesired = MC1_controllerPItype1_asmSc(mfwOmegaRequiredMech, mfwOmegaActualMech, &mudtSpeedParamsPI);

            miwUDesiredLimit = MC1_controllerPItype1_asmSc(mfwIDCBusDesiredLimit, mfwIDCBus, &mudtCurLimitParamsPI);
            
            if (miwUDesiredLimit < miwUDesired)
            {
                miwUDesired = miwUDesiredLimit;
                miwCurrentLimitingMarker++;
            }
            else
            {
                mudtCurLimitParamsPI.IntegralPortionK_1 = mudtSpeedParamsPI.IntegralPortionK_1;
                miwCurrentLimitingMarker--;                
            }
            
	        /* Calculate PWMReload to ADCStart time, according to DutyCycle */
	        uwwTimerOffset = mult_r(VOLTAGE_OFFSET_SYSU + miwUDesired, mfwPwmtoADCSamplingTime);

	        /* Update PWMReload to ADCSync timer compare value */
	        ioctl(QTIMER_3, QT_WRITE_LOAD_REG, uwwTimerOffset);
        }
    }

    if (mudtCmdApplication.uintAlignmentTimedFlag)
    {
        if (--muwwAlignmentTimer == 0)
        {
            /* Disable alignment timing */
            mudtCmdApplication.uintAlignmentTimedFlag = 0;

            /* Becasue alignment time is expired, request for end of alignment */
            mudtCmdApplication.uintEndAlignmentRqFlag = 1;
        }
        else
        {
            /* Control Alignment Current */
            miwUDesired = MC1_controllerPItype1_asmSc(mfwIDCBusDesiredAlign, mfwIDCBus, &mudtCurAlignParamsPI);

            miwUDesiredLimit = MC1_controllerPItype1_asmSc(mfwIDCBusDesiredLimit, mfwIDCBus, &mudtCurLimitParamsPI);
            miwCurrentLimitingMarker -= 1;
                        
            if (miwUDesiredLimit < miwUDesired)
            {
                miwUDesired = miwUDesiredLimit;
                miwCurrentLimitingMarker += 2;
            }
            
	        /* Calculate PWMReload to ADCStart time, according to DutyCycle */
	        uwwTimerOffset = mult_r(VOLTAGE_OFFSET_SYSU + miwUDesired, mfwPwmtoADCSamplingTime);

	        /* Update PWMReload to ADCSync timer compare value */
	        ioctl(QTIMER_3, QT_WRITE_LOAD_REG, uwwTimerOffset);
        }
    }

	ioctl(QTIMER_2, QT_CLEAR_FLAG, QT_COMPARE_FLAG);
}

/******************************************************************************* 
* 
* Module        : IsrQTRecorder()
* 
* Description   : Interrupt function used for periodic calling of FreeMaster recorder.
*
* Returns       : None
*
* Global Data   : None
*
* Arguments     : None
* 
* Range Issues  : None 
* 
/*******************************************************************************/
#pragma interrupt saveall
void IsrQTRecorder(void)
{
    /* Process FreeMaster recorder */
    PC_M1_pcmasterdrvRecorder();
    
	ioctl(QTIMER_1, QT_CLEAR_FLAG, QT_COMPARE_FLAG);
}

/******************************************************************************* 
* 
* Module        : IsrPWMReload()
* 
* Description   : Interrupt function for updating PWM module with calculated duty cycle.
*                 This interrupt is here becasue of future expansions.
*
* Returns       : None
*
* Global Data   : miwUDesired   - Calulated duty cycle value
*
* Arguments     : None
* 
* Range Issues  : None 
* 
/*******************************************************************************/
#pragma interrupt saveall
void IsrPWMReload(void)
{ 
    ioctl(PWM, PWM_UPDATE_VALUE_REG_0, miwUDesired + VOLTAGE_OFFSET_SYSU);

    ioctl(PWM, PWM_CLEAR_RELOAD_FLAG, NULL);
}

/******************************************************************************* 
* 
* Module        : EVM33395BoardSettings()
* 
* Description   : Setting of constants and coeficients from bldcadczcdefines.h
*                 file for EVM33395 Board
*
* Returns       : None
*
* Global Data   : mfwMaxVoltage           - Maximum measureable DC Bus Voltage
*                 mfwMaxCurrent           - Maximum measureable DC Bus Current
*                 mfwOmegaIncrementUp     - Increment step for ramp up
*                 mfwOmegaIncrementDown   - Decrement step for ramp down
*
* Arguments     : None
* 
* Range Issues  : None 
* 
/*******************************************************************************/
void EVM33395BoardSettings(void)
{
    ioctl(ADC, ADC_WRITE_OFFSET0, 0); 
    ioctl(ADC, ADC_WRITE_LOW_LIMIT0, FRAC16(EVM33395_DCB_UNDERVOLTAGE / EVM33395_APP_VOLT_MAX));
    ioctl(ADC, ADC_WRITE_HIGH_LIMIT0, FRAC16(EVM33395_DCB_OVERVOLTAGE / EVM33395_APP_VOLT_MAX));

    ioctl(ADC, ADC_WRITE_OFFSET1, CURR_DC_BUS_OFFSET_SYS); 
    ioctl(ADC, ADC_WRITE_LOW_LIMIT1, 0);
    ioctl(ADC, ADC_WRITE_HIGH_LIMIT1, CURR_DC_BUS_OFFSET_SYS + (EVM33395_DCB_OVERCURRENT * \
                                        CURR_DC_BUS_UP_LIMIT_SYS / EVM33395_APP_CURR_MAX));
                                        
    mfwMaxVoltage           = EVM33395_APP_VOLT_MAX;
    mfwMaxCurrent           = EVM33395_APP_CURR_MAX * 100;
    
    mfwOmegaIncrementUp     = RAMP_INCREMENT_UP;
    mfwOmegaIncrementDown   = RAMP_INCREMENT_DOWN;
}

/******************************************************************************* 
* 
* Module        : MPBoardSettings() 
* 
* Description   : Setting of constants and coeficients from bldcadczcdefines.h
*                 file for Micro Power Board
*
* Returns       : None
*
* Global Data   : mfwMaxVoltage           - Maximum measureable DC Bus Voltage
*                 mfwMaxCurrent           - Maximum measureable DC Bus Current
*                 mfwOmegaIncrementUp     - Increment step for ramp up
*                 mfwOmegaIncrementDown   - Decrement step for ramp down
*       
* Arguments     : None
* 
* Range Issues  : None 
* 
*******************************************************************************/
void MPBoardSettings(void)
{
    ioctl(ADC, ADC_WRITE_OFFSET0, 0); 
    ioctl(ADC, ADC_WRITE_LOW_LIMIT0, FRAC16(MP_DCB_UNDERVOLTAGE / MP_APP_VOLT_MAX));
    ioctl(ADC, ADC_WRITE_HIGH_LIMIT0, FRAC16(MP_DCB_OVERVOLTAGE / MP_APP_VOLT_MAX));

    ioctl(ADC, ADC_WRITE_OFFSET1, CURR_DC_BUS_OFFSET_SYS); 
    ioctl(ADC, ADC_WRITE_LOW_LIMIT1, 0);
    ioctl(ADC, ADC_WRITE_HIGH_LIMIT1, CURR_DC_BUS_OFFSET_SYS + (MP_DCB_OVERCURRENT * \
                                        CURR_DC_BUS_UP_LIMIT_SYS / MP_APP_CURR_MAX));
                                        
    mfwMaxVoltage           = MP_APP_VOLT_MAX;
    mfwMaxCurrent           = MP_APP_CURR_MAX * 100;

    mfwOmegaIncrementUp     = RAMP_INCREMENT_UP;
    mfwOmegaIncrementDown   = RAMP_INCREMENT_DOWN;
}

/******************************************************************************* 
* 
* Module        : MotorASettings() 
* 
* Description   : Setting of constants and coeficients from bldcadczcdefines.h
*                 file for MotorA (Low Voltage Motor MCG IB23810)
*
* 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 MotorASettings(void)
{
    mudtStartComputInit                         = mudtMOTORA_START_COMPUT_INIT;
    mudtRunComputInit                           = mudtMOTORA_RUN_COMPUT_INIT; 

    muwwPerAlignmentSys                         = MOTORA_PER_ALIGNMENT_SYS;
    mfwCurrAlignDesired                         = ((long) MOTORA_CURR_ALIGN_DESIRED_sub * 100UL) / (long) mfwMaxCurrent;
    mfwOmegaMinSysu                             = MOTORA_OMEGA_MIN_SYSU;
    mfwMaxSpeed                                 = MOTORA_SPEED_ROTOR_MAX_RPM;
    mwwPerCmtMin                                = MOTORA_PER_CMT_MIN;
    mwwMaxZCrosErr                              = MOTORA_MAX_ZCROSERR;
    mwwMinZCrosOKStart                          = MOTORA_MIN_ZCROSOK_START;
    muwwConstPerProcCmt                         = MOTORA_PER_START_PROCCMT;
    mfwPwmtoADCSamplingTime                     = mult_r(MOTORA_PWM_to_ADC_COEF, C_PWM_A_reg_PWM_PWMCM);

    /* muwwAlignmentStepCmt = EVM_ALIGNMENT_STEP_CMT; */
    muwwAlignmentStepCmtABC                     = MOTORA_ALIGNMENT_STEP_CMT_ABC;
    muwwAlignmentStepCmtACB                     = MOTORA_ALIGNMENT_STEP_CMT_ACB;
    muwwAlignmentStepCmt                        = muwwAlignmentStepCmtABC;
    
    mfwIDCBusDesiredLimit                       = ((long) MOTORA_CURR_LIMIT_DESIRED_sub * 100UL) / (long) mfwMaxCurrent;
    
    /* PI Speed Controller setings */
    mudtSpeedParamsPI.ProportionalGain          = MOTORA_SPEED_PI_PROPORTIONAL_GAIN;
    mudtSpeedParamsPI.ProportionalGainScale     = MOTORA_SPEED_PI_PROPORTIONAL_GAIN_SCALE;
    mudtSpeedParamsPI.IntegralGain              = MOTORA_SPEED_PI_INTEGRAL_GAIN;
    mudtSpeedParamsPI.IntegralGainScale         = MOTORA_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       = MOTORA_CURR_PI_PROPORTIONAL_GAIN;
    mudtCurAlignParamsPI.ProportionalGainScale  = MOTORA_CURR_PI_PROPORTIONAL_GAIN_SCALE;
    mudtCurAlignParamsPI.IntegralGain           = MOTORA_CURR_PI_INTEGRAL_GAIN;
    mudtCurAlignParamsPI.IntegralGainScale      = MOTORA_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       = MOTORA_CURRLIMIT_PI_PROPORTIONAL_GAIN;
    mudtCurLimitParamsPI.ProportionalGainScale  = MOTORA_CURRLIMIT_PI_PROPORTIONAL_GAIN_SCALE;
   	mudtCurLimitParamsPI.IntegralGain           = MOTORA_CURRLIMIT_PI_INTEGRAL_GAIN;
   	mudtCurLimitParamsPI.IntegralGainScale      = MOTORA_CURRLIMIT_PI_INTEGRAL_GAIN_SCALE;
   	mudtCurLimitParamsPI.PositivePILimit        = 32767; 
   	mudtCurLimitParamsPI.NegativePILimit        = 0;
   	mudtCurLimitParamsPI.IntegralPortionK_1     = 0;
}

/******************************************************************************* 
* 
* Module        : MotorBSettings() 

⌨️ 快捷键说明

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