本帖最后由 zhcj66 于 2019-12-4 08:26 编辑
如题<STM32L051定时器,修改定时参数,不起作用,什么原因?> 输出频率固定在551KHz
无论怎么修改
TimHandle.Init.Period = 5000 - 1;
TimHandle.Init.Prescaler = (uint32_t) ((SystemCoreClock / 10000) - 1);/* Compute the prescaler value to have TIMx counter clock equal to 10 KHz */
参数都无法更改定时频率,
-
- #define TIMx_CLK_ENABLE __HAL_RCC_TIM6_CLK_ENABLE
- /* Definition for TIMx's NVIC */
- #define TIMx_IRQn TIM6_DAC_IRQn
- #define TIMx_IRQHandler TIM6_DAC_IRQHandler
- TIM_HandleTypeDef TimHandle;
- static void ErrorHandler(void)
- {
- /* Infinite loop */
- while(1)
- {
- }
- }
- /* Prescaler declaration */
- uint32_t uwPrescalerValue = 0;
- void TIM6_Init(void)//0.5s-2Hz
- {
- /*##-1- Configure the TIM peripheral #######################################*/
- /* Set TIMx instance */
- TimHandle.Instance = TIM6;
-
- /* Initialize TIMx peripheral as follow:
- + Period = 10000 - 1
- + Prescaler = SystemCoreClock/10000 Note that APB clock = TIMx clock if
- APB prescaler = 1.
- + ClockDivision = 0
- + Counter direction = Up
- */
- TimHandle.Init.Period = 5000 - 1;
- TimHandle.Init.Prescaler = (uint32_t) ((SystemCoreClock / 10000) - 1);/* Compute the prescaler value to have TIMx counter clock equal to 10 KHz */
- TimHandle.Init.ClockDivision = 0;
- TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
- if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
- {
- /* Initialization Error */
- ErrorHandler();
- }
-
- /*##-2- Start the TIM Base generation in interrupt mode ####################*/
- /* Start Channel1 */
- if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
- {
- /* Starting Error */
- ErrorHandler();
- }
- }
- #define TIMx_CLK_ENABLE __HAL_RCC_TIM6_CLK_ENABLE
- void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
- {
- /*##-1- Enable peripherals and GPIO Clocks #################################*/
- /* TIMx Peripheral clock enable */
- TIMx_CLK_ENABLE();
-
- /* The used GPIO (LED2 port) will be configured in the main program through
- LED2 initialization method */
- /*##-2- Configure the NVIC for TIMx ########################################*/
- /* Set the TIMx priority */
- HAL_NVIC_SetPriority(TIMx_IRQn, 0, 0);
-
- /* Enable the TIMx global Interrupt */
- HAL_NVIC_EnableIRQ(TIMx_IRQn);
- }
- void TIMx_IRQHandler(void)
- {
- HAL_GPIO_TogglePin(GPIOH, GPIO_PIN_1);
- }
复制代码
看了官网给出的例程没有清,但是未出问题,因此未写清除标志;在数据手册中确实写了,加上就ok了
一周热门 更多>