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

📄 bldc.c

📁 直流无刷电机控制程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ==============================================================================
System Name:  BLDC3_2

File Name:	BLDC32.C

Description:	Primary system file for the implementation of sensorless current 
                  controller for a three phase brushless DC Motor.

Originator:		Digital control systems Group - Texas Instruments

Target dependency:	x240/1/2/3/07
To Select the target device see target.h file.

=====================================================================================
 History:
-------------------------------------------------------------------------------------
 9-15-2000	Release	Rev 1.0
=================================================================================  */

/*-----------------------------------------------------------------------------
    Get the compilation target setting.
    This target is defined by TARGET.H. To change the target, or to find out
    the present target, see that file.
-----------------------------------------------------------------------------*/
#include <TARGET.H>
/*-----------------------------------------------------------------------------
    Include header information for this file.
-----------------------------------------------------------------------------*/
#include <bldc.h>

/*-------------------------------------------------------------------------------
    Get buildlevel information.
---------------------------------------------------------------------------------*/
#include <build.h>
/*-----------------------------------------------------------------------------
    System settings
-----------------------------------------------------------------------------*/
#if (TARGET==F243)
#define WAIT_STATES     0x0040
#endif /* (TARGET==F243) */

#if (TARGET==F2407)
#define WAIT_STATES     0x00C0
#endif /* (TARGET==F243) */

/*-----------------------------------------------------------------------------
    Global Declarations

/*-----------------------------------------------------------------------------
    Instance the EVMDAC Interface.
-----------------------------------------------------------------------------*/
        EVMDAC dac = EVMDAC_DEFAULTS;

/*-----------------------------------------------------------------------------
    Instance the PWM Generator (Driver) Interface.
    Also initalize the PWMGEN object.
    This pre-initializer takes on the nature depending on the TARGET device.
    An IMPORTANT NOTE :
        This pre-initalization initializes the PWMGEN data structure in
        memory. This WILL NOT initialize the PWM Generator timers and
        so on. This is accomplished by calling the init method in the
        PWMGEN object. This applies to most drivers that supply an init
        method.
-----------------------------------------------------------------------------*/
        PWMGEN pwm = PWMGEN_DEFAULTS;

/*-----------------------------------------------------------------------------
    Instance the ADC (Driver) Interface.
    Also initalize the ADCVALS object.
    This pre-initializer takes on the nature depending on the TARGET device.
    An IMPORTANT NOTE :
        This pre-initalization initializes the ADCVALS data structure in
        memory. This WILL NOT initialize the ADC CONTROLS and
        so on. This is accomplished by calling the init method in the
        ADCVALS object.
-----------------------------------------------------------------------------*/
        ADCVALS adc = ADC_DEFAULTS;

/*-----------------------------------------------------------------------------
    Instance a single BLDC_TI object.
-----------------------------------------------------------------------------*/
        BLDC_TI bldc = BLDC_TI_INITVALS;

/*-----------------------------------------------------------------------------
    Instance the WATCHDOG Interface.
-----------------------------------------------------------------------------*/
        WATCHDOG wdog = WATCHDOG_DEFAULTS;

/*-----------------------------------------------------------------------------
    Instance the ISR checking variable
-----------------------------------------------------------------------------*/
        int	isr_ticker;

void main()
{
/*-----------------------------------------------------------------------------
    Return system to a sane condition
-----------------------------------------------------------------------------*/
        RstSystem();

/*-----------------------------------------------------------------------------
    Initialize PWM generator
-----------------------------------------------------------------------------*/
        pwm.init(&pwm);         /* pwm driver initialization */
        
/*-----------------------------------------------------------------------------
    Initialize ADC driver
-----------------------------------------------------------------------------*/
        adc.init(&adc);      /* adc driver initialization */

/*-----------------------------------------------------------------------------
    Initialize time base generator
-----------------------------------------------------------------------------*/
        time_base_init();

/*-----------------------------------------------------------------------------
    Initialise the Real time monitor
-----------------------------------------------------------------------------*/

#if (REAL_TIME == TRUE)
        rtmon_init();      /* Call the monitor init function  */
#endif /* REAL_TIME==TRUE */

/*-----------------------------------------------------------------------------
    Hardware/Board Specific Initialization
-----------------------------------------------------------------------------*/
        evm_pwm_init();

/*-----------------------------------------------------------------------------
    ADC channel select
    Channels 6,5,4,3 for 243EVM with DMC1500
    Channels 12,11,10,5 for 2407EVM/6,5,4,3 for 2407eZdsp with DMC1500
-----------------------------------------------------------------------------*/

        adc.a4_ch_sel = CHANNEL_SETTINGS;

/*-----------------------------------------------------------------------------
    Intialize the BLDC_TI object. This is a call to the init method within
    the BLDC_TI object bldc
-----------------------------------------------------------------------------*/
        BLDC_TI_Init(&bldc);

        pwm.d_func = ALIGN_DUTY;


#if (BUILDLEVEL==LEVEL1)
/*-----------------------------------------------------------------------------
    DAC pointer init
-----------------------------------------------------------------------------*/

        dac.qptr0 = &bldc.impl.out;

#endif  /* BUILDLEVEL==LEVEL1 */


#if (BUILDLEVEL==LEVEL2)

/*-----------------------------------------------------------------------------
    ADC gain & offset adjustment
-----------------------------------------------------------------------------*/

        adc.c1_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c2_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c3_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c4_gain = 0x1fff;    /* gain = 1.0 (Q13)                */

/*-----------------------------------------------------------------------------
    DAC pointer init
-----------------------------------------------------------------------------*/

        dac.qptr0 = &adc.c1_out;
        dac.qptr1 = &adc.c2_out;
        dac.qptr2 = &adc.c3_out;
        dac.qptr3 = &adc.c4_out;

#endif  /* BUILDLEVEL==LEVEL2 */


#if (BUILDLEVEL==LEVEL3)

/*-----------------------------------------------------------------------------
    ADC gain & offset adjustment
-----------------------------------------------------------------------------*/

        adc.c1_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c2_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c3_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c4_gain = 0x1fff;    /* gain = 1.0 (Q13)                */

/*-----------------------------------------------------------------------------
    DAC pointer init
-----------------------------------------------------------------------------*/

        dac.qptr0 = &bldc.cmtn.trig;

/*-----------------------------------------------------------------------------
    The following line will not compile since neutral is a local variable in
    commutation trigger module.
-----------------------------------------------------------------------------*/
        #if 0
        dac.qptr1 = &bldc.cmtn.neutral;
        #endif
/*-----------------------------------------------------------------------------*/
        dac.qptr2 = &bldc.cmtn.zc_trig;
        dac.qptr3 = &bldc.cmtn.debug_Bemf;

#endif  /* BUILDLEVEL==LEVEL3 */

#if (BUILDLEVEL==LEVEL4)

/*-----------------------------------------------------------------------------
    ADC gain & offset adjustment
-----------------------------------------------------------------------------*/

        adc.c1_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c2_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c3_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c4_gain = 0x1fff;    /* gain = 1.0 (Q13)                */

/*-----------------------------------------------------------------------------
    DAC pointer init
-----------------------------------------------------------------------------*/

        dac.qptr0 = &adc.c1_out;
        dac.qptr1 = &adc.c2_out;
        dac.qptr2 = &adc.c3_out;
        dac.qptr3 = &adc.c4_out;


#endif  /* BUILDLEVEL==LEVEL4 */

#if (BUILDLEVEL==LEVEL5)

/*-----------------------------------------------------------------------------
    ADC gain & offset adjustment
-----------------------------------------------------------------------------*/

        adc.c1_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c2_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c3_gain = 0x0800;    /* gain = 0.125 (Q13)              */
        adc.c4_gain = 0x1fff;    /* gain = 1.0 (Q13)                */

        bldc.current_set = 0x0065;

/*-----------------------------------------------------------------------------
    DAC pointer init
-----------------------------------------------------------------------------*/

        dac.qptr0 = &adc.c1_out;
        dac.qptr1 = &adc.c2_out;
        dac.qptr2 = &adc.c3_out;
        dac.qptr3 = &adc.c4_out;


#endif  /* BUILDLEVEL==LEVEL5 */


 enable_ints();     /* set off the system running */



/*---------------------------------------------------------------------------*/

        while(1)             /* Nothing running in the background at present */

⌨️ 快捷键说明

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