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

📄 bldc_zc_8013.c

📁 菲斯卡尔无传感器无刷控制方案。具体说明文档和程序都在压缩包内。
💻 C
📖 第 1 页 / 共 5 页
字号:
    
    /* Process button prescaler */
    if (muwwButtonReadPrescaler > 0) muwwButtonReadPrescaler--;	
	
    /* Becasue DC Bus voltage is read, refresh ADC Back-EMF channel zero cross offsets */
    if (mudtCmdApplication.uintCalibrationDoneFlag)
    {
        mfwUDCBusHalf = mult_r(mfwCalibrationCoefs[mudtBldcAlgoStates.State_Cmt.Step_Cmt], mfwUDCBus);
    }
    else
    {
        mfwUDCBusHalf = mult_r(FRAC16(0.5), mfwUDCBus);
    }

    ioctl(ADC, ADC_WRITE_OFFSET4, mfwUDCBusHalf);
    ioctl(ADC, ADC_WRITE_OFFSET5, mfwUDCBusHalf);
    ioctl(ADC, ADC_WRITE_OFFSET6, mfwUDCBusHalf);
    
    /* Clear status register EOSI bit */
    ioctl(ADC, ADC_CLEAR_STATUS_EOSI, NULL);
}
#pragma optimization_level 2

/******************************************************************************* 
* 
* Module        : IsrADCLimit() 
* 
* Description   : Interrupt function for
*                 ADC Zero Crossing callback
*                 ADC Low Limit callback
*                 ADC High Limit callback
*
*                 The function provides:
*                 - Zero Crossing interrupt :
*                   - Checking that Zero Cross is from Back EMF channels
*                   - If Zero Crossing Enabled, reading of commutation counter and
*                     executing 'bldczcZCrosEdgeIntAlg()' algorithm
*                   - Updating commutation timer timeout if needed
*                 - Low Limit interrupt
*                   - Stopping application and switching to Fault state, in case
*                     of DC Undervoltage event
*                 - High Limit interrupt
*                   - Stopping application and switching to Fault state, in case
*                     of DC Overvoltage event
*           
* Returns       : None 
*
* Global Data   : mApplicationMode        - Application Mode (Run/Stop/Fault)
*                 muwwDriveFaultStatus    - Drive Fault Status
*                 mudtCmdApplication      - Application flags
*                 mudtBldcAlgoTimes       - Times structure for commutation algorithms BldcZC
*                 mudtBldcAlgoStates      - States structure for commutation algorithms BldcZC
*
* Arguments     : None
* 
* Range Issues  : None 
* 
*******************************************************************************/
#pragma interrupt saveall
void IsrADCLimit(void)
{
    UWord16 uwwLimitStatus;
    UWord16	muwwTZCSample;		/* Zero Crossing Sample time */    
    
    // Zero Crossing interrupt
    if (ioctl(ADC, ADC_GET_STATUS_ZCI, NULL))
    {
        /* if Zero Crossing caused by phase voltages */
        if (mudtCmdApplication.uintZeroCrosEnblFlag)
        {
            if (mudtBldcAlgoStates.State_ZCros.Cmd_ZCros.ZCrosInt_EnblFlag)
            {                 
                muwwTZCSample = ioctl(QTIMER_0, QT_READ_COUNTER_REG, NULL);

                bldczcZCrosEdgeIntAlg(&mudtBldcAlgoStates, &mudtBldcAlgoTimes, muwwTZCSample);

                /* Check for any commutation timer compare register change request */
                if (mudtBldcAlgoStates.State_General.Cmd_General.Timer_DrvRqFlag)
                {
                    /* Update compare register with mudtBldcAlgoTimes.T_Next */
                    ioctl(QTIMER_0, QT_WRITE_COMPARE_REG1, mudtBldcAlgoTimes.T_Next);

                    /* Clear update request bit */
                    mudtBldcAlgoStates.State_General.Cmd_General.Timer_DrvRqFlag = 0;
                }
            }
        }
        ioctl(ADC, ADC_CLEAR_STATUS_ZCI, NULL);
    }

    /* Low Limit interrupt */
    if (ioctl(ADC, ADC_GET_STATUS_LLMTI, NULL))
    {
        uwwLimitStatus = ioctl(ADC, ADC_READ_LIMIT_STATUS, NULL);
        
        /* Check for DC Undervoltage */
        if (uwwLimitStatus & ADC_ADLSTAT_LLS0)
        {
            StopApplication();
            muwwDriveFaultStatus |= DC_UNDERVOLTAGE;
            mApplicationMode = FAULT;
        }  
        
        ioctl(ADC, ADC_CLEAR_STATUS_LLMTI, NULL);
    }

    /* High Limit interrupt */
    if (ioctl(ADC, ADC_GET_STATUS_HLMTI, NULL))
    {
       uwwLimitStatus = ioctl(ADC, ADC_READ_LIMIT_STATUS, NULL);
       
        /* Check for DC Overvoltage */
       if (uwwLimitStatus & ADC_ADLSTAT_HLS0)
       {
           StopApplication();
           muwwDriveFaultStatus |= DC_OVERVOLTAGE;
           mApplicationMode = FAULT;
       }

        /* Check for DC Overcurrent */
    	if (uwwLimitStatus & ADC_ADLSTAT_HLS1)
        {
        //    StopApplication ();
        //    muwwDriveFaultStatus |= DC_OVERCURRENT;
        //    mApplicationMode = FAULT;
        }

        ioctl(ADC, ADC_CLEAR_STATUS_HLMTI, NULL);
    }
}

/******************************************************************************* 
* 
* Module        : IsrPWMFault() 
* 
* Description   : Interrupt function for PWM Fault callback
*
*                 The function provides hardware PWM fault bit for overcurrent
*                 and / or overvoltage protections
*           
* Returns       : None
*
* Global Data   : mApplicationMode      - Application Mode (Run/Stop/Fault)
*                 muwwDriveFaultStatus  - Drive Fault Status
*
* Arguments     : None
* 
* Range Issues  : None 
* 
*******************************************************************************/
#pragma interrupt saveall
void IsrPWMFault(void)
{    
    StopApplication();  

    if (ioctl(PWM, PWM_READ_FAULT_STATUS_REG, NULL) & 0x0100)
    { 
        muwwDriveFaultStatus |= DC_OVERCURRENT;
        mApplicationMode = FAULT;

	    /*  Clear  Overcurrent fault flag */
	    ioctl(PWM, PWM_CLEAR_FAULT_FLAG, PWM_FAULT_0);
	}
}

/******************************************************************************* 
* 
* Module        : IsrCommutation() 
* 
* Description   : Interrupt function (Uses Quad Timer 0) for Commutation timer callback
*
*     	          The function provides:
*                 - Motor commutation timing (in bldczcTimeoutIntAlg())
*                 - Motor commutation, if requested
*                 - Updating next commutation timer intterupt timeout, if requested 
*                 - Changing Zero Cross channel mask, if requested 
*
*                 The procedure is:
*                 - Interrupt timeout algorithm bldczcTimeoutIntAlg() is called
*                 - The other bldczc algorithms are provided according to request flags 
*                   set by bldczcTimeoutIntAlg()
*           
* Returns       : None 
*
* Global Data   : mudtBldcAlgoTimes   - Times structure for commutation algorithms BldcZC
*                 mudtBldcAlgoStates  - States structure for commutation algorithms BldcZC
*                 mfwUZCPhaseX        - Back EMF voltage of non-feeded phase
*
* Arguments     : None 
* 
* Range Issues  : None 
* 
*******************************************************************************/
#pragma interrupt saveall
void IsrCommutation(void)
{
	/* This timer serves as commutation timer */

    UWord16 T_Actual;
    
    T_Actual = ioctl(QTIMER_0, QT_READ_COUNTER_REG, NULL);

    bldczcTimeoutIntAlg(&mudtBldcAlgoStates, &mudtBldcAlgoTimes, T_Actual, mfwUZCPhaseX);
 
    /* Check for Commutation Driver Request Flag, which is set in CmtTimeout.
	   If this flag is set, perform commutation. */
    if (mudtBldcAlgoStates.State_Cmt.Cmd_Cmt.Cmt_DrvRqFlag)
    {
        /* Exact instant of commutation. Commutation is performed here. */
        BldcCmtPWM(mudtBldcAlgoStates.State_Cmt.Step_Cmt);

        /* Disable Commutation Driver Request Flag */
        mudtBldcAlgoStates.State_Cmt.Cmd_Cmt.Cmt_DrvRqFlag = 0;
     }
 
    /* Check for any commutation timer compare register change request */
    if (mudtBldcAlgoStates.State_General.Cmd_General.Timer_DrvRqFlag)
    {
        /* Update compare register with mudtBldcAlgoTimes.T_Next */
        ioctl(QTIMER_0, QT_WRITE_COMPARE_REG1, mudtBldcAlgoTimes.T_Next);

        /* Clear request flag */
        mudtBldcAlgoStates.State_General.Cmd_General.Timer_DrvRqFlag = 0;
    }
    
    /* If ZeroCross input channel modify request exist, perform modification */
    if (mudtBldcAlgoStates.State_ZCros.Cmd_ZCros.ZCInpSet_DrvRqFlag)
    {  
        /* Change ZeroCross input channel according to current step and direction */
        ioctl(ADC, ADC_WRITE_ZERO_CROSS_CNTRL, \
        SetADC_ZCInp_Tab[mudtBldcAlgoStates.State_Cmt.Step_Cmt][mudtBldcAlgoStates.State_Cmt.Cmd_Cmt.DIRFlag]);

        /* Clear ZeroCross input channel modify request */
        mudtBldcAlgoStates.State_ZCros.Cmd_ZCros.ZCInpSet_DrvRqFlag = 0;
    }

    ioctl(QTIMER_0, QT_CLEAR_FLAG, QT_COMPARE_FLAG);

}
/*******************************************************************************

/******************************************************************************* 
* 
* Module        : IsrSpeedCurrentControl() 
* 
* Description   : Interrupt function (Uses Quad Timer 2) for Speed and Alignment
*                 current control timer callback.
*
*                 The function provides:
*                 - Calls speed PI controller if enabled and prescaler timeout occoured
*                 - Performs ramp operation for desired speed
*                 - Calls alignment current PI controller if enabled
*                 - Countdowns alignment duration, if alignment is enabled
*                 - Calls current limiting PI controller and perform current limitation, if required
*                 - Updates PWM to ADC syncronization timer according to PWM duty cycle
*                   voltage average.
*           
* Returns       : None 
*
* Global Data   : mudtCmdApplication              - Application flags
*                 mwwSpeedPrescaler               - Prescaler for speed controller
*                 mwwPerSpeedSys                  - Reload value of speed prescaler
*                 mwwPerCmtMin                    - Minimum commutation period
*                 mudtBldcAlgoTimes.Per_ZCrosFlt  - Filtered commutation period for 
*                                                   mfwOmegaActualMech computation
*                 mfwOmegaActualMech              - Actual mechanical motor speed
*                 mfwOmegaRequiredMech            - Requested motor speed from user
*                 mfwOmegaDesiredMech             - Processed speed from mfwOmegaRequiredMech
*                 mfwOmegaMinSysu                 - Minimum allowed motor speed
*                 mfwOmegaIncrementUp             - Increment amount of ramp for speed
*                 mfwOmegaIncrementDown           - Decrement amount of ramp for speed
*                 mfwIDCBusDesiredAlign           - Desired DC Bus current during Alignment
*                 mfwIDCBus                       - Actual DC Bus current
*                 mudtSpeedParamsPI               - Speed PI controller data structure
*                 mudtCurAlignParamsPI            - Alignment current PI controller data structure
*                 mudtCurLimitParamsPI            - Current limit PI controller data structure
*                 miwUDesired                     - Desired output of Speed PI controller or alignment
*                                                   current controller
*                 miwUDesiredLimit                - Output of current limiting PI controller
*                 muwwAlignmentTimer              - Timer for alignment state
*                 miwCurrentLimitingMarker        - Marker to enable / disable current limiting warning
* 
* Arguments     : None 
* 
* Range Issues  : None 
* 
*******************************************************************************/
#pragma interrupt saveall
void IsrSpeedCurrentControl(void)
{
    Word16 TempSpeedCalc;
    static UWord16 uwwTimerOffset;
    
    mwwIsrSpeedCurrentCall++;
    

⌨️ 快捷键说明

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