我想设置22路PWM波,但是只有两路波形出来,其他没有波形。有没有大神解答一下啊

2019-08-22 14:09发布

#include "PWM.h"
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
8条回答
yyuu
2019-08-23 05:01
yyuu 发表于 2017-3-16 17:09
GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
   GPIO_InitStru ...

void p11(void) //pa8
{  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
   TIM_OCInitTypeDef  TIM_OCInitStructure;
   TIM_TimeBaseStructure.TIM_Period = f;      
   TIM_TimeBaseStructure.TIM_Prescaler = 0;            
   TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;       
   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  

   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;            
   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;   
   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
   TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
   TIM_OCInitStructure.TIM_Pulse = CCR_Val;       
   TIM_OC1Init(TIM1, &TIM_OCInitStructure);         
   TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
   TIM_ARRPreloadConfig(TIM1, ENABLE);                       
   TIM_Cmd(TIM1, ENABLE);                                                                       
   TIM_CtrlPWMOutputs(TIM1,ENABLE);
}                         
void p12(void) //pa9
{  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
   TIM_OCInitTypeDef  TIM_OCInitStructure;
   TIM_TimeBaseStructure.TIM_Period = f;      
   TIM_TimeBaseStructure.TIM_Prescaler = 0;            
   TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;       
   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  

   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;            
   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;   
   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
   TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
   TIM_OCInitStructure.TIM_Pulse = CCR_Val;       
   TIM_OC1Init(TIM1, &TIM_OCInitStructure);         
   TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
   TIM_ARRPreloadConfig(TIM1, ENABLE);                       
   TIM_Cmd(TIM1, ENABLE);                                                                       
   TIM_CtrlPWMOutputs(TIM1,ENABLE);   
}                                                                       
void p21(void)        //pa10
{  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
   TIM_OCInitTypeDef  TIM_OCInitStructure;
   TIM_TimeBaseStructure.TIM_Period = f;      
   TIM_TimeBaseStructure.TIM_Prescaler = 0;            
   TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;       
   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  

   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;            
   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;   
   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
   TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
   TIM_OCInitStructure.TIM_Pulse = CCR_Val;       
   TIM_OC3Init(TIM1, &TIM_OCInitStructure);         
   TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
   TIM_ARRPreloadConfig(TIM1, ENABLE);                       
   TIM_Cmd(TIM1, ENABLE);                                                                       
   TIM_CtrlPWMOutputs(TIM1,ENABLE);
}
void p22(void)
{ TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
   TIM_OCInitTypeDef  TIM_OCInitStructure;
   TIM_TimeBaseStructure.TIM_Period = f;      
   TIM_TimeBaseStructure.TIM_Prescaler = 0;            
   TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;       
   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  

   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;            
   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;   
   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
   TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
   TIM_OCInitStructure.TIM_Pulse = CCR_Val;       
   TIM_OC4Init(TIM1, &TIM_OCInitStructure);         
   TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
   TIM_ARRPreloadConfig(TIM1, ENABLE);                       
   TIM_Cmd(TIM1, ENABLE);                                                                       
   TIM_CtrlPWMOutputs(TIM1,ENABLE);
}

一周热门 更多>