你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 7272|回复: 6

STM8L TIMER4 定时中断时间不能调整

[复制链接]

4

主题

24

回帖

0

蝴蝶豆

初级会员

最后登录
2020-7-9
发表于 2014-7-25 11:49:09 | 显示全部楼层 |阅读模式
 在官网下载了最新的库文件,在 stm8l15x_tim4.c文件中看到如下描述:
       ===================================================================      
              TIM4 Driver: how to use it in Timing(Time base) Mode
       =================================================================== 
       To use the Timer in Timing(Time base) mode, the following steps are mandatory:
       
       1. Enable TIM4 clock using CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE) function.
        
       2. Call TIM4_TimeBaseInit() to configure the Time Base unit with the
          corresponding configuration.
          
       3. Enable global interrupts if you need to generate the update interrupt.
          
       4. Enable the corresponding interrupt using the function TIM4_ITConfig(TIM4_IT_Update) 
          
       5. Call the TIM4_Cmd(ENABLE) function to enable the TIM4 counter.
     
 
因此,我写了一个定时的timer:
main.c函数:
 
  Clk_AutoSwitch(CLK_SYSCLKSource_LSI);


  CLK_RTCCLKSwitchOnLSEFailureEnable(); 
  CLK_LSEClockSecuritySystemEnable();


  /* Enable TIM4 CLK */
   CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);
   
  /* TIM4 configuration:
    - TIM4CLK is set to 32 K Hz, the TIM4 Prescaler is equal to 128 so the TIM1 counter
    clock used is 32 KHz / 128 = 250 Hz
   - With 250 Hz we can generate time base:
       max time base is 1.024 s if TIM4_PERIOD = 255 --> (255 + 1) / 250 = 1.024s
       min time base is 8 ms if TIM4_PERIOD = 1   --> (  1 + 1) / 125000 = 8 ms
   - In this examle we need to generate a time base equal to 1 ms
    so TIM4_PERIOD = (0.001 * 125000 - 1) = 124 */
 
 
   /* Time base configuration */
   TIM4_TimeBaseInit(TIM4_Prescaler_128, 250);    //调整参数,可以改变定时时间?
      /* enable interrupts */
   enableInterrupts();
   /* Enable update interrupt */
   TIM4_ITConfig(TIM4_IT_Update, ENABLE);
   /* Clear TIM4 update flag */
  TIM4_ClearFlag(TIM4_FLAG_Update);
   
   /* Enable TIM4 */
   TIM4_Cmd(ENABLE);
 
中断函数:
INTERRUPT_HANDLER(TIM4_UPD_OVF_TRG_IRQHandler, 25)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */


    GPIO_ToggleBits(LED_BL_PORT,LED_BL_PIN);
    TIM4_ClearITPendingBit(TIM4_IT_Update);



}
 
结果,中断可以进入,但是中断时间不可以调整。
按照我的理解,   TIM4_TimeBaseInit(TIM4_Prescaler_128, 250);调整参数会改变触发中断的时间,结果没有任何作用。
实际我的需求是,调整定时时间。这个定时Base怎么理解?
 
请帮帮指点.
<
回复

使用道具 举报

4

主题

24

回帖

0

蝴蝶豆

初级会员

最后登录
2020-7-9
 楼主| 发表于 2014-7-25 11:57:32 | 显示全部楼层

RE:STM8L TIMER4 定时中断时间不能调整

秒表测试了一下,定时的时间也不是我计算的1S
回复 支持 反对

使用道具 举报

4

主题

24

回帖

0

蝴蝶豆

初级会员

最后登录
2020-7-9
 楼主| 发表于 2014-7-25 14:57:45 | 显示全部楼层

RE:STM8L TIMER4 定时中断时间不能调整

问题解决。
上述代码没有问题。
回复 支持 反对

使用道具 举报

1

主题

4

回帖

0

蝴蝶豆

初级会员

最后登录
2018-9-26
发表于 2015-2-6 22:32:52 | 显示全部楼层
问题怎么解决的?能共享下吗?
回复 支持 反对

使用道具 举报

1

主题

120

回帖

0

蝴蝶豆

中级会员

最后登录
2015-6-16
发表于 2015-2-7 00:30:17 | 显示全部楼层
xxxxxxxxxx.jpg
回复 支持 反对

使用道具 举报

1

主题

179

回帖

0

蝴蝶豆

中级会员

最后登录
2015-6-16
发表于 2015-2-7 10:46:35 | 显示全部楼层
stm32.jpg
回复 支持 反对

使用道具 举报

2

主题

397

回帖

0

蝴蝶豆

高级会员

最后登录
2016-12-21
发表于 2015-2-7 23:17:23 | 显示全部楼层
怎么解决的
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版