嗨piovan,
我不明白你的观点,但这是我对这个例子的理解:
使用TIM2_ICInit()函数可以准确地配置捕获。
因此,如果使用TIM2_ICPSC_DIV,则在4个上升沿之后设置catpture事件(标志)(取决于TIM2_ICPOLARITY_FALLING / TIM2_ICPOLARITYRISING的降低边缘)
因此,为了计算信号的频率(在本例中它是LSI),你应该在下面的公式中乘以4(instaed为8),这样就变成了
LSIClockFreq =(4 * TIM2ClockFreq)/(ICValue2 - ICValue1);
让我们处理时钟频率,计算频率值的一般规则是:
捕获分频器*定时器时钟/(第二次捕获 - 第一次捕获)
在ST提供的示例中,
1-捕获为8(TIM2_ICPSC_DIV8)
2-定时器时钟为2MHz(使用#define TIM2ClockFreq((u32)2000000定义)
提醒:定时器的时钟频率与CPU相同,默认为STM8
似乎运行在2MHz,这就是它定义为2000000的原因。
我希望这清楚,它对你有用。
Herzlich
MCULüfter
以上来自于谷歌翻译
以下为原文
Hi piovan,
I didn't understand exactly your point but this is my understanding of the example:
using TIM2_ICInit() function you configure the capture when exactly it occurs.
So if you use TIM2_ICPSC_DIV, the catpture event (flag) is set after 4 rising edges (orfalling edges that depends on the TIM2_ICPOLARITY_FALLING/TIM2_ICPOLARITYRISING)
consequently to compute the frequency of a signal (in the example it is the LSI) you should multiply by 4 (instaed of 8)in the formula below so it becomes
LSIClockFreq = (4*TIM2ClockFreq) / (ICValue2 - ICValue1);
Let's process the clock frequency, the general rule to compute the frequency value is:
capture divider * timer clock / (second capture - first capture)
In the example provided by ST,
1- the capture is 8 (TIM2_ICPSC_DIV8)
2- the timer clock is 2MHz (It is defined using #define TIM2ClockFreq ((u32)2000000)
Reminder: the timer is clocked at the same clock than the CPU and by default STM8
seems to run at 2MHz that is why it is defined at 2000000.
I hope this clear and it is useful for you.
Herzlich
MCU Lüfter
嗨piovan,
我不明白你的观点,但这是我对这个例子的理解:
使用TIM2_ICInit()函数可以准确地配置捕获。
因此,如果使用TIM2_ICPSC_DIV,则在4个上升沿之后设置catpture事件(标志)(取决于TIM2_ICPOLARITY_FALLING / TIM2_ICPOLARITYRISING的降低边缘)
因此,为了计算信号的频率(在本例中它是LSI),你应该在下面的公式中乘以4(instaed为8),这样就变成了
LSIClockFreq =(4 * TIM2ClockFreq)/(ICValue2 - ICValue1);
让我们处理时钟频率,计算频率值的一般规则是:
捕获分频器*定时器时钟/(第二次捕获 - 第一次捕获)
在ST提供的示例中,
1-捕获为8(TIM2_ICPSC_DIV8)
2-定时器时钟为2MHz(使用#define TIM2ClockFreq((u32)2000000定义)
提醒:定时器的时钟频率与CPU相同,默认为STM8
似乎运行在2MHz,这就是它定义为2000000的原因。
我希望这清楚,它对你有用。
Herzlich
MCULüfter
以上来自于谷歌翻译
以下为原文
Hi piovan,
I didn't understand exactly your point but this is my understanding of the example:
using TIM2_ICInit() function you configure the capture when exactly it occurs.
So if you use TIM2_ICPSC_DIV, the catpture event (flag) is set after 4 rising edges (orfalling edges that depends on the TIM2_ICPOLARITY_FALLING/TIM2_ICPOLARITYRISING)
consequently to compute the frequency of a signal (in the example it is the LSI) you should multiply by 4 (instaed of 8)in the formula below so it becomes
LSIClockFreq = (4*TIM2ClockFreq) / (ICValue2 - ICValue1);
Let's process the clock frequency, the general rule to compute the frequency value is:
capture divider * timer clock / (second capture - first capture)
In the example provided by ST,
1- the capture is 8 (TIM2_ICPSC_DIV8)
2- the timer clock is 2MHz (It is defined using #define TIM2ClockFreq ((u32)2000000)
Reminder: the timer is clocked at the same clock than the CPU and by default STM8
seems to run at 2MHz that is why it is defined at 2000000.
I hope this clear and it is useful for you.
Herzlich
MCU Lüfter
举报