问答

汇集网友智慧,解决技术难题

CCSYJQ

TA的家园币:20  

  • STM32F4 pwm TIM4 CH3 配置没有波形输出

    voidTIM4_PWM_Init(u32arr,u32psc){GPIO_InitTypeDefGPIO_InitStructure;TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;TIM_OCInitTypeDefTIM_OCInitStructure;RCC_APB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);//IO口使能设置RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);//配置时钟GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;//TIM3的CH3连接PB8管脚GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;//复用推挽输出GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStructure);TIM_TimeBaseStructure.TIM_Period=arr;//10000;//1sTIM_TimeBaseStructure.TIM_Prescaler=psc;//7199;//720分频TIM_TimeBaseStructure.TIM_ClockDivision=0;TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//向上计数TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure);TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;//PWM1模式1TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//比较输出使能TIM_OCInitStructure.TIM_Pulse=2500;//设置占空比TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;//输出比较极性高TIM_OC3Init(TIM4,&TIM_OCInitStructure);//初始化TIM4的CH3通道TIM_OC3PreloadConfig(TIM4,TIM_OCPreload_Enable);//使能TIM4在CH3通道CCR3上的预装载寄存器TIM_ARRPreloadConfig(TIM4,ENABLE);//使能TIM4在CH3通道ARR3上的预装载寄存器TIM_Cmd(TIM4,ENABLE);//使能定时器4

    单片机 ST

    2022-02-10 1