在线时间6 小时
UID112466
ST金币0
蝴蝶豆0
注册时间2008-7-31
初级会员
- 最后登录
- 2020-7-9
|
a0a.1 0b0c
在官网下载了最新的库文件,在 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怎么理解?
请帮帮指点. |
|