ST意法半导体
直播中

殷晓婷

7年用户 141经验值
私信 关注
[问答]

STM8S103F3 TIM4是否自动重载上升计数器?

STM8S103F3 tiM4是否自动重载上升计数器?

以上来自于谷歌翻译


以下为原文



Is STM8S103F3 TIM4 auto-reload up-counter ?

回帖(5)

殷晓婷

2019-4-3 14:53:09
我可以成功使用TIM4中断,如下代码:
 
 
 // TIM4自动重载向上计数器?
 // TIM4_TimeBaseInit(TIM4_PRESCALER_128,128); // (一个)
 TIM4_TimeBaseInit(TIM4_PRESCALER_128,16); //(B)
 
 // TIM4_ITConfig(TIM4_IT_UPDATE,ENABLE);
 TIM4_ITConfig(TIM4_CR1_ARPE | TIM4_CR1_URS | TIM4_CR1_CEN,ENABLE);
 
 / *启用TIM4 * /
 TIM4_Cmd(ENABLE);
 
但我不确定TIM4是否作为STM8S103F3自动重载向上计数器
RM0016(第239页)文档,因为(B)语句比(A)更快地切换LED。这意味着(B)的TIM4中断周期更短。
 
 
 
[此消息由以下人员编辑:jeffrey.chang168于14-12-2009 15:54]
 
 
[此消息由以下人员编辑:jeffrey.chang168于15-12-2009 00:12]

以上来自于谷歌翻译


以下为原文




I can use TIM4 interrupt successfully as following codes:


// TIM4 auto-reload up-counter ?  
//TIM4_TimeBaseInit(TIM4_PRESCALER_128, 128); // (A)  
TIM4_TimeBaseInit(TIM4_PRESCALER_128, 16); // (B)  

//TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);  
TIM4_ITConfig(TIM4_CR1_ARPE | TIM4_CR1_URS | TIM4_CR1_CEN, ENABLE);  

/* Enable TIM4 */  
TIM4_Cmd(ENABLE);  

But I am NOT sure whether the TIM4 is auto-reload up-counter as STM8S103F3  
RM0016 (page 239) document since the (B) statement toggles the LED faster than the (A) one. It means that the TIM4 interrupt period of (B) is shorter.  



[ This message was edited by: jeffrey.chang168 on 14-12-2009 15:54 ]  


[ This message was edited by: jeffrey.chang168 on 15-12-2009 00:12 ]
举报

冬妮

2019-4-3 15:08:26
嗨jeffrey.chang168,
 
 
如RM0016中所述,TIM4是自动重载向上计数器计时器。
下面是对理论的解释!
 
// TIM4_TimeBaseInit(TIM4_PRESCALER_128,128); // (一个)
如果以默认系统时钟配置(2MHz)运行系统,则TIM4计数器的时钟频率为2000000 /预分频器= 2000000/128 = 15 625 Hz,因此每次产生更新中断(128 + 1)/ 15625 = 8.256 ms
 
TIM4_TimeBaseInit(TIM4_PRESCALER_128,16); //(B)
如果以默认系统时钟配置(2MHz)运行系统,则TIM4计数器的时钟频率为2000000 /预分频器= 2000000/128 = 15 625 Hz,因此每次生成更新中断(16 + 1)/ 15625 = 1.088 ms
 
如果仍然不清楚,请告诉我。
 
问候,

以上来自于谷歌翻译


以下为原文




Hi jeffrey.chang168,


As mentioned in the RM0016, the TIM4 is auto-reload up-counter timer.  
An below the explanation of the theory !  

//TIM4_TimeBaseInit(TIM4_PRESCALER_128, 128); // (A)  
If you are running your system in the default system clock configuration (2MHz), the TIM4 counter is clocked by 2000000 / prescaler = 2000000 / 128 = 15 625 Hz so update interrupt is generated each (128 + 1) / 15625 = 8.256 ms  

TIM4_TimeBaseInit(TIM4_PRESCALER_128, 16); // (B)  
If you are running your system in the default system clock configuration (2MHz), the TIM4 counter is clocked by 2000000 / prescaler = 2000000 / 128 = 15 625 Hz so update interrupt is generated each (16 + 1) / 15625 = 1.088 ms  

Let me know if that stills unclear.  

Regards,
举报

殷晓婷

2019-4-3 15:20:06
引用:
 
 
2009年12月15日10:39,Anonymous写道:
嗨jeffrey.chang168,
 
如RM0016中所述,TIM4是自动重载向上计数器计时器。
下面是对理论的解释!
 
// TIM4_TimeBaseInit(TIM4_PRESCALER_128,128); // (一个)
如果以默认系统时钟配置(2MHz)运行系统,则TIM4计数器的时钟频率为2000000 /预分频器= 2000000/128 = 15 625 Hz,因此每次产生更新中断(128 + 1)/ 15625 = 8.256 ms
 
TIM4_TimeBaseInit(TIM4_PRESCALER_128,16); //(B)
如果以默认系统时钟配置(2MHz)运行系统,则TIM4计数器的时钟频率为2000000 /预分频器= 2000000/128 = 15 625 Hz,因此每次生成更新中断(16 + 1)/ 15625 = 1.088 ms
 
如果仍然不清楚,请告诉我。
 
问候,
 
 
 
如RM0016第239页中所述,TIM4中断是在计数器溢出时产生的。所以UP计数器在溢出时自动重载。
情况A)128,129,...,255,0,128
因此,中断周期A应为(256 - 128)/ 15625 = 128/15625。
案例B)16,17,......,255,16
因此中断周期B应为(256 - 16)/ 15625 = 240/15625。
 
期间A< B期
 
//////////////////////////////////////
如果TIM4是自动重载DOWN计数器。
情况A)128,127,...,1,0,128
因此,中断周期A应为(128 + 1)/ 15625 = 129/15625。
案例B)16,15,...,1,0,16
因此,中断周期应为(16 + 1)/ 15625 = 17/15625。
 
期间A> B期
 
 
哪一个是正确的?
 
 
 
 
[此消息由以下人员编辑:jeffrey.chang168于15-12-2009 16:59发表]

以上来自于谷歌翻译


以下为原文





Quote:


On 15-12-2009 at 10:39, Anonymous wrote:  
Hi jeffrey.chang168,  
  
As mentioned in the RM0016, the TIM4 is auto-reload up-counter timer.  
An below the explanation of the theory !  
  
//TIM4_TimeBaseInit(TIM4_PRESCALER_128, 128); // (A)  
If you are running your system in the default system clock configuration (2MHz), the TIM4 counter is clocked by 2000000 / prescaler = 2000000 / 128 = 15 625 Hz so update interrupt is generated each (128 + 1) / 15625 = 8.256 ms  
  
TIM4_TimeBaseInit(TIM4_PRESCALER_128, 16); // (B)  
If you are running your system in the default system clock configuration (2MHz), the TIM4 counter is clocked by 2000000 / prescaler = 2000000 / 128 = 15 625 Hz so update interrupt is generated each (16 + 1) / 15625 = 1.088 ms  
  
Let me know if that stills unclear.  
  
Regards,  
  


As mentioned in RM0016 page 239, the TIM4 interrupt is generated on counter overflow. So the UP counter is auto-reload on overflow.  
Case A) 128, 129, ..., 255, 0, 128  
so Interrupt Period A should be (256 - 128) / 15625 = 128/15625.  
Case B) 16, 17, ..., 255, 16  
so Interrupt Period B should be (256 - 16) / 15625 = 240/15625.  

Period A < Period B  

//////////////////////////////////////  
If TIM4 is auto-reload DOWN counter.  
Case A) 128, 127, ..., 1, 0, 128  
so Interrupt Period A should be (128 + 1) / 15625 = 129/15625.  
Case B) 16, 15, ..., 1, 0, 16  
so Interrup Period should be (16 + 1) / 15625 = 17/15625.  

Period A > Period B  


Which one is correct ?  




[ This message was edited by: jeffrey.chang168 on 15-12-2009 16:59 ]
举报

冬妮

2019-4-3 15:31:16
嗨jeffrey.chang168,
 
 
当我开始在STM8上开发时,我想和你一样!
当计数器(CNTR寄存器)达到自动重载值(ARR寄存器)时,发生溢出事件。
这在TIM1部分解释。
 
计数器溢出时产生TIM4中断。所以UP计数器在溢出时自动重载。
情况A)0,1,...,128在128溢出事件
所以中断周期A是(128 + 1)/ 15625 = 8.256 ms
情况B)0,1,...,15在16溢出事件
因此中断周期B为(16 + 1)/ 15625 = 1.088 ms。
 
我希望现在很清楚。
问候,

以上来自于谷歌翻译


以下为原文




Hi jeffrey.chang168,


I thought like you when I started developping on STM8 !  
The overflow event occurs when the counter (CNTR register) reaches the Auto-Reload value (ARR register).  
That is explained in TIM1 section.  

the TIM4 interrupt is generated on counter overflow. So the UP counter is auto-reload on overflow.  
Case A) 0, 1, ..., 128 at 128 the overflows event  
so Interrupt Period A is (128 + 1) / 15625 = 8.256 ms  
Case B) 0, 1, ..., 15 at 16 the overflows event  
so Interrupt Period B is (16 + 1) / 15625 = 1.088 ms.  

I wish It is clear now.  
Regards,
举报

更多回帖

发帖
×
20
完善资料,
赚取积分