-
MM32G0001A 2个Timer各出1PWM 设置占空比不同 实际结果确一样
MM32G0001A使用两个定时器TIM14和TIM3各出一路PWM设置不一样的占空比但是实际结果确一样哪里设置有问题吗?voidTIM3_Configure(void){GPIO_InitTypeDefGPIO_InitStruct;TIM_OCInitTypeDefTIM_OCInitStruct;TIM_TimeBaseInitTypeDefTIM_TimeBaseStruct;/*ComputethevaluetobesetinARRregitertogeneratesignalfrequencyat100Khz*/uint32_tTimerPeriod=(TIM_GetTIMxClock(TIM3)/5000)-1;/*ComputeCCR1valuetogenerateadutycycleat80%forchannel1*/uint32_tChannel1Pulse=((uint32_t)800*(TimerPeriod-1))/1000;RCC_APB1PeriphClockCmd(RCC_APB1ENR_TIM3,ENABLE);TIM_TimeBaseStructInit(&TIM_TimeBaseStruct);TIM_TimeBaseStruct.TIM_Prescaler=0;TIM_TimeBaseStruct.TIM_CounterMode=TIM_CounterMode_Up;TIM_TimeBaseStruct.TIM_Period=TimerPeriod;TIM_TimeBaseStruct.TIM_ClockDivision=TIM_CKD_Div1;TIM_TimeBaseStruct.TIM_RepetitionCounter=0;TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStruct);TIM_OCStructInit(&TIM_OCInitStruct);TIM_OCInitStruct.TIM_OCMode=TIM_OCMode_PWM1;TIM_OCInitStruct.TIM_OutputState=TIM_OutputState_Enable;TIM_OCInitStruct.TIM_Pulse=0;TIM_OCInitStruct.TIM_OCPolarity=TIM_OCPolarity_High;TIM_OCInitStruct.TIM_OCIdleState=TIM_OCIdleState_Set;TIM_OCInitStruct.TIM_Pulse=Channel1Pulse;TIM_OC1Init(TIM3,&TIM_OCInitStruct);RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA,ENABLE);GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_3);/*TIM1_CH1*/GPIO_StructInit(&GPIO_InitStruct);GPIO_InitStruct.GPIO_Pin=GPIO_Pin_11;GPIO_InitStruct.GPIO_Speed=GPIO_Speed_High;GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;GPIO_Init(GPIOA,&GPIO_InitStruct);TIM_Cmd(TIM3,ENABLE);TIM_CtrlPWMOutputs(TIM3,ENABLE);}/********************************************************************
2024-03-31 1