中级会员
- 积分
- 345
- 金钱
- 345
- 注册时间
- 2016-12-5
- 在线时间
- 57 小时
|
10金钱
遇到一个问题,
stm32f407 tim3 PWM CH3-PB0PWM1模式,有效电平是高电平
初始化的时候,使能了CH3通道,PB0立马从高电平变成了低电平。然后使能定时器计数,第一个周期的该IO口一直是低电平,直到定时器的第二个周期,才翻转成有效电平-高电平。
代码如下
- TIM_InitStruct.Prescaler = 6;
- TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
- TIM_InitStruct.Autoreload = 23;
- TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
- LL_TIM_Init(TIM3, &TIM_InitStruct);
- LL_TIM_EnableARRPreload(TIM3);
- LL_TIM_SetClockSource(TIM3, LL_TIM_CLOCKSOURCE_INTERNAL);
- TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_FROZEN;
- TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
- TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
- TIM_OC_InitStruct.CompareValue = 10;
- TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
- LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
- LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH2);
- LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH3);
- TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
- TIM_OC_InitStruct.CompareValue = 9;
- LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
- LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH3);
- LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
- LL_TIM_DisableMasterSlaveMode(TIM3);
- LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH2);
- /* USER CODE BEGIN TIM3_Init 2 */
- /* USER CODE END TIM3_Init 2 */
- LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
- /**TIM3 GPIO Configuration
- PB0 ------> TIM3_CH3
- */
- GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
- GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
- GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
- GPIO_InitStruct.Alternate = LL_GPIO_AF_2;
- LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
复制代码 使能代码如下
- LL_TIM_SetCounter(TIM3,0);//清0,重新计数
- LL_TIM_ClearFlag_UPDATE(TIM3);
- LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH3);//执行完这一句,PWM口就拉低了
- LL_TIM_OC_SetCompareCH3(TIM3, 9);
- LL_TIM_EnableIT_UPDATE(TIM3);//TIM3更新使能
- LED_DEBUG_TOGGLE();
- LL_TIM_EnableCounter(TIM3);//TIM1计数使能
复制代码 第一个周期没有拉高,就觉得怪怪的,求助大佬
|
|