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

📄 vhz.c

📁 用于dsp产生pwm信号的c语言 程序,我刚开始学习,还请多多帮助
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ==============================================================================
System Name:  ACI3_1

File Name:	VHZ.C

Description:	Primary system file for the implementation of Sensored constant 
                  Volt/Hertz control of a Three Phase AC Induction 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 <vhz.h>
/*-----------------------------------------------------------------------------
    System settings
-----------------------------------------------------------------------------*/
#define WAIT_STATES     0x40
/*-----------------------------------------------------------------------------
    Global Declarations 

    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 Capture Driver Interface.
    This driver is pre-canned to read CAP1FIFO. To modify this the functions
    F243_CAP_Read(..) or F2407_EV?_CAP_Read must be modified or implemented 
    separately. Also initalize the cap object.
-----------------------------------------------------------------------------*/
        CAPTURE cap=CAPTURE_DEFAULTS;
                                         
/*-----------------------------------------------------------------------------
    Instance a speed measurement object. The defaults are set in
    SPEED_PR.H. Also  the init defaults to measure speed by period.
-----------------------------------------------------------------------------*/
        SPEED_MEAS speed=SPEED_PR_MEAS_DEFAULTS;
                                         
/*-----------------------------------------------------------------------------
    Instance a single VHZ_TI object.
-----------------------------------------------------------------------------*/
        VHZ_TI vhz=VHZ_TI_INITVALS; 

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

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

/*-----------------------------------------------------------------------------
    Instance DRIVE object. The defaults are set in F07DRIVE.H or F243DRIVE.H
-----------------------------------------------------------------------------*/
     	DRIVE drive = DRIVE_DEFAULTS;

/*-----------------------------------------------------------------------------
    Instance DATALOG object. The defaults are set in DATA_LOG.H
-----------------------------------------------------------------------------*/
     	DATALOG dlog = DATALOG_DEFAULTS;

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

void main()   
{
/*-----------------------------------------------------------------------------
    Return system to a sane condition
-----------------------------------------------------------------------------*/
        RstSystem();
     
#if (BUILDLEVEL==LEVEL1)
/*-----------------------------------------------------------------------------
    Set the pwm period to 500 cycles,(F243) [ or 750 cycles, LF240x ].
    This assumes a CPU CLKIN of 5MHz for the F243 and CLKIN of 7.5 MHz
    for the LF240x.

    Defaults for pwm are set in F243_PWM.H
    Note that this will ONLY change runtime configurable parameters.
    For changing settings like timer modes or PWM Polarity, once the 
    constants like PWM_INIT_STATE, or ACTR_INIT_STATE are changed, the
    driver file must be re-compiled.

    To do this change the constant and then run the batch file 
    ..\..\drv010\build\f243drv.bat or f2407drv.bat

    This will re-build the driver, with the new timer mode or PWM polarity,
    and then  (re)build for this project. This will update the setting.
-----------------------------------------------------------------------------*/
#if     TARGET==F243                      
        pwm.period_max=500;      /* This is based on 20kHz PWM frequency (20MHz) */

#elif   TARGET==F2407                                                          
/*        pwm.period_max=750;   */   /* This is based on 20kHz PWM frequency (30MHz) */
        pwm.period_max=1000;      /* This is based on 20kHz PWM frequency (40MHz) */
#endif  /* TARGET */            


/*-----------------------------------------------------------------------------
    Initialize the VHZ_TI object. This is a call to the init method within the 
    VHZ_TI object vhz.
-----------------------------------------------------------------------------*/
        VHZ_TI_Init(&vhz);

/*-----------------------------------------------------------------------------
    Initialize the real time monitor
-----------------------------------------------------------------------------*/
        rtmon_init();            /* Call the monitor init function           */
        enable_ints();           /* Set off the system running.              */

/*-----------------------------------------------------------------------------
    Initialize DRIVE  --  Waiting for PWM enable flag setting 
-----------------------------------------------------------------------------*/
        while(drive.enable_flg==0)
        {
        drive.init(&drive);
        }

/*-----------------------------------------------------------------------------
    Initialize PWM Generator
-----------------------------------------------------------------------------*/
        pwm.mfunc_c1=0;
        pwm.mfunc_c2=0;
        pwm.mfunc_c3=0;
        pwm.init(&pwm);          

/*-----------------------------------------------------------------------------
    Clear any EV(A)IFRA flags.
-----------------------------------------------------------------------------*/
#if     TARGET==F243                      
        EVIFRA=0xffff;          
#elif   TARGET==F2407                                                          
	    EVAIFRA=0xffff;        
#endif  /* TARGET */

/*-----------------------------------------------------------------------------
    Set the dac pointers to the phases and alpha of the VHZ_TI object 
    phase outputs.
-----------------------------------------------------------------------------*/
        dac.qptr0=&vhz.svgen.va;
        dac.qptr1=&vhz.svgen.vb;
        dac.qptr2=&vhz.svgen.vc;
        dac.qptr3=&vhz.svgen.alpha;

/*-----------------------------------------------------------------------------
    Initialize the DATALOG moddule. And set the dlog pointers to the 
    phases of the VHZ_TI object phase outputs.
-----------------------------------------------------------------------------*/
        dlog.init(&dlog);
        dlog.dlog_iptr1=&vhz.svgen.va;
        dlog.dlog_iptr2=&vhz.svgen.vb;

#endif /* (BUILDLEVEL==LEVEL1) */  


#if (BUILDLEVEL==LEVEL2)

/*-----------------------------------------------------------------------------
    Set the pwm period to 500 cycles,(F243) [ or 750 cycles, LF240x ].
    This assumes a CPU CLKIN of 5MHz for the F243 and CLKIN of 7.5 MHz
    for the LF240x.
    Defaults for pwm are set in F243_PWM.H
    Note that this will ONLY change runtime configurable parameters.
    For changing settings like timer modes or PWM Polarity, once the 
    constants like PWM_INIT_STATE, or ACTR_INIT_STATE are changed, the
    driver file must be re-compiled.

    To do this change the constant and then run the batch file 
    ..\..\drv010\build\f243drv.bat or f2407drv.bat

    This will re-build the driver, with the new timer mode or PWM polarity,
    and then run the (re)build for this project. This will update the 
    setting.
-----------------------------------------------------------------------------*/
#if     TARGET==F243                      
        pwm.period_max=500;      /* This is based on 20kHz PWM frequency (20MHz) */

#elif   TARGET==F2407                                                          
/*        pwm.period_max=750;   */   /* This is based on 20kHz PWM frequency (30MHz) */
        pwm.period_max=1000;      /* This is based on 20kHz PWM frequency (40MHz) */
#endif  /* TARGET */            

/*-----------------------------------------------------------------------------
    Initialize the VHZ_TI object. 
-----------------------------------------------------------------------------*/
        VHZ_TI_Init(&vhz);

/*-----------------------------------------------------------------------------
    Initialize the real time monitor
-----------------------------------------------------------------------------*/
        rtmon_init();            /* Call the monitor init function           */
        enable_ints();           /* Set off the system running.              */

/*-----------------------------------------------------------------------------
    Initialize DRIVE  --  Waiting for PWM enable flag setting 
-----------------------------------------------------------------------------*/
        while(drive.enable_flg==0)
        {
        drive.init(&drive);
        }

/*-----------------------------------------------------------------------------
    Initialize PWM Generator
-----------------------------------------------------------------------------*/
        pwm.mfunc_c1=0;
        pwm.mfunc_c2=0;
        pwm.mfunc_c3=0;
        pwm.init(&pwm);

/*-----------------------------------------------------------------------------
    Set the dac pointers to the phases and alpha of the VHZ_TI object 
    phase outputs.
-----------------------------------------------------------------------------*/
        dac.qptr0=&vhz.svgen.va;
        dac.qptr1=&vhz.svgen.vb;
        dac.qptr2=&vhz.svgen.vc;
        dac.qptr3=&vhz.svgen.alpha;

/*-----------------------------------------------------------------------------
    Initialize the DATALOG moddule. And set the dlog pointers to the 
    phases of the VHZ_TI object phase outputs.
-----------------------------------------------------------------------------*/
        dlog.init(&dlog);
        dlog.dlog_iptr1=&vhz.svgen.va;
        dlog.dlog_iptr2=&vhz.svgen.vb;

#endif /* (BUILDLEVEL==LEVEL2) */   

#if (BUILDLEVEL==LEVEL3)

/*-----------------------------------------------------------------------------
    Set the pwm period to 500 cycles,(F243) [ or 750 cycles, LF240x ].
    This assumes a CPU CLKIN of 5MHz for the F243 and CLKIN of 7.5 MHz
    for the LF240x.
    Defaults for pwm are set in F243_PWM.H
    Note that this will ONLY change runtime configurable parameters.
    For changing settings like timer modes or PWM Polarity, once the 
    constants like PWM_INIT_STATE, or ACTR_INIT_STATE are changed, the
    driver file must be re-compiled.

    To do this change the constant and then run the batch file 
    ..\..\drv010\build\f243drv.bat or f2407drv.bat

    This will re-build the driver, with the new timer mode or PWM polarity,
    and then run the (re)build for this project. This will update the 
    setting.
-----------------------------------------------------------------------------*/
#if     TARGET==F243                      
        pwm.period_max=500;      /* This is based on 20kHz PWM frequency (20MHz) */

#elif   TARGET==F2407                                                          

⌨️ 快捷键说明

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