在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!) 创芯人才网--重磅上线啦!
查看: 6948|回复: 2

[原创] 求助:为什么我的程序进不了中断?

[复制链接]
发表于 2009-9-17 15:56:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 cjsb37 于 2013-4-29 09:06 编辑

// Step 0.  Include required header files
         // DSP28_Device.h: device specific definitions #include statements for
         // all of the peripheral .h definition files.
         // DSP28_Example.h is specific for the given example.  
#include "DSP28_Device.h"
#include "math.h"
#include "stdlib.h"
#include "stdio.h"
#define PI 3.1416//π
#define fp 5000  //载波频率5kHZ
#define fc 50 //调制波频率50HZ
#define  M 0.8 //调制比
interrupt void eva_timer1_isr(void);
interrupt void eva_timer2_isr(void);

double cosdata[51]; //storage cos values
double tion[51]; //storage CMPR values
double CMPR[51]; //CMPR values
   Uint16 drag1;
   Uint16 drag2;
   Uint16 TC=0x7530; //TC=30000
   int i;
   int N=0;
   double deltaT;

void main(void)
{
// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
    // This function is found in the DSP28_SysCtrl.c file.
InitSysCtrl();
// Step 2. Select GPIO for the device or for the specific application:
    // This function is found in the DSP28_Gpio.c file.
// InitGpio();  // Skip for this test
// Initalize GPIO for this test here
EALLOW;
// Enable PWM pins
    GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM
   
    EDIS;
   
// Step 3. Initialize PIE vector table:
// The PIE vector table is initialized with pointers to shell Interrupt
    // Service Routines (ISR).  The shell routines are found in DSP28_DefaultIsr.c.
// Insert user specific ISR code in the appropriate shell ISR routine in
    // the DSP28_DefaultIsr.c file.
// Disable and clear all CPU interrupts:
DINT;
IER = 0x0000;
IFR = 0x0000;
// Initialize Pie Control Registers To Default State:
        // This function is found in the DSP28_PieCtrl.c file.
InitPieCtrl();
// Initialize the PIE Vector Table To a Known State:
        // This function is found in DSP28_PieVect.c.
// This function populates the PIE vector table with pointers
        // to the shell ISR functions found in DSP28_DefaultIsr.c.
InitPieVectTable();

// Step 4. Initialize all the Device Peripherals to a known state:
// This function is found in DSP28_InitPeripherals.c
   // InitPeripherals();
//initalize  interrupts count values to 0
    drag1=0;
drag2=0;
// EVA Configure T1PWM, T2PWM, PWM1-PWM6
// Step 1  Initalize the timers
// fc=5kHZ,fs=50HZ,fdsp=150MHZ,Tc=30000*Ttimer
// Initalize EVA Timer1
EvaRegs.GPTCONA.all=0;
EvaRegs.T1PR = (int)(TC/2);       // Timer1 period
  EvaRegs.T1CMPR = 0x0000;     // Timer1 compare
EvaRegs.T1CNT = 0x0001;      // Timer1 counter
    // TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T1CON.all = 0x0842;   //Timer1 continuous up/down mode

// Initalize EVA Timer2
EvaRegs.T2PR = (int)(TC/2);       // Timer2 period
EvaRegs.T2CMPR =0x0000;     // Timer2 compare
EvaRegs.T2CNT = 0x0001;      // Timer2 counter
    // TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T2CON.all = 0x0842;   //Timer2 continuous up/down mode
// Step 2  Setup T1PWM and T2PWM
// Drive T1/T2 PWM by compare logic
EvaRegs.GPTCONA.bit.TCOMPOE = 1;
// Polarity of GP Timer 1 Compare = Active low
EvaRegs.GPTCONA.bit.T1PIN = 1;
// Polarity of GP Timer 2 Compare = Active high
EvaRegs.GPTCONA.bit.T2PIN = 2;
// Step 3  Enable compare for PWM1-PWM6
EvaRegs.CMPR1 = (int)(TC/2);
EvaRegs.CMPR2 = (int)(TC/2);
EvaRegs.CMPR3 = (int)(TC/2);
   
    // Compare action control.  Action that takes place
    // on a cmpare event
    // output pin 1 CMPR1 - active high
    // output pin 2 CMPR1 - active low
    // output pin 3 CMPR2 - active high
    // output pin 4 CMPR2 - active low
    // output pin 5 CMPR3 - active high
    // output pin 6 CMPR3 - active low
    EvaRegs.ACTRA.all = 0x0666;
EvaRegs.DBTCONA.all = 0x0000; // deadband=1.6us
    EvaRegs.COMCONA.all = 0xA600;//使能比较,下溢重载
    EvaRegs.EVAIMRA.bit.T1PINT=1;//使能通用定时器周期中断
   EvaRegs.EVAIFRA.bit.T1PINT=1;//clear interrupt
   EvaRegs.EVAIMRB.bit.T2PINT=0;//disable Timer2 周期中断
   EvaRegs.EVAIFRB.bit.T2PINT=1;//clear interrupt
   EALLOW;
   PieVectTable.T1PINT=&eva_timer1_isr;
   PieVectTable.T2PINT=&eva_timer2_isr;
   EDIS;
   PieCtrlRegs.PIEIFR2.bit.INTx4=1;
   PieCtrlRegs.PIEIER3.bit.INTx1=1;
   
   IER|=(M_INT2|M_INT3);
   EINT;//enable globl interrupts
   ERTM;
   

// storage CMPR values
    N=fp/(2*fc);
deltaT=0.0002;
    for(i=0;i<N+1;i++)
    cosdata=cos(i*PI/N);
for(i=0;i<N;i++)
{
tion[i+1]=cosdata-cosdata[i+1];
tion[i+1]=fabs(tion[i+1]);
tion[i+1]=M*tion[i+1];
tion[i+1]=tion[i+1]/2;
tion[i+1]=tion[i+1]/PI;
tion[i+1]=tion[i+1]/fc;
tion[i+1]=-tion[i+1];
tion[i+1]=tion[i+1]+(deltaT);
tion[i+1]=0.5*tion[i+1];
CMPR[i+1]=tion[i+1]*150000000;
//    tion=150000000000/2*[1/fp-M/(2*PI*fc)*(cosdata-cosdata[i+1])];
    }

    for(;;);

}  
    interrupt void eva_timer1_isr(void)
{
  drag1++;
  if(drag1<51)
  {
  EvaRegs.CMPR1=(int)CMPR[drag1];
     EvaRegs.EVAIFRA.bit.T1PINT=1;
  }
  else
  {
  EvaRegs.CMPR1=(int)(TC/2);
  drag1=0;
  EvaRegs.EVAIFRA.bit.T1PINT=1;
     EvaRegs.EVAIMRB.bit.T2PINT=1;
     EvaRegs.EVAIMRA.bit.T1PINT=0;
  }

}
    interrupt void eva_timer2_isr(void)
{
drag2++;
  if(drag2<51)
  {
  EvaRegs.CMPR2=(int)CMPR[drag2];
  EvaRegs.EVAIFRB.bit.T2PINT=1;
  }
  else
  {
  EvaRegs.CMPR2=(int)(TC/2);
     drag2=0;
     EvaRegs.EVAIFRB.bit.T2PINT=1;
     EvaRegs.EVAIMRB.bit.T2PINT=0;
     EvaRegs.EVAIMRA.bit.T1PINT=1;
  }
}


SPWM的程序,现在是进不了中断,应该还有其他错误,本人初学,希望各位大侠见教了!





发表于 2009-9-17 16:40:48 | 显示全部楼层
如果你是在DSP/BIOS环境下使用的,main函数当中默认是屏蔽中断的,DSP/BIOS自动在main函数后打开全局中断。程序也不允许在main函数有打开中断的语句,main函数只是用来初始化DSP的。所以你的中断不会被响应
 楼主| 发表于 2009-9-18 16:16:15 | 显示全部楼层
问题已经解决,是 没有加
  PieCtrlRegs.PIECRTL.bit.ENPIE=1;// enable PIE
  PieCtrlRegs.PIEIER2.bit.INTx6=1;//enable INT2 interrupts
  PieCtrlRegs.PIEIER4.bit.INTx6=1;//enable INT4 interrupts
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-15 11:32 , Processed in 0.030446 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表