Board logo

标题: 测量中断的方法 [打印本页]

作者: fjczd    时间: 2009-1-4 08:51     标题: 测量中断的方法

这是飞思卡尔的答复

我在定时器溢出中断中试了试可以

但是在外部中断中,似乎还是有问题

这是飞思卡尔的答复

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
}



作者: fjczd    时间: 2009-1-5 11:01

没人

自己顶一下






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0