/* ==============================================================================
System Name: BLDC31
File Name: BLDC3_1.C
Description: Primary system file for the Real Implementation of Sensored
Trapezoidal Drive for a Three Phase Brushless DC Motor (BLDC) using
Hall Effect sensor
Originator: Digital control systems Group - Texas Instruments
Note: In this software, the default inverter is supposed to be DMC1500 board.
=====================================================================================
History:
-------------------------------------------------------------------------------------
04-15-2005 Version 3.20: Support both F280x and F281x targets
04-25-2005 Version 3.21: Move EINT and ERTM down to ensure that all initialization
is completed before interrupts are allowed.
================================================================================= */
// Include header files used in the main function
#include "target.h"
#if (DSP_TARGET==F2808)
#include "DSP280x_Device.h"
#endif
#if (DSP_TARGET==F2812)
#include "DSP281x_Device.h"
#endif
#include "IQmathLib.h"
#include "bldc3_1.h"
#include "parameter.h"
#include "build.h"
#include <math.h>
// Prototype statements for functions found within this file.
interrupt void MainISR(void);
// Global variables used in this system
float32 SpeedRef = 0.20; // Speed reference (pu)
float32 T = 0.001/ISR_FREQUENCY; // Samping period (sec), see parameter.h
Uint32 VirtualTimer = 0;
Uint16 ILoopFlag = FALSE;
Uint16 SpeedLoopFlag = FALSE;
int16 DFuncDesired = 0x1A00; // Desired duty cycle (Q15)
_iq CurrentSet = _IQ(0.0031);
Uint16 IsrTicker = 0;
Uint16 BackTicker = 0;
int16 DlogCh1 = 0;
int16 DlogCh2 = 0;
int16 DlogCh3 = 0;
int16 DlogCh4 = 0;
volatile Uint16 EnableFlag = FALSE;
// Instance PID regulator to regulate the DC-bus current and speed
PIDREG3 pid1_idc = PIDREG3_DEFAULTS;
PIDREG3 pid1_spd = PIDREG3_DEFAULTS;
// Instance a PWM driver instance
PWMGEN pwm1 = PWMGEN_DEFAULTS;
// Create an instance of the ADC driver
ADCVALS adc1 = ADCVALS_DEFAULTS;
// Instance a enable PWM drive driver (only for DMC1500)
DRIVE drv1 = DRIVE_DEFAULTS;
// Instance a Hall effect driver
HALL3 hall1 = HALL3_DEFAULTS;
// Instance a ramp controller to smoothly ramp the frequency
RMPCNTL rc1 = RMPCNTL_DEFAULTS;
void main(void)
{
// ******************************************
// Initialization code for DSP_TARGET = F2808
// ******************************************
#if (DSP_TARGET==F2808)
// Initialize System Control registers, PLL, WatchDog, Clocks to default state:
// This function is found in the DSP280x_SysCtrl.c file.
InitSysCtrl();
// Globally synchronize all ePWM modules to the time base clock (TBCLK)
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
// HISPCP prescale register settings, normally it will be set to default values
EALLOW; // This is needed to write to EALLOW protected registers
SysCtrlRegs.HISPCP.all = 0x0000; // SYSCLKOUT/1
EDIS; // This is needed to disable write to EALLOW protected registers
// Disable and clear all CPU interrupts:
DINT;
IER = 0x0000;
IFR = 0x0000;
// Initialize Pie Control Registers To Default State:
// This function is found in the DSP280x_PieCtrl.c file.
InitPieCtrl();
// Initialize the PIE Vector Table To a Known State:
// This function is found in DSP280x_PieVect.c.
// This function populates the PIE vector table with pointers
// to the shell ISR functions found in DSP280x_DefaultIsr.c.
InitPieVectTable();
// User specific functions, Reassign vectors (optional), Enable Interrupts:
// Waiting for enable flag set
while (EnableFlag==FALSE)
{
BackTicker++;
}
// Initialize all the Device Peripherals:
// This function is found in DSP280x_CpuTimers.c
InitCpuTimers();
// Configure CPU-Timer 0 to interrupt every ISR Period:
// 100MHz CPU Freq, ISR Period (in uSeconds)
// This function is found in DSP280x_CpuTimers.c
ConfigCpuTimer(&CpuTimer0, 100, SYSTEM_FREQUENCY*10/ISR_FREQUENCY);
StartCpuTimer0();
// Reassign ISRs.
// Reassign the PIE vector for TINT0 to point to a different
// ISR then the shell routine found in DSP280x_DefaultIsr.c.
// This is done if the user does not want to use the shell ISR routine
// but instead wants to use their own ISR.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &MainISR;
EDIS; // This is needed to disable write to EALLOW protected registers
// Enable PIE group 1 interrupt 7 for TINT0
PieCtrlRegs.PIEIER1.all = M_INT7;
// Enable CPU INT1 for TINT0:
IER |= M_INT1;
#endif
// ******************************************
// Initialization code for DSP_TARGET = F2812
// ******************************************
#if (DSP_TARGET==F2812)
// Initialize System Control registers, PLL, WatchDog, Clocks to default state:
// This function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// HISPCP prescale register settings, normally it will be set to default values
EALLOW; // This is needed to write to EALLOW protected registers
SysCtrlRegs.HISPCP.all = 0x0000; // SYSCLKOUT/1
EDIS; // This is needed to disable write to EALLOW protected registers
// Disable and clear all CPU interrupts:
DINT;
IER = 0x0000;
IFR = 0x0000;
// Initialize Pie Control Registers To Default State:
// This function is found in the DSP281x_PieCtrl.c file.
InitPieCtrl();
// Initialize the PIE Vector Table To a Known State:
// This function is found in DSP281x_PieVect.c.
// This function populates the PIE vector table with pointers
// to the shell ISR functions found in DSP281x_DefaultIsr.c.
InitPieVectTable();
// User specific functions, Reassign vectors (optional), Enable Interrupts:
// Initialize EVA Timer 1/2:
// Setup Timer 1/2 Registers (EV A)
EvaRegs.GPTCONA.all = 0;
// Set the Period for the GP timer 2
EvaRegs.T2PR = SYSTEM_FREQUENCY*1000000*T; // Perscaler X1 (T2), ISR period = T x 1
// Clear the counter/compare Regs for GP timer 2
EvaRegs.T2CNT = 0x0000;
EvaRegs.T2CMPR = 0x0000;
// Waiting for enable flag set
while (EnableFlag==FALSE)
{
BackTicker++;
}
// Enable Period interrupt bits for GP timer 2
EvaRegs.EVAIMRB.bit.T2PINT = 1;
EvaRegs.EVAIFRB.bit.T2PINT = 1;
// Count up, x1, internal clk, disable compare, use own period
EvaRegs.T2CON.all = 0x9040;
// Reassign ISRs.
// Reassign the PIE vector for T2PINT to point to a different
// ISR then the shell routine found in DSP281x_DefaultIsr.c.
// This is done if the user does not want to use the shell ISR routine
// but instead wants to use their own ISR.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.T2PINT = &MainISR;
EDIS; // This is needed to disable write to EALLOW protected registers
// Enable PIE group 3 interrupt 1 for T2PINT
PieCtrlRegs.PIEIER3.all = M_INT1;
// Enable CPU INT3 for T2PINT:
IER |= M_INT3;
#endif
// Initialize PWM module
pwm1.PeriodMax = (SYSTEM_FREQUENCY/PWM_FREQUENCY)*1000; // Asymmetric PWM
pwm1.DutyFunc = DFuncDesired; // DutyFunc = Q15
pwm1.init(&pwm1);
// Initialize DATALOG module
dlog.iptr1 = &DlogCh1;
dlog.iptr2 = &DlogCh2;
dlog.iptr3 = &DlogCh3;
dlog.iptr4 = &DlogCh4;
dlog.trig_value = 0x01;
dlog.size = 0x400;
dlog.prescalar = 1;
dlog.init(&dlog);
// Initialize ADC module
adc1.ChSelect = 0x6543; // for DMC1500 and eZdsp2812/eZdsp2808 boards
adc1.in
zlws.rar_直流无刷
版权申诉
34 浏览量
2022-09-14
19:09:04
上传
评论
收藏 4KB RAR 举报
局外狗
- 粉丝: 66
- 资源: 1万+
最新资源
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
- for daily read
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈