|
RT 求问大神 什么原因 在线等啊 多谢!
代码配置如下
void bsp_PwmGpioInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOC clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
//GPIOF Configuration: TIM10/11/13/14 PF6/7/8/9 CH1 ËÄ·PWMÊä³ö
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOF, & GPIO_InitStructure);
/* Connect TIM10/11/13/14 pins to AF3/AF9 */
GPIO_PinAFConfig(GPIOF, GPIO_Pin_6, GPIO_AF_TIM10);
GPIO_PinAFConfig(GPIOF, GPIO_Pin_7, GPIO_AF_TIM11);
GPIO_PinAFConfig(GPIOF, GPIO_Pin_8, GPIO_AF_TIM13);
GPIO_PinAFConfig(GPIOF, GPIO_Pin_9, GPIO_AF_TIM14);
}
void bsp_PwmTimConfig(uint16_t outputClock)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* TIM clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM13, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
/*TIM_DeInit(TIM10);
TIM_DeInit(TIM11);
TIM_DeInit(TIM13);
TIM_DeInit(TIM14); */
/* Compute the prescaler value */
PrescalerValue = (uint16_t)((SystemCoreClock / 2) / TIMn_CounterClock) - 1;//168M/2-84M-1=0 /* Time base configuration */
TIM_CHn_ARR = TIMn_CounterClock / outputClock - 1; //PWM¶¨Ê±ÖÜÆÚ×ܼÆÊý 84MHz/20kHz(PWMƵÂÊ)-1=4199
TIM_TimeBaseStructure.TIM_Period = TIM_CHn_ARR;
TIM_TimeBaseStructure.TIM_Prescaler = 0; //PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM10, & TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM11, & TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM13, & TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM14, & TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse = 2099; //³õʼ»¯Îª0 //(uint16_t)((uint32_t)(TIM_CHn_ARR+1)*5 / 10);//250
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM10, & TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM10, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM10, ENABLE);
TIM_OC1Init(TIM11, & TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM11, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM11, ENABLE);
TIM_OC1Init(TIM13, & TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM13, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM13, ENABLE);
TIM_OC1Init(TIM14, & TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM14, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM14, ENABLE);
// TIM3 enable counter //
TIM_Cmd(TIM10, ENABLE);
TIM_Cmd(TIM11, ENABLE);
TIM_Cmd(TIM13, ENABLE);
TIM_Cmd(TIM14, ENABLE);
//TIM_CtrlPWMOutputs(TIM10, ENABLE); //TIM1-8
} |
|