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

📄 bldc_zc_8013.c

📁 菲斯卡尔无传感器无刷控制方案。具体说明文档和程序都在压缩包内。
💻 C
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************
* Freescale Inc.
* (c) Copyright 2005 Freescale, Inc.
* ALL RIGHTS RESERVED.
*************************************************************************/

/*************************************************************************
* FILE NAME         :   bldc_zc_8013.c
*
* Description       :   3-phase BLDC Motor Control with Zero Cross ADC Application.
*				        No sensor is used for speed measurements or position estimation.
*				        Back EMF Zero crosses are detected using ADC.
*
* Modules Included  :   main                        ( void )
*                       Initialize                  ( void )
*                       InitializeSetup             ( void )
*                       ApplicationStateMachine     ( void )
*                       IsrCommutation              ( void )
*                       IsrSpeedCurrentControl      ( void )
*                       IsrADCEndOfScan             ( void )
*                       IsrADCLimit                 ( void )
*                       IsrPWMFault                 ( void )
*                       InitADCMeasurements         ( void )
*                       EVM33395BoardSettings       ( void )
*                       MPBoardSettings             ( void )
*                       MotorASettings              ( void )
*                       MotorBSettings              ( void )
*                       CheckRunStopSwitch          ( void )
*                       CheckUpDownSwitches         ( void )
*                       CommutationControlInit      ( void )
*                       CommutationControl          ( void )
*                       CommutationSetAlignment     ( UWord16, UWord16, UWord16,
*                                                     BldcfCmdApplication )
*                       CommutationSetStarting      ( bldczc_sStates, bldczc_sTimes,
*                                                     UWord16, Word16,
*                                                     Word16, BldcfCmdApplication )
*                       CommutationSetRunning       ( bldczc_sStates, bldczc_sTimes )
*                       CommutationSetStop          ( bldczc_sStates, BldcfCmdApplication )
*                       BldcCmtPWM                  ( UWord16 )
*                       RampGetValue                ( Frac16, Frac16, const Frac16,
*                                                     const Frac16 )
*                       StopApplication             ( void )
*************************************************************************/

/************************************************************************/
/*                            I N C L U D E                             */
/************************************************************************/
/* Including used modules for compilling procedure */

#include "Cpu.h"
#include "QTIMER_0.h"
#include "QTIMER_2.h"
#include "QTIMER_3.h"
#include "ADC_A.h"
#include "PWM_A.h"
#include "MC1.h"
#include "PC_M1.h"
#include "Inhr1.h"
#include "QTIMER_1.h"

/* Include shared modules, which are used for whole project */

#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

#include <stdlib.h>                             /* Metrowerks header file - standard library    */

#include "bldcadczcconfig.h"                    /* Include file for application configuration   */
#include "bldcdrv.h"
#include "BldcZC.h"
#include "bldcadczcdefines.h"                   /* Include file for application definitions     */

/************************************************************************/
/*                      G L O B A L  V A R I A B L E S                  */
/************************************************************************/
/* External variables */
static eRunStop     mApplicationMode;           /* status of application state machine */
static eRunStop     mSwitchState;               /* status of RUN / STOP switch */

static UWord16      muwwDriveFaultStatus;       /* Drive Fault Status */

static Frac16       mfwOmegaDesiredMech;        /* Omega Mechanical Desired */
static Frac16       mfwOmegaRequiredMech;       /* Omega Mechanical Required */
static Frac16       mfwOmegaRequestedMech;      /* Omega Mechanical Requested */
static Frac16       mfwOmegaActualMech;         /* Omega Mechanical Actual */
static Frac32       mfwOmegaActualMechSum;      /* Accumulator for Omega Mechanical Actual filtering */

static Frac16       mfwOmegaIncrementUp;
static Frac16       mfwOmegaIncrementDown;

static UWord16      muwwAlignmentTimer;         /* Timer register for Alignment */
static Word16       mwwSpeedPrescaler;          /* Prescaler for Speed Controller */
static Int16        miwCurrentLimitingMarker;

/* Bldc control command variables */
static BldcfCmdApplication mudtCmdApplication;  /* application command/request byte */

/* Variables set according motor type */
static Word16       mwwMaxZCrosErr;             /* Maximal zero crossing errors */
static Word16       mwwMinZCrosOKStart;         /* Minimal correct zero crossing to leave "Starting" stage */
static UWord16      muwwAlignmentStepCmt;       /* Final Alignment step index */
static UWord16      muwwAlignmentStepCmtABC;    /* Alignment step index for abc rotation direction */
static UWord16      muwwAlignmentStepCmtACB;    /* Alignment step index for acb rotation direction */

static UWord16      muwwConstPerProcCmt;
static Frac16       mfwCurrAlignDesired;        /* Desired Alignment Current */
static Frac16       mfwOmegaMinSysu;            /* Minimal angular speed in system units */
static UWord16      muwwPerAlignmentSys;        /* Alignment period (interval) in system units */
static Word16       mwwPerSpeedSys;             /* Speed prescaler */
static Word16       mwwPerCmtMin;               /* Minimal Commutation period */
static Frac16       mfwMaxSpeed;                /* Maximal Speed */
static Frac16       mfwMaxVoltage;              /* Maximal Voltage */
static Frac16       mfwMaxCurrent;              /* Maximal Current */
static Frac16       mfwPwmtoADCSamplingTime;    /* Time definition from PWM reload to ADC sampling time */

/* Analog measurement variables */
static bldczc_fU_ZC3Phase mudtUZC3Phase;        /* Phase voltage structure */ 
static Word16       mfwUZCPhaseX;               /* Phase voltage of Zero crossing input */
static Int16        miwUDesired;                /* Desired voltage */
static Frac16       mfwIDCBusDesiredLimit;      /* Desired (set by user) DC Bus limit current for running */
static Frac16       mfwIDCBusDesiredAlign;		/* Desired (set by user) DC Bus current for alignment */
static Int16        miwCalibrationStep;         /* Alignment step counter for calibration */
static Frac16       mfwCalibrationCoefs[MAX_STEP_CMT + 1];

static Int16        miwUDesiredLimit;

static Frac16       mfwUDCBus;                  /* Actual filtered DC Bus voltage */
static Frac16       mfwUDCBusSample;            /* DC Bus voltage one sample */
static Frac32       mfwUDCBusSum;               /* Accumulator for DC Bus voltage filtering */
static Frac16       mfwUDCBusHalf;              /* Half of DC Bus voltage filtered */                  

static Frac16       mfwIDCBus;                  /* Actual filtered DC Bus current */
static Frac16       mfwIDCBusSample;            /* DC Bus current one sample */
static Frac32       mfwIDCBusSum;               /* Accumulator for DC Bus current filtering */

/* Controller parameter structures */
mc_sPIparams1_limitSc mudtSpeedParamsPI;        /* structure with PI Speed controller Parameters */
mc_sPIparams1_limitSc mudtCurAlignParamsPI;     /* structure with PI Alignment Current Controller Parameters */
mc_sPIparams1_limitSc mudtCurLimitParamsPI;     /* structure with PI Limit Current Controller Parameters */

/* Motor commutation variables */
static eBldcStatusCommutation mStatusCommutation;

/* status variable of BLDC commutation controller */
static bldczc_sStates       mudtBldcAlgoStates; /* states variable of BLDC commutation algorithms */
static bldczc_sTimes        mudtBldcAlgoTimes;  /* times varisble for BLDC commutation algorithms */
static bldczc_sComputInit   mudtStartComputInit;/* Initialization structure for commutation starting */
static bldczc_sComputInit   mudtRunComputInit;  /* Initialization structure for commutation running */

mc_tPWMSignalMask   mudtPWMMaskState;           /* PWM Mask State variable for pwm operation */
mc_tPWMSignalMask   mudtPWMSwapState;           /* PWM Swap State variable for pwm (complementary) operation */

static UWord16      muwwButtonReadPrescaler;

static Frac16       mwwIsrSpeedCurrentCall;

/************************************************************************/
/*                      F U N C T I O N S  C O D E                      */
/************************************************************************/

/*************************************************************************
* 
* Module        : main() 
* 
* Description   : This application is designed to demonstrate the BLDC Motor Control
*                 using the A/D Converter zero crossing detection to detect zero
*                 crossings of Back EMF. After initialization for the used power stage,
*                 motor and processor, the application enters an executive loop, that
*                 calls the ApplicationStateMachine and CommutationControl functions.
*
*                 The application uses several interrupt routines:
*                 - IsrCommutation            - Commutation interrupt, uses Quad Timer 0
*                 - IsrSpeedCurrentControl    - Speed & Current regulations interrupt, uses Quad Timer 2
*                 - IsrADCEndOfScan           - A/D converter end of scan interrupt
*                 - IsrADCLimit               - A/D converter zero cross and limit (protections) interrupt
*                 - IsrPWMFault               - PWM module fault interrupt
* 
*                 The control process is following:
*                 User interface buttons (Run / Stop switch, Up / Down buttons) are periodicaly
*                 scanned. According to the state of the control signals (Run / Stop switch,
*                 Up / Down buttons) the speed command is calculated. The comparison between
*                 the actual speed command and the measured speed generates a speed error. The
*                 speed error is brought to the speed PI controller that generates a new corrected
*                 applied voltage. Commutations are performed by the Commutation Interrupt, where
*                 Back EMF of the non-feeded phase is continuously scanned by the A / D converter.
*                 The commutation algorithm calculates which PWM channel is enabled for output generation
*                 and which phase should be swapped. The PWM module can work either in independent or
*                 complementary mode. DC Bus voltage and current are also continuously measured by the
*                 A / D converter and filtered. Again thanks to the A / D converter limit functions,
*                 DC undervoltage and DC overvoltage protections are performed.
* 
* Returns       : None 
* 
* Global Data   : None
*
* Arguments     : None 
* 
* Range Issues  : None 
* 
*************************************************************************/
void main(void)
{
	/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
	PE_low_level_init();
	/*** End of Processor Expert internal initialization.                    ***/
      
	turn_off_sat(); 
    
	Initialize();
	InitializeSetup();
    
	/* Main control loop */
	while(1)
	{
        ApplicationStateMachine();
        CommutationControl();

		CheckRunStopSwitch();
		CheckUpDownSwitches();	
    }
}

/******************************************************************************* 
* 
* Module        : Initialize() 
* 
* Description   : The function provides:
*	         	  - ADC initialization
*                 - PWM initialization
*                 - Quad timers initialization
*                 - GPIO initialization
*                 - Setting initial values for application bits
*		
* Returns       : None 
*
* Global Data   : mudtCmdApplication  - Set bits for initialization values
*                 mSwitchState        - Set switch state to Stop
*                 mApplicationMode    - Set application mode to Stop
* 
* Arguments     : None 
* 
* Range Issues  : None 
* 
*******************************************************************************/
static void Initialize(void)
{
    /* disable all interrupts */
    archDisableInt();

    /* Application command byte clear */ 

    mudtCmdApplication.uintStartAlignmentCmtCmdFlag     = 0;
    mudtCmdApplication.uintEndAlignmentRqFlag           = 0;
    mudtCmdApplication.uintAlignmentTimedFlag           = 0;
    mudtCmdApplication.uintBldcRunRqFlag                = 0;
    mudtCmdApplication.uintDirACBCmtRqFlag              = 0;
    mudtCmdApplication.uintDirACBCmtActualFlag          = 0;
    mudtCmdApplication.uintStartRunningCmtCmdFlag       = 0;
    mudtCmdApplication.uintSpeedCtrlEnblFlag            = 0;
    mudtCmdApplication.uintEndRunningCmtCmdFlag         = 0;
    mudtCmdApplication.uintZeroCrosEnblFlag             = 0;
    mudtCmdApplication.uintCurrentLimitingActiveFlag    = 0;
    mudtCmdApplication.uintCalibrationDoneFlag          = 0;

    /* Fault status initialization */
    muwwDriveFaultStatus = NO_FAULT;

    /* Taken from an application with the real manual switch */
    mSwitchState = STOP;
    mApplicationMode = STOP;

    /* Desired voltage and current to zero */
    miwUDesired = 0;
    mfwIDCBusDesiredAlign = 0;
    
    mwwPerSpeedSys = PER_SPEED_SYS;

    miwCurrentLimitingMarker = CL_MARKER_LOW_LIMIT;    

    miwCalibrationStep = 0;
    
    muwwButtonReadPrescaler = BUTTON_READ_PRESCALER_SCAN;

    /* Commutation initialization */
    CommutationControlInit();

    /* ADC B basic initialization */
    ADC_A_Init();

    /* Define FAULT0/GPIOA6 pin as FAULT0 */
    ioctl(GPIO_A, GPIO_SETAS_PERIPHERAL, BIT_6);

    /* Init GPIOB */

⌨️ 快捷键说明

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