打印

怪了,关了总中断它还进中断!

[复制链接]
1866|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
cruby|  楼主 | 2007-7-19 22:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
AD, dc, ADC, se, BLE
看书上说如果你进入AD中断后,那么这时总中断也应该被关了吧,如果你不在这个中断服务程序里开总中断的话,那么以后就永远不会进入中断了吧?

今天我调程序dsp2407时,写了下面代码:
interrupt void ADCInt(void)
{
    //Get ADC result
    Disable(); //关中断
    count++;
    asm(" clrc SXM");
    j = RESULT0;
    adcResult[i++] = (*j) >> 6;
    if (i == 22)
        i = 0;
    //*ADCTRL2 |= 0x4000;
    SocADC();
    //*IFR = *IFR | 0x0001;
    if (count>65534)
        count = 0;
    //Enable();
}
结果一运行,发现count能不断地增加,意思是它不止一次地进入中断,不知有谁知道是怎么回事?


程序的全部代码如下:#include "DSP2407A.h"

/********* Declare Functions ******/

typedef unsigned int uint;

//Global functions
inline void Disable(void);
inline void Enable(void);
void SysInit(void);
void nothing(void);

//ADC functions
void ADCInit(void);
interrupt void ADCInt(void);
inline void SocADC(void);

//Global variables
volatile uint *j;
static uint adcResult[22];
static uint i = 0;
static uint count = 0;
/************ End ********************/


/************* main ******************/
int main(void)
{
    Disable();
    SysInit();
    ADCInit();
    Enable();
    SocADC();
    while(1);
    return 0;
}
/************* End of main ************/


/************* Implement of functions *******************/
inline void Disable(void)
{
    asm(" setc INTM");
}

inline void Enable(void)
{
    asm(" clrc INTM");
}

void ADCInit(void)
{
    *ADCTRL1 = 0x0000;
    *ADCTRL2 = 0x0600;
    *MAXCONV = 0x0000; //one channel to be converted
    *CHSELSEQ1 = 0x0000; //Channel 0
    *CHSELSEQ2 = 0;
    *CHSELSEQ3 = 0;
    *CHSELSEQ4 = 0;
}

interrupt void ADCInt(void)
{
    //Get ADC result
    Disable();
    count++;
    asm(" clrc SXM");
    j = RESULT0;
    adcResult[i++] = (*j) >> 6;
    if (i == 22)
        i = 0;
    //*ADCTRL2 |= 0x4000;
    SocADC();
    //*IFR = *IFR | 0x0001;
    if (count>65534)
        count = 0;
    //Enable();
}

void SysInit(void)
{
    asm(" setc SXM"); //符号扩展位有效
    asm(" clrc OVM"); //累加器结果正常溢出
    asm(" clrc CNF"); //B0被配置成数据存储空间
    
    *SCSR1 = 0x81fe;
    *WDCR = 0x0e8;
    *IMR = 0x0001; //enable INT1
    *IFR = 0x0ffff; //clear all interrupt flag: write a 1 clears these bits
}

inline void SocADC(void)
{
    *ADCTRL2 |= 0x2000; //set SOC SEQ1
}

void nothing(void)
{
    return;
}
/***************** End ********************************************/

相关帖子

沙发
cruby|  楼主 | 2007-7-20 11:59 | 只看该作者

新发现

程序进入中断时会关总中断,但是出了中断服务程序后就清了标志位,又可以进入中断了;不过我将中断服务程序的代码改成
interrupt void ADCInt(void)
{
    //Get ADC result
    Disable(); //关中断
    count++;
    asm(" clrc SXM");
    j = RESULT0;
    adcResult[i++] = (*j) >> 6;
    if (i == 22)
        i = 0;
    *ADCTRL2 |= 0x4000; //复位通道
    if (count>65534)
        count = 0;
    SocADC();
    Enable(); //加了这句话使程序跑飞了
}
后,发现程序会跑飞,我不就是在最后加了个Enable吗?怎么会造成这么严重的后果呢?

使用特权

评论回复
板凳
cruby|  楼主 | 2007-7-20 17:28 | 只看该作者

继续等待......

使用特权

评论回复
地板
haibian826| | 2007-7-20 21:34 | 只看该作者

用485了吗?

如果用了MAX485芯片,建议换一个485芯片





使用特权

评论回复
5
nxy825715| | 2007-7-23 09:20 | 只看该作者

个人见解:

如果是你所说的AD转换太快,那你可以算算AD转换一次的时间,以及中断服务程序运行一次的时间呀。

使用特权

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

本版积分规则

10

主题

64

帖子

0

粉丝