打印
[DSP编程]

EPWM中断启动的问题

[复制链接]
2205|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lzx18570633112|  楼主 | 2019-3-29 16:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
PWM, dc, AD, ADC, pi
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include "DSP2833x_GlobalConst.h"
#include "DSP2833x_Globalpara.h"
#include ".\source\app\AdcProcess.c"
#include ".\source\app\Timer.c"
#include ".\source\app\MotorCtrl.c"
#include "485.c"
#include "ECana.c"
#include "dmctype.h"
#include "rmp_cntl.h"
//#include "AD.h"
//#include "DA.h"
#include "Resolver.h"

CLARKE clarkeu=CLARKE_DEFAULTS;
CLARKE clarkei=CLARKE_DEFAULTS;
PARK parku=PARK_DEFAULTS;
PARK parki=PARK_DEFAULTS;
PIDREG3 pid1_PLL =PIDREG3_DEFAULTS;
PIDREG3 pid1_Speed =PIDREG3_DEFAULTS;
PIDREG3 pid1_idloop=PIDREG3_DEFAULTS;
PIDREG3 pid1_iqloop=PIDREG3_DEFAULTS;
IPARK iparku=IPARK_DEFAULTS;
PIDREG3 pid1_vdc =PIDREG3_DEFAULTS;
SPEED_ESTIMATION speed1=SPEED_ESTIMATION_DEFAULTS;
RMPCNTL rc1=RMPCNTL_DEFAULTS;

//AD Adv=AD_DEFAULTS;
//DA DAv=DA_DEFAULTS;
RESOLVER resolver=RESOLVER_DEFAULTS;

//interrupt void MainIsr();
//interrupt void AdcIsr();
//interrupt void CpuTimer0Isr(void);
//interrupt void CpuTimer1Isr(void);
//interrupt void ISRExint(void);
//interrupt void ECanaISR(void);
//void InitMboxa(void);
//void ClrStatup(void);
float32 Ualpha1=0,Ubeta1=0,Ref_theta=0;
float Freq1=0;
int kk;
float32 minus=0,oldElecTheta=0;
Uint16 ledcont=0;
Uint16 INT3Count=0;
float32 Cosine1,Sine1;
float theta1=0,vdc1flt=0;
Uint32 iqcount=0;
Uint32 ao1=0;
int key=0,key1count=0,key2count=0;
//int kji=0,kreset=0,nreset=0;
/************************************************采样中断*******************************************************/

Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Current1[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Uint16 CURRENT1 = 0;
Uint16 iLo = 0;
Uint16 ILO_REF = 41800;
Uint16 ILo = 0;
Uint16 ILo_ref = 0;
Uint16 ILo_error = 0;
Uint16 ILo_Inter = 0;
Uint16 ILo_out = 0;
Uint16 Uzaibo = 0;
Uint16 Uzaibo_out = 0;
Uint16 ILo_P = 0.01;
Uint16 ILo_I = 0.10;

/*************************************************主函数*******************************************************/
#pragma CODE_SECTION(main,"ramfuncs")
void main(void)
{
DSP28x_usDelay(5000);
// Initialize System Control registers, PLL, WatchDog, Clocks to default state
// This function is found in the DSP280x_SysCtrl.c file
InitSysCtrl();
InitGpio();
InitSci();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitCpuTimers();
InitAdc();

// EALLOW;
// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
// EDIS;

InitEPwm();

// EALLOW;
// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
// EDIS;

#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif

EDIS;
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK;        // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
EALLOW;

DINT;

InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT = &adc_isr;
PieVectTable.EPWM1_INT = &MainIsr;
EDIS; // This is needed to disable write to EALLOW protected registers

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;

InitAdc(); // For this example, init the ADC
InitEPwm();

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;

PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |=M_INT1; //开放CPUTimer0/AD/ePWM
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
IER |=M_INT3; //开放CPUTimer0/AD/ePWM
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

EALLOW;
// Configure ADC
AdcRegs.ADCTRL3.bit.SMODE_SEL= 0x0; //同步采样模式
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xf; //ADC采样时间选择
AdcRegs.ADCTRL3.bit.ADCCLKPS = OSCCLOCK; //ADC内核分频
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; //级联工作方式
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; //级联工作方式
AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 1 conv's on SEQ1
//AdcRegs.ADCTRL1.bit.CONT_RUN = 1; //连续采样
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x1; //设置CONV0 为第一个通道
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; //Enable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; //Enable SEQ1 interrupt (every EOS)
//AdcRegs.ADCTRL1.bit.CONT_RUN = 1; //连续运行模式
//AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; //完成排序后,排序器指针回到最初状态
EDIS;

for(;;)
{
}

}
/**********************************************************EPWM中断程序*******************************************************************/
#pragma CODE_SECTION(MainIsr,"ramfuncs")
interrupt void MainIsr(void)
{
//        float32 vdcMaxPU;
//        float32 iMaxPU;
//        float Kiu,Kiv;

ILo = iLo;
ILo_ref = ILO_REF;
ILo_error = ILo_ref-ILo;
ILo_Inter += ILo_error*ILo_I;
if(ILo_Inter > 400)
ILo_Inter = 400;
else if(ILo_Inter < -400)
ILo_Inter = -400;
ILo_out = ILo_Inter+ILo_P*ILo_error;
if(ILo_out > 500)
ILo_out = 500;
else if(ILo_out < -500)
ILo_out = -500;
Uzaibo = ILo_out/500.0;
// Uzaibo_out = -Uzaibo*30000/2+30000/2;

EPwm2Regs.TBPHS.half.TBPHS = 0.0*30000;//1.06*30000;
EPwm3Regs.TBPHS.half.TBPHS = 1.0*30000;//1.1538*30000;
EPwm4Regs.TBPHS.half.TBPHS = (1.1+0.5*Uzaibo)*30000;//0.1438*30000;
EPwm5Regs.TBPHS.half.TBPHS = (0.1+0.5*Uzaibo)*30000;//0.1438*30000;

EPwm2Regs.CMPA.half.CMPA = (0.4+Uzaibo)*30000;
EPwm3Regs.CMPA.half.CMPA = (0.4+Uzaibo)*30000;
EPwm4Regs.CMPA.half.CMPA = (0.4+Uzaibo)*30000;
EPwm5Regs.CMPA.half.CMPA = (0.4+Uzaibo)*30000;

//EPwm1Regs.CMPA.half.CMPA=30000/2;
//EPwm2Regs.CMPA.half.CMPA=30000/2;

EPwm1Regs.ETCLR.bit.INT =1;
DINT;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; //响应本次接收中断;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;        //开CPUTimer0中断
}
/********************************************************************采样中断*************************************************************/
#pragma CODE_SECTION(adc_isr,"ramfuncs")
interrupt void adc_isr(void)
{

Current1[ConversionCount] = AdcRegs.ADCRESULT0 >>4;
CURRENT1 +=Current1[ConversionCount];

// If 40 conversions have been logged, start over
if(ConversionCount == 19)
{
iLo = CURRENT1;
ConversionCount = 0;
CURRENT1= 0;

}
else
{
ConversionCount++;
}

// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE

return;
}
/**************************************************************************************************************************************/
这是我的主函数,我要实现的功能是采集平均电流,并用PI闭环跟踪给定电流!请问我的程序问题在哪里?

使用特权

评论回复

相关帖子

沙发
Cjy_JDxy| | 2019-3-29 17:08 | 只看该作者
你先说有什么问题啊

使用特权

评论回复
板凳
lzx18570633112|  楼主 | 2019-3-29 18:18 | 只看该作者
Cjy_JDxy 发表于 2019-3-29 17:08
你先说有什么问题啊

程序跑不通啊,是不是EPWM中断没有触发,因为我不知道EPWM中断是怎么触发的

使用特权

评论回复
地板
Cjy_JDxy| | 2019-3-30 08:31 | 只看该作者
设个断点看看,看看进没进中断

使用特权

评论回复
评论
lzx18570633112 2019-3-30 10:42 回复TA
断电执行到InitPieVectTable();时应该在下一步进入中断,但是我这个程序没有,请问这是为什么? 
5
蒋博1026| | 2019-3-30 13:28 | 只看该作者
这种状况只能一步一步的仿真了,也可以写有返回值的函数,通过返回值看看函数运行的是否正确。

使用特权

评论回复
6
蒋博1026| | 2019-3-30 13:35 | 只看该作者
还就是在中断里点亮一个LED,反转LED的状态也行,通过现象来判断是否进中断了。。

使用特权

评论回复
7
Cjy_JDxy| | 2019-3-30 16:01 | 只看该作者
Cjy_JDxy 发表于 2019-3-30 08:31
设个断点看看,看看进没进中断

不是吧?你还没配置EPWM呢,怎么可能进入中断呢?
看你好像EPWM中断触发ADC吧

使用特权

评论回复
8
pplo| | 2019-4-1 15:43 | 只看该作者
你的中断有:ADC_ISR,EPWM1_ISR,CPU_TIME0
你没有把InitEPwm()程序贴出来,所以不知道,你有没初始化EPWM1_INT?,或者触发ADC_INT?
我记得还需要看一下InitPeripheralClocks()这个程序,里面有各个时钟的使能,不知道你有没有使能?
多看看TI的文档吧!
问题也要描述清楚啊,这样别人也能更好的帮忙!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

24

主题

33

帖子

0

粉丝