我写了个输出PWM波形的程序,高级定时器TIM1的行,但是TIM8的不行,谁能告诉我这是怎么回事???最好给个例程!!!我的开发板是stm32103zet6的!下面是程序:
TIM_TimeBaseInitTypeDef Time_TimeBaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
TIM_DeInit(TIM8);
TIM_ClearFlag(TIM8, TIM_FLAG_Update); //清除更新标志位 ^^^^^^^^^^^^
/*设置计数重装载指,预分频;时钟分割和计数模式----》设置时钟中的时间基数单位*/
Time_TimeBaseInitStructure.TIM_Period = 200;
Time_TimeBaseInitStructure.TIM_Prescaler = 7199;
Time_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
Time_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
Time_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM8,&Time_TimeBaseInitStructure);
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //设为输出比较触发模式
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 10;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM8,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 15;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC2Init(TIM8,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 20;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC3Init(TIM8,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 25;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC4Init(TIM8,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM8,TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM8,TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM8,TIM_OCPreload_Enable);
TIM_OC4PreloadConfig(TIM8,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM8,ENABLE);
TIM_CtrlPWMOutputs(TIM8,ENABLE); //11
TIM_Cmd(TIM8,ENABLE); |