TIM1的互补输出PWM,死区时间我都调试出来了,用MDK仿真也没问题,但是 我还有个是关于库函数版本代码的
我将下面三行代码注释后,仿真还是一样的,也就是说着三行代码没用的
// TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
// TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);
// TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable);
那么问题来了,使能自动重装载到底是哪个函数在实现?
TIM1->CCMR2|=1<<11; // CH4预装载使能
我找了半天还是时有TIM_OCxPreloadConfig();有这个功能
然后,我去测试了原子的PWM代码的库函数版本,注释了
TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);依然输出了PWM附图1
不知道我说清楚了 我的问题没,希望有人能解答,同时二楼附上我的代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;//定义定时器结构体
TIM_OCInitTypeDef TIM_OCInitStructure;//定义PWM结构体
TIM_BDTRInitTypeDef TIM_BDTRInitStructure; //死区时间结构体
GPIO_InitTypeDef GPIO_InitStructure; //定义GPIO结构体
//使能时钟TIM1 GPIOA GPIOB AFIO
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_TIM1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);//初始化 GPIPA8,9,10,11复用推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_Init(GPIOB,&GPIO_InitStructure); //初始化GPIOB13,14,15复用推挽输出
//TIM_DeInit(TIM1);
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler = psc;
TIM_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_Up ;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High ; //高电平为有效电平
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //输出使能
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High ;//互补输出,高电平为有效电平
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;//互补输出使能
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;//CR2寄存器 这里没用到,不知道干嘛用的 0x0000;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;//CR2寄存器,这里没用到,reset的值是=0x0000;
TIM_OCInitStructure.TIM_Pulse = 300; //设置占空比
TIM_OC1Init(TIM1,&TIM_OCInitStructure); //初始化 CH1 CHN1通道;占空比30%
TIM_OCInitStructure.TIM_Pulse = 405;
TIM_OC2Init(TIM1,&TIM_OCInitStructure); //初始化 CH2 CHN2通道;占空比45%
TIM_OCInitStructure.TIM_Pulse = 450;
TIM_OC3Init(TIM1,&TIM_OCInitStructure); // 初始化 CH3 CHN3通道;占空比50%
TIM_OCInitStructure.TIM_Pulse = 600 ;
TIM_OC4Init(TIM1,&TIM_OCInitStructure); //初始化 CH4通道 ;占空比60%
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable ;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
TIM_BDTRInitStructure.TIM_DeadTime = 0x14;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF; //锁定关闭
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Disable; //
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Disable; //
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure); //设置死区时间2MS
// TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
// TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);
// TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_CtrlPWMOutputs(TIM1,ENABLE); //使能外设 TIM1 的主输出
TIM_ARRPreloadConfig(TIM1,ENABLE); //自动重装载使能
TIM_Cmd(TIM1,ENABLE); //时钟使能
但是我突然发现,我没有使能CH4的自动重装使能,但是CH4一样会有输出
现在,有没有说MDK能到查询到,CCMR2寄存的某一位是由哪个函数设置的,
一周热门 更多>