配置我参考原子哥 的TIM14 但是就是没有输出 想不明白是哪里不对
//c文件中
void TIM3_OC2_PWMInit(u32 arr,u32 psc)
{
GPIO_InitTypeDef GPIO_InitStruct;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitTypeInitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
TIM_TimeBaseInitStruct.TIM_Prescaler = psc;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period = arr;
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct);
TIM_OCInitTypeInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitTypeInitStruct.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitTypeInitStruct.TIM_OutputState = TIM_OutputState_Enable;
//TIM_OCInitTypeInitStruct.TIM_Pulse = 250;
TIM_OC2Init(TIM3,&TIM_OCInitTypeInitStruct);
TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3,ENABLE);
}
//头文件
#ifndef __PWM_H
#define __PWM_H
#include "sys.h"
void TIM3_OC2_PWMInit(u32 arr,u32 psc);
#endif
//主函数中
TIM3_OC2_PWMInit(1000-1,84-1);//定时器初始化
。。。。
。。。。
while(1)
{
TIM_SetCompare2(TIM3,500);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>