TIM1的pwm输出没有波形?

2019-07-21 02:26发布

我感觉是库函数的问题,因为库函数没有要求给他TIM3,参数只有数据 [mw_shl_code=c,true]void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* TIM_BDTRInitStruct) { /* Set the default configuration */ TIM_BDTRInitStruct->TIM_OSSRState = TIM_OSSRState_Disable; TIM_BDTRInitStruct->TIM_OSSIState = TIM_OSSIState_Disable; TIM_BDTRInitStruct->TIM_LOCKLevel = TIM_LOCKLevel_OFF; TIM_BDTRInitStruct->TIM_DeadTime = 0x00; TIM_BDTRInitStruct->TIM_Break = TIM_Break_Disable; TIM_BDTRInitStruct->TIM_BreakPolarity = TIM_BreakPolarity_Low; TIM_BDTRInitStruct->TIM_AutomaticOutput = TIM_AutomaticOutput_Disable; }[/mw_shl_code] 没有要求让我把TIM1给他,那么他如何知道我是要初始化TIM1的呢?其他部分代码应该没有问题,因为使用tim3时可以输出
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
7条回答
胡桃
2019-07-21 09:25
改配置的我都配置了,但是输出还是为0,还望赐教。。。。我对于那个不用传TIM的函数还是耿耿于怀,应为看了网上其他的函数,是要传的 [mw_shl_code=c,true]GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; TIM_BDTRInitTypeDef TIM_BDTRInitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); //?????¨?±?÷1?±?? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); //????GPIO???è??AFIO???????????é?±?? TIM_DeInit(TIM1); //?????÷???è???±???? GPIO_PinRemapConfig(GPIO_PartialRemap_TIM1, ENABLE); //Timer1??·??????? //?è?????????????????????? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8; //PA7??PA8 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //???????ì???? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure);//??????GPIO //??????TIM1 TIM_TimeBaseStructure.TIM_Period = arr; //?è???????????ü??????×°????????×?????×°???????÷???????? TIM_TimeBaseStructure.TIM_Prescaler =psc; //?è??????×÷??TIMx?±?????????????¤·????? TIM_TimeBaseStructure.TIM_ClockDivision = 0; //?è???±??·???:TDTS = Tck_tim TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM?ò?????????? TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //?ù??TIM_TimeBaseInitStruct?????¨????????????TIMx???±???ù?????? //??????TIM1 Channel2 PWM???? TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //?????¨?±?÷????:TIM?????í???÷??????2 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±??????????? TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_Pulse = 200; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //????????:TIM????±????????? TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM1, &TIM_OCInitStructure); //?ù??T???¨???????????????èTIM1 OC2 TIM_OC2Init(TIM1, &TIM_OCInitStructure); TIM_OC3Init(TIM1, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable); //????TIM1??CCR2?????¤×°???????÷ TIM_BDTRInitStruct.TIM_OSSRState = TIM_OSSRState_Enable; TIM_BDTRInitStruct.TIM_OSSIState = TIM_OSSIState_Enable; TIM_BDTRInitStruct.TIM_LOCKLevel = TIM_LOCKLevel_OFF; TIM_BDTRInitStruct.TIM_DeadTime = 1; TIM_BDTRInitStruct.TIM_Break = TIM_Break_Disable; TIM_BDTRInitStruct.TIM_BreakPolarity = TIM_BreakPolarity_High; TIM_BDTRInitStruct.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable; TIM_BDTRStructInit(&TIM_BDTRInitStruct); TIM1->BDTR |= 1<<15; TIM_Cmd(TIM1, ENABLE); //????TIM1 TIM_ARRPreloadConfig(TIM1, ENABLE); TIM_CtrlPWMOutputs(TIM1,ENABLE);[/mw_shl_code]

一周热门 更多>