首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

如何计算两个中断之间的时间间隔?

如何计算两个中断之间的时间间隔?

需要计算两个外部中断产生的时间间隔,有这样的函数么?

比如第一次中断发生后,记下当前的时间,第二次发生后,再记下第二次的时间,然后做减法,就得到这两个中断发生的时间间隔了

请问有这样的函数么?我在PE里也没发现啊

Free running counter
Typical Usage:
(Examples of a typical usage of the bean in user code. For more information please see the page Bean Code Typical Usage.)

Assume bean name is "FC1".

(1)
It's not reasonable to use the bean for time measurement without any methods.
The following code snippet measures the time of the for-cycle in counter ticks.

			MAIN.C

void main(void)
{
  unsigned char i;
  FC1_TTimerValue Time;
  
  FC1_Reset(); /* reset the counter */
  for(i = 0; i < 255; ++i); /* for-cycle */
  
  /* get measured time of whole for-cycle */
  if (FC1_GetCounterValue(&Time) = ERR_OK) {
    /* */
  } 
}

自问自答

自说自话

请问楼主用的是哪个版本的CodeWarrior呢?SPECIAL/BASIC/STANDARD/PROFESSIONAL?

应该是PROFESSIONAL

因为有时间限制,一个月

QUOTE:
以下是引用iehome在2008-12-20 9:08:00的发言:
请问楼主用的是哪个版本的CodeWarrior呢?SPECIAL/BASIC/STANDARD/PROFESSIONAL?

应该是PROFESSIONAL

因为有时间限制,一个月


可以用定时器实现

QUOTE:
以下是引用applespine在2008-12-23 18:09:00的发言:

可以用定时器实现

在开始计时时,让定时器工作,结束计时时,让计时器停止

是这样吧

我现在用的是cw4.7里的PE

想记录中断发生了多长时间,中断名为EInt1_OnInterrupt

我在个中断发生后,用如下方式实现记录其运行了多久.如果这段代码(如下)

FC161_Reset(); // reset the counter
Cpu_Delay100US(500);//
延迟,做中断处理等等

if(FC161_GetTimeUS(&bbb) == ERR_OK) {//记录从reset到当前的时间

ccc = bbb / 60000.0;

放在main(),是可以记录运行时间的,bbb里有数据.但是如果把上述代码放到名为EInt1_OnInterrupt的中断中,同样的代码,bbb却始终为0.

是不是在中断中不能有类似FC161_Reset()之类的函数呢?还是要进行别的什么设置呢?

这是含有FC161_Reset()等语句的中断函数void EInt1_OnInterrupt(void)
{
/* place your EInt1 interrupt procedure body here */

FC161_Reset(); // reset the counter
Cpu_Delay100US(500);//
延迟,做中断处理等等

if(FC161_GetTimeUS(&bbb) == ERR_OK) {//记录从reset到当前的时间

ccc = bbb / 60000.0;
}

如果只是想看一下多少时间,应该不必那么麻烦吧?

在进第一个中断时给一个不用的IO口高电平,在另外一个中断里给低电平.通过示波器看高低电平之间的时间就可以了啊!为什么非要找定时器或函数来实现呢?

QUOTE:
以下是引用kent8411在2008-12-27 14:24:00的发言:

如果只是想看一下多少时间,应该不必那么麻烦吧?

在进第一个中断时给一个不用的IO口高电平,在另外一个中断里给低电平.通过示波器看高低电平之间的时间就可以了啊!为什么非要找定时器或函数来实现呢?

不是看时间,是单片机自动获得这个时间.使用的环境不允许用示波器之类的外部设备

This is the answerd form FREESCALE ENGINEER
1. If this method is used in main() then the result is not very
accurate. 
This method is based on the interrupt - the PE uses a timer that
periodically overflows in defined intervals. Overflow cause an interrupt
where some internal variable is incremented. On the basis of this
variable the PE calculates the time. 
But there are two sources of error:
- resolution of timer
- you have to add time that takes the execution of interrupt service
routine of the timer. This ISR may be executed many times (depending on
the resolution of timer)

So, you may get inaccurate time. 

2. This method cannot be used to measure the running time of ISR. As I
said before, this method is based on interrupt. Nested interrupts are
not supported, so the timer ISR cannot be executed while you are waiting
in another ISR! You will get zero result in this case. 

The most efficient and very simple way is to toggle some pin at the
start and at the end of the interrupt service routine and measure the
interval by the oscilloscope. This is the most precise method not
affected by software.
				

OR 

Run the project in Full Chip Simulation. Step over the desired
commands/functions. We can see the total number of "CPU cycles" in the
Register window in debugger. I would like to note that this feature is
available only in Full Chip Simulation (with all disadvantages of
simulation).

PS. I will cancel the second service request because that's the same
question. 

Thank you for your interest in Freescale Semiconductor products and for
the opportunity to serve you. 

Should you need to contact us with regard to this message, please see
the notes below.
1. If this method is used in main() then the result is not very
accurate. 
This method is based on the interrupt - the PE uses a timer that
periodically overflows in defined intervals. Overflow cause an interrupt
where some internal variable is incremented. On the basis of this
variable the PE calculates the time. 
But there are two sources of error:
- resolution of timer
- you have to add time that takes the execution of interrupt service
routine of the timer. This ISR may be executed many times (depending on
the resolution of timer)

So, you may get inaccurate time. 

2. This method cannot be used to measure the running time of ISR. As I
said before, this method is based on interrupt. Nested interrupts are
not supported, so the timer ISR cannot be executed while you are waiting
in another ISR! You will get zero result in this case. 

The most efficient and very simple way is to toggle some pin at the
start and at the end of the interrupt service routine and measure the
interval by the oscilloscope. This is the most precise method not
affected by software.
				

OR 

Run the project in Full Chip Simulation. Step over the desired
commands/functions. We can see the total number of "CPU cycles" in the
Register window in debugger. I would like to note that this feature is
available only in Full Chip Simulation (with all disadvantages of
simulation).

PS. I will cancel the second service request because that's the same
question. 
Thank you for your interest in Freescale Semiconductor products and for
the opportunity to serve you. 

Should you need to contact us with regard to this message, please see
the notes below.
返回列表