最近在使用正点原子的阿波罗
开发板做
tiM14的PWM输出实验 要求输出30Hz的。对比手册,TIM14挂在APB1上,APB
时钟为54MHz,可实际使用中发现TIM14的时钟源输出的是432MHz,查看代码,只有在系统时钟初始化时将PLL设为432MHz,代码如下:
GPIO_InitTypeDef GPIO_Initure;
TIM_HandleTypeDef TIM14_Handle;
TIM_OC_InitTypeDef TIM14_CH1Handle;
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_TIM14_CLK_ENABLE();
GPIO_Initure.Pin=GPIO_PIN_9; //PF9 ϽµÑØ´¥·¢£¬ÉÏÀ
GPIO_Initure.Mode=GPIO_MODE_AF_PP; //¸´ÓÃÍÆÍì
GPIO_Initure.Pull=GPIO_PULLUP; //ÉÏÀ
GPIO_Initure.Alternate = GPIO_AF9_TIM14;
HAL_GPIO_Init(GPIOF,&GPIO_Initure);
//base sconfig
TIM14_Handle.Instance = TIM14;
TIM14_Handle.Init.Period = 100;
TIM14_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
TIM14_Handle.Init.Prescaler = (36000 - 1);
TIM14_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
TIM14_Handle.Init.RepetitionCounter = 0; //ÂíÉϸüÐÂARR
HAL_TIM_Base_Init(&TIM14_Handle);
//OC config
TIM14_CH1Handle.OCMode=TIM_OCMODE_PWM1;
TIM14_CH1Handle.Pulse = 50;
TIM14_CH1Handle.OCPolarity=TIM_OCPOLARITY_HIGH;
HAL_TIM_PWM_ConfigChannel(&TIM14_Handle,&TIM14_CH1Handle,TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&TIM14_Handle,TIM_CHANNEL_1);
432M/4/36000 = 3KHz
计数100 刚好30Hz 示波器
测量也是30Hz
一周热门 更多>