📄 pmsm31.c
字号:
/* ==============================================================================
System Name: PMSM3_1 (QEP version)
File Name: PMSM31.C
Description: Peripheral independent object for the implementation
of Sensored Field Orientation Control for a Three Phase
Permanent-Magnet Synchronous Motor using measured rotor angle.
Originator: Digital control systems Group - Texas Instruments
Target dependency: x240/1/2/3/07
To Select the target device see target.h file.
Note that the PWM/sampling frequency in C system is running at 15 kHz, which
is different from the PWM/samping frequency in ASM system (i.e., 20 kHz) as
indicated in the PMSM3-1 system documentation. Also, this PWM/samping frequency
in both ASM and C systems are based on x2407 with 30 MHz clock. If the x243 with
20 MHz clock is used, then the PWM/samping frequency may be decreased accordingly.
=====================================================================================
History:
-------------------------------------------------------------------------------------
03-01-2001 Release Rev 1.0
================================================================================= */
/*-----------------------------------------------------------------------------
Include header information for this file.
-----------------------------------------------------------------------------*/
#include <pmsm31.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 a speed measurement object. The defaults are set in
SPEED_FR.H. Also the init defaults to measure speed by frequency.
-----------------------------------------------------------------------------*/
SPEED_MEAS speed = SPEED_FR_MEAS_DEFAULTS;
/*------------------------------------------------------------------------------
Declaration for the QEP Interface Driver. The defaults are set in
F2407QEP.H or F243_QEP.H
------------------------------------------------------------------------------*/
QEP qep = QEP_DEFAULTS;
/*-----------------------------------------------------------------------------
Instance a single FOC_TI object.
-----------------------------------------------------------------------------*/
FOC_TI foc = FOC_TI_INITVALS;
/*-----------------------------------------------------------------------------
Instance the EVMDAC Interface.
-----------------------------------------------------------------------------*/
EVMDAC dac = EVMDAC_DEFAULTS;
/*-----------------------------------------------------------------------------
Instance the WATCHDOG Interface.
-----------------------------------------------------------------------------*/
WATCHDOG wdog = WATCHDOG_DEFAULTS;
/*-----------------------------------------------------------------------------
Instance ILEG2MEAS object. The defaults are set in F2407ILG.H or F243ILG.H
-----------------------------------------------------------------------------*/
ILEG2MEAS ilg2 = ILEG2MEAS_DEFAULTS;
/*-----------------------------------------------------------------------------
Instance DRIVE object. The defaults are set in F07DRIVE.H or F243DRIVE.H
-----------------------------------------------------------------------------*/
DRIVE drive = DRIVE_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
..\..\drv011\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.
-----------------------------------------------------------------------------*/
/* pwm.period_max=1000; */ /* This is based on 15kHz PWM frequency (30MHz) */
pwm.period_max=1333; /* This is based on 15kHz PWM frequency (40MHz)*/
/*-----------------------------------------------------------------------------
Initialize the FOC_TI object. This is a call to the init method within
the FOC_TI object foc.
-----------------------------------------------------------------------------*/
FOC_TI_Init(&foc);
/*-----------------------------------------------------------------------------
Initialize the real time monitor
-----------------------------------------------------------------------------*/
rtmon_init(); /* Call the monitor init function */
// enable_ints(); /* Set off the system running. */
asm (" CLRC INTM"); /* 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.init(&pwm);
/*-----------------------------------------------------------------------------
Clear any EV(A)IFRA flags.
-----------------------------------------------------------------------------*/
//#if TARGET==F243
// EVIFRA=0xffff;
//#elif TARGET==F2407
EVBIFRA=0xffff;
//#endif /* TARGET */
/*-----------------------------------------------------------------------------
Set the dac pointers
-----------------------------------------------------------------------------*/
dac.qptr0=&foc.svgen.va;
dac.qptr1=&foc.svgen.vb;
dac.qptr2=&foc.svgen.vc;
dac.qptr3=&foc.rg.rmp_out;
#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
..\..\drv011\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=667; /* This is based on 15kHz PWM frequency (20MHz) */
//#elif TARGET==F2407
/* pwm.period_max=1000; */ /* This is based on 15kHz PWM frequency (30MHz) */
pwm.period_max=1333; /* This is based on 15kHz PWM frequency (40MHz)*/
//#endif /* TARGET */
/*-----------------------------------------------------------------------------
Initialize the FOC_TI object. This is a call to the init method within
the FOC_TI object foc.
-----------------------------------------------------------------------------*/
FOC_TI_Init(&foc);
/*-----------------------------------------------------------------------------
Initialize the real time monitor
-----------------------------------------------------------------------------*/
rtmon_init(); /* Call the monitor init function */
// enable_ints(); /* Set off the system running. */
asm (" CLRC INTM"); /* 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.init(&pwm);
/*-----------------------------------------------------------------------------
Initialize ILEG2MEAS
-----------------------------------------------------------------------------*/
ilg2.init(&ilg2);
/*-----------------------------------------------------------------------------
Set the dac pointers
-----------------------------------------------------------------------------*/
dac.qptr0=&ilg2.out_a;
dac.qptr1=&ilg2.out_b;
dac.qptr2=&foc.rg.rmp_out;
dac.qptr3=&foc.voltage_dq.q;
#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
..\..\drv011\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=667; /* This is based on 15kHz PWM frequency (20MHz) */
//#elif TARGET==F2407
/* pwm.period_max=1000; */ /* This is based on 15kHz PWM frequency (30MHz) */
pwm.period_max=1333; /* This is based on 15kHz PWM frequency (40MHz)*/
//#endif /* TARGET */
/*-----------------------------------------------------------------------------
Initialize the FOC_TI object. This is a call to the init method within
the FOC_TI object foc.
-----------------------------------------------------------------------------*/
FOC_TI_Init(&foc);
/*-----------------------------------------------------------------------------
Initialize the real time monitor
-----------------------------------------------------------------------------*/
rtmon_init(); /* Call the monitor init function */
// enable_ints(); /* Set off the system running. */
asm (" CLRC INTM"); /* Set off the system running. */
/*-----------------------------------------------------------------------------
Initialize DRIVE -- Waiting for PWM enable flag setting
-----------------------------------------------------------------------------*/
while(drive.enable_flg==0)
{
drive.init(&drive);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -