打印

求救!中断、定时器问题,请各位高手给指点一下!

[复制链接]
1704|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ccjchen|  楼主 | 2009-7-13 13:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
外部两个中断不同时发生,用定时器1来对这两个中断发生的时间进行计时,不知为什么每次计时两个中断发生的时间竟然是一样的,请各位前辈给指点一下!
下面是我的程序:
#include <csl.h>
#include <csl_emifa.h>
#include <csl_irq.h>
#include <csl_chip.h>
#include <csl_timer.h>
#include <csl_gpio.h>
#include <stdio.h>
#include "seeddm642.h"
#include "seeddm642_uart.h"


static TIMER_Handle hTimer1;

static Uint32 TimerEventId;

static unsigned int cnt = 0;
static unsigned int t1 = 0;
static unsigned int t2 = 0;
static unsigned int v = 0;
static Uint32 TimerControl = 

            

    TIMER_CTL_RMK

    (

        TIMER_CTL_SPND_EMUSTOP,

          TIMER_CTL_INVINP_NO,         // TINP inverter control(INVINP)

          TIMER_CTL_CLKSRC_CPUOVR8,    // Timer input clock source (CLKSRC)

        TIMER_CTL_CP_PULSE,         // Clock/pulse mode(CP)

        TIMER_CTL_HLD_YES,             // Hold(HLD)

        TIMER_CTL_GO_NO,             // Go bit(GO)-

                                    //   resets & starts timer counter

        TIMER_CTL_PWID_ONE,         // Pulse width(PWID)-

                                    //   used only in pulse mode

        TIMER_CTL_DATOUT_0,         // Data output (DATOUT)

        TIMER_CTL_INVOUT_NO,         // TOUT inverter control (INVOUT) 

        TIMER_CTL_FUNC_GPIO         // Function of TOUT pin(FUNC)

    );     


extern far void vectors();
static unsigned char flag ;
/*此程序可将四个采集口的数据经过Video Port0送出*/
void main()
{
    TIMER_Config myTimConfig;
    CSL_init(); 
    IRQ_setVecs(vectors);   
    hTimer1 = TIMER_open(TIMER_DEV1, 0);
    TimerEventId = TIMER_getEventId(hTimer1);
    GPIO_RSET(GPEN,0x1E0);//
    GPIO_RSET(GPDIR,0x100);/*将GPIO做为输出*/
    GPIO_RSET(GPVAL,0x000);
    IRQ_globalDisable();
    IRQ_nmiDisable();
    IRQ_nmiEnable();
    IRQ_globalEnable();
    IRQ_map(TimerEventId, 15);
    IRQ_map(IRQ_EVT_EXTINT6,6);
    IRQ_map(IRQ_EVT_EXTINT7,7);    
    IRQ_reset(TimerEventId);
    IRQ_reset(IRQ_EVT_EXTINT6);
    IRQ_reset(IRQ_EVT_EXTINT7);
    IRQ_RSET(EXTPOL,0x0E);//下降沿中断
     myTimConfig.cnt = 0x0;
    myTimConfig.ctl = TimerControl;
    myTimConfig.prd = 0x00124f8; //定时1ms
    IRQ_enable(TimerEventId);        
    IRQ_enable(IRQ_EVT_EXTINT6);
    IRQ_enable(IRQ_EVT_EXTINT7);
    TIMER_config(hTimer1, &myTimConfig);
    
     TIMER_start(hTimer1); 
   
     while(1);                
}

interrupt void ext_isr6()
{
    
   t1 = 0.5+cnt*75000*8/600000;//75000对应myTimConfig.prd = 0x00124f8
      printf("t1 : %d ",t1); 
}     

interrupt void ext_isr7()
{
   t2 =0.5+ cnt*75000*8/600000;
   printf("t2 : %d ",t2);
}

interrupt void CLK_cnt()
{
   cnt++;
}

以下是仿真结果:
t1 : 68//中断不同时发生t1,t2应该是不一样的啊,
t2 : 68//不知仿真结果为什么是一样的?
t1 : 165
t2 : 165
t1 : 348
t2 : 348
t1 : 531
t2 : 531
t1 : 713
t2 : 713
t1 : 893
t2 : 893
t1 : 1076
t2 : 1076
t1 : 1219
t2 : 1219

相关帖子

沙发
ccjchen|  楼主 | 2009-7-14 09:53 | 只看该作者

不知是我的定时算法有问题,还是中断有问题

恳请各位前辈给指点一下!

使用特权

评论回复
板凳
ccjchen|  楼主 | 2009-7-15 10:55 | 只看该作者

我 设置的外部中断6和7时间间隔至少为十几ms

而定时器时间间隔为1ms,为什么测试的数据t1和t2却是一样的呢?

使用特权

评论回复
地板
ccjchen|  楼主 | 2009-7-15 15:19 | 只看该作者

又反复进行了实验,发现好像是printf函数的问题

printf运行所需时间比较长,不过如果我在DSP/bios中用LOG_printf的话应该怎么将t1、t2显示出来呢?

使用特权

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

本版积分规则

175

主题

446

帖子

1

粉丝