想用PWM但是一直输出LOW
不知道是不是板子的问题但是再别的f1板子上还是可以跑相似的程序的
多谢各位大佬相助
#include "stm32f0xx_tim.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx.h"
int main(void)
{
GPIO_InitTypeDef port;
TIM_TimeBaseInitTypeDef timer;
TIM_OCInitTypeDef timerPWM;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
GPIO_StructInit(&port);
port.GPIO_Mode = GPIO_Mode_AF;
port.GPIO_Pin = GPIO_Pin_4;
port.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_Init(GPIOA, &port);
TIM_TimeBaseStructInit(&timer);
timer.TIM_Prescaler = 480;
timer.TIM_Period = 1000;
timer.TIM_ClockDivision = TIM_CKD_DIV1;
timer.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM14, &timer);
// TIM_SetAutoreload(TIM14, 1000);
TIM_OC1PreloadConfig(TIM14, TIM_OCPreload_Enable);
TIM_OCStructInit(&timerPWM);
timerPWM.TIM_OCMode = TIM_OCMode_PWM1;
timerPWM.TIM_OutputState = TIM_OutputState_Enable;
timerPWM.TIM_Pulse = 500;
timerPWM.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM14, &timerPWM);
TIM_Cmd(TIM14, ENABLE);
// TIM_OC1FastConfig(TIM14, TIM_OCFast_Disable);
// TIM_CtrlPWMOutputs(TIM14, ENABLE);
// TIM_OC1PreloadConfig(TIM14, TIM_OCPreload_Enable);
while(1)
{
}
}
|