嗨dragomir.raimond,谢谢你的回复。 ARR的值由TIM2_Deinit()设置为0xFFFF;然后将其更改为(大约值)0x0344
TIM2_TimeBaseInit()在它启动的计时器之前:
void TIM2_DeInit(void)
{
TIM2-> CR1 =(uint8_t)TIM2_CR1_RESET_VALUE;
TIM2-> IER =(uint8_t)TIM2_IER_RESET_VALUE;
...
TIM2-> ARRH =(uint8_t)TIM2_ARRH_RESET_VALUE;
TIM2-> ARRL =(uint8_t)TIM2_ARRL_RESET_VALUE;
...
}
void TIM2_TimeBaseInit(TIM2_Prescaler_TypeDef TIM2_Prescaler,
uint16_t TIM2_Period)
{
/ *设置预分频器值* /
TIM2-> PSCR =(uint8_t)(TIM2_Prescaler);
/ *设置自动重载值* /
TIM2-> ARRH =(uint8_t)(TIM2_Period> 8);
TIM2-> ARRL =(uint8_t)(TIM2_Period);
}
我已经尝试在TIM2_> SR1更新位(0x01)之前立即通过设置TIM2-> CR1的CEN位来激活定时器,因为我认为它应该阻止由于前面的设置引起的任何中断。它没有帮助 - 我仍然得到立即中断。
>为什么不直接使用寄存器?
这是一个外部客户的一次性项目,可能是我唯一一次使用STM8;我正在使用ST的HAL库来加速开发,因为我没有任何其他基于STM8的项目即将出现,并且不想花太多时间仔细研究寄存器定义,因为整个软件开发时间只有一周左右。
目前我刚刚在中断处理程序中使用静态bool来忽略它第一次运行,但我想要一个更好的方法。
再次感谢,
托德
以上来自于谷歌翻译
以下为原文
Hi dragomir.raimond, and thanks for the reply. The value of ARR set by to 0xFFFF by TIM2_Deinit(); it is then changed to (a value of approximately) 0x0344 by
TIM2_TimeBaseInit() before the timer it started:
void TIM2_DeInit(void)
{
TIM2->CR1 = (uint8_t)TIM2_CR1_RESET_VALUE;
TIM2->IER = (uint8_t)TIM2_IER_RESET_VALUE;
...
TIM2->ARRH = (uint8_t)TIM2_ARRH_RESET_VALUE;
TIM2->ARRL = (uint8_t)TIM2_ARRL_RESET_VALUE;
...
}
void TIM2_TimeBaseInit( TIM2_Prescaler_TypeDef TIM2_Prescaler,
uint16_t TIM2_Period)
{
/* Set the Prescaler value */
TIM2->PSCR = (uint8_t)(TIM2_Prescaler);
/* Set the Autoreload value */
TIM2->ARRH = (uint8_t)(TIM2_Period >> 8);
TIM2->ARRL = (uint8_t)(TIM2_Period);
}
I have tried clearing the TIM2->SR1 update bit (0x01) immediately before TIM2_Cmd() activates the timer by setting TIM2->CR1's CEN bit as I figured that should block any interrupts due to the preceding setup. It doesn't help though -- I still get that immediate interrupt.
> Why you don't work with registers directly?
This is a one-off project for an external customer and may be the only time I use an STM8; I was using ST's HAL library to expedite the development as I don't have any other STM8-based projects coming up and didn't want to spend too much time poring over register definitions as the whole software development time was only around a week.
At the moment I've just used a static bool in the interrupt handler to ignore the first time it runs, but I wanted a better way.
Thanks again,
Todd
嗨dragomir.raimond,谢谢你的回复。 ARR的值由TIM2_Deinit()设置为0xFFFF;然后将其更改为(大约值)0x0344
TIM2_TimeBaseInit()在它启动的计时器之前:
void TIM2_DeInit(void)
{
TIM2-> CR1 =(uint8_t)TIM2_CR1_RESET_VALUE;
TIM2-> IER =(uint8_t)TIM2_IER_RESET_VALUE;
...
TIM2-> ARRH =(uint8_t)TIM2_ARRH_RESET_VALUE;
TIM2-> ARRL =(uint8_t)TIM2_ARRL_RESET_VALUE;
...
}
void TIM2_TimeBaseInit(TIM2_Prescaler_TypeDef TIM2_Prescaler,
uint16_t TIM2_Period)
{
/ *设置预分频器值* /
TIM2-> PSCR =(uint8_t)(TIM2_Prescaler);
/ *设置自动重载值* /
TIM2-> ARRH =(uint8_t)(TIM2_Period> 8);
TIM2-> ARRL =(uint8_t)(TIM2_Period);
}
我已经尝试在TIM2_> SR1更新位(0x01)之前立即通过设置TIM2-> CR1的CEN位来激活定时器,因为我认为它应该阻止由于前面的设置引起的任何中断。它没有帮助 - 我仍然得到立即中断。
>为什么不直接使用寄存器?
这是一个外部客户的一次性项目,可能是我唯一一次使用STM8;我正在使用ST的HAL库来加速开发,因为我没有任何其他基于STM8的项目即将出现,并且不想花太多时间仔细研究寄存器定义,因为整个软件开发时间只有一周左右。
目前我刚刚在中断处理程序中使用静态bool来忽略它第一次运行,但我想要一个更好的方法。
再次感谢,
托德
以上来自于谷歌翻译
以下为原文
Hi dragomir.raimond, and thanks for the reply. The value of ARR set by to 0xFFFF by TIM2_Deinit(); it is then changed to (a value of approximately) 0x0344 by
TIM2_TimeBaseInit() before the timer it started:
void TIM2_DeInit(void)
{
TIM2->CR1 = (uint8_t)TIM2_CR1_RESET_VALUE;
TIM2->IER = (uint8_t)TIM2_IER_RESET_VALUE;
...
TIM2->ARRH = (uint8_t)TIM2_ARRH_RESET_VALUE;
TIM2->ARRL = (uint8_t)TIM2_ARRL_RESET_VALUE;
...
}
void TIM2_TimeBaseInit( TIM2_Prescaler_TypeDef TIM2_Prescaler,
uint16_t TIM2_Period)
{
/* Set the Prescaler value */
TIM2->PSCR = (uint8_t)(TIM2_Prescaler);
/* Set the Autoreload value */
TIM2->ARRH = (uint8_t)(TIM2_Period >> 8);
TIM2->ARRL = (uint8_t)(TIM2_Period);
}
I have tried clearing the TIM2->SR1 update bit (0x01) immediately before TIM2_Cmd() activates the timer by setting TIM2->CR1's CEN bit as I figured that should block any interrupts due to the preceding setup. It doesn't help though -- I still get that immediate interrupt.
> Why you don't work with registers directly?
This is a one-off project for an external customer and may be the only time I use an STM8; I was using ST's HAL library to expedite the development as I don't have any other STM8-based projects coming up and didn't want to spend too much time poring over register definitions as the whole software development time was only around a week.
At the moment I've just used a static bool in the interrupt handler to ignore the first time it runs, but I wanted a better way.
Thanks again,
Todd
举报