STM32F1 103 C8T6 无法输出PWM

2019-07-21 06:42发布

                哪位朋友帮忙看看这个程序为什么PWM 口PA1无法输出PWM,用的是TIM2
void TIM2_CH1(void)
                {
                         RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2  , ENABLE); ///时钟打开
                         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA| RCC_APB2Periph_GPIOA  , ENABLE);
                         TIM_TimeBaseInitTypeDef  TIM_TimeBaseInitStruct;  
       TIM_OCInitTypeDef        TIM_OCInitStruct;

       GPIO_InitTypeDef                                 GPIO_InitStruct;  
             GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;  ///PA0口作为输出PWM口
       GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;  
       GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;  
       GPIO_Init(GPIOA, &GPIO_InitStruct);

                   TIM_TimeBaseInitStruct.TIM_Period =100; ///125KHz / //
       TIM_TimeBaseInitStruct.TIM_Prescaler = 36-1;  /////预分频
       TIM_TimeBaseInitStruct.TIM_ClockDivision = 0;  
       TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;  
       TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStruct);  
                       
                         TIM_OCInitStruct.TIM_OCMode=TIM_OCMode_PWM1;///PWM模式1
                         TIM_OCInitStruct.TIM_OCPolarity=TIM_OCPolarity_High;
                        TIM_OCInitStruct.TIM_OutputState=TIM_OutputState_Disable;
                         TIM_OCInitStruct.TIM_Pulse=100/2;////占空比
                          TIM_OC1Init(TIM2, &TIM_OCInitStruct);
                               
                         TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStruct);
                         TIM_ARRPreloadConfig(TIM2, ENABLE);
                         TIM_Cmd(TIM2, ENABLE);                ///使能
                }

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
nashui_sx
1楼-- · 2019-07-21 09:22
牵手 发表于 2018-12-15 14:05
请教大神这一句哪里有问题,没看出来

你引脚定时器都只初始化的通道0 也就是A0  通道2  PA1肯定没输出呀
nashui_sx
2楼-- · 2019-07-21 11:08
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;  ///PA0口作为输出PWM口
牵手
3楼-- · 2019-07-21 14:34
nashui_sx 发表于 2018-12-15 13:46
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;  ///PA0口作为输出PWM口

请教大神这一句哪里有问题,没看出来

一周热门 更多>