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

如何得到TCNT溢出中断的个数

如何得到TCNT溢出中断的个数

我想获取TCNT溢出中断的个数,该从哪里看呢?我用的是CW4.7 的PE
Well, I would use something like input capture method. The idea is:
- enable the free running timer (TIM)
- at the start save the current value of timer count register TCNT
(first_value)
- enable the timer overflow interrupt
- count the overflow interrupts (overflows++)
- at the end save the current value of TCNT (second_value)
- now calculate the interval: (0x10000 - first_value) + (overflows *
0x10000) + second_value
If the timer didn't overflow then it's simple: second_value -
first_value
It will be necessary to find out appropriate timer prescaler (I don't
know what intervals you want to measure). 
In fact, this method can be used also for ISR's length measuring. But
there's problem with the timer overflow interrupt as I wrote in my
previous reply. If the length of ISR is not greater than the period
between two overflows then I can imagine this method:

interrupt void test(void)
{

					TFLG2_TOF = 1;
					//clear timer overflow flag (interrupt is
disabled)
first_value = TCNT;

				

					//do something here
					


					second_value = TCNT;

					if(TFLG2_TOF == 1)

					length = 0x10000 - first_value + second_value;

					else

					length = second_value - first_value
}

在TCNT的溢出中断里面计数就可以了,

个人BLOG:http://blog.eccn.com/u/107300/index.htm

我的是在PE里生成的,

你说的是自己编写代码吧

PE与自己写代码的优缺点

Processor Expert is a high level programming tool with all advantages
(easy to use, save time...) and disadvantages (the programmer does not
have full control over the code, it's difficult to do "unexpected"
things...).

Of course, we can combine the PE code with our own code. But we have to
make sure that our code doesn't impact the PE code, i.e. rewriting the
registers...


Without PE is's very easy, just a few lines of code...

With PE I would use some bean that enables the free running timer (FC161
for example, as you mentioned earlier) and enable the timer overflow
ISR. Then I would create own global variable that should be incremented
in the timer overflow ISR. The rest is the same as I described in my
previous reply...
PE也有TCNT的溢出中断的,在那里加入你的代码就可以了,。、
个人BLOG:http://blog.eccn.com/u/107300/index.htm
返回列表