打印

HK32F030MF4P6 PC3-TIM1_CH3 PWM 没输出

[复制链接]
2123|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lpx280666373|  楼主 | 2021-3-25 15:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
pc, TI, PWM, IO, pi, ST
void TIM1_WindPwm_Config(void)                        //16K TIM1_CH3
{
      GPIO_InitTypeDef GPIO_InitStructure;
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
        TIM_OCInitTypeDef  TIM_OCInitStructure;
      
        RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOC, ENABLE );
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
        // 使能IOMUX时钟
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX,ENABLE);   
   
      GPIO_IOMUX_PinAFConfig(GPIOC,GPIO_PinSource3,IOMUX_PC3_TIM1CH3);
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd_DOWN;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOC, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOC,GPIO_PinSource3,GPIO_AF_3);   
     
        /* Time Base configuration */
        TIM_TimeBaseStructure.TIM_Prescaler = 0;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseStructure.TIM_Period = TIM1_PERIOD-1;
        TIM_TimeBaseStructure.TIM_ClockDivision = 0;
        TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

        TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

        /* Channel 1, 2,3 and 4 Configuration in PWM mode */
        TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
        TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;//TIM_OutputNState_Enable;
        TIM_OCInitStructure.TIM_Pulse = 1000;
        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
        //TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
        TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
        //TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;

        TIM_OC3Init(TIM1, &TIM_OCInitStructure);

        /* TIM1 counter enable */
        TIM_Cmd(TIM1, ENABLE);

        /* TIM1 Main Output Enable */
        TIM_CtrlPWMOutputs(TIM1, ENABLE);
}

使用特权

评论回复

相关帖子

沙发
walton1226| | 2021-3-25 17:23 | 只看该作者
TIM_ARRPreloadConfig(TIM1,ENABLE);

使用特权

评论回复
板凳
lpx280666373|  楼主 | 2021-9-30 12:33 | 只看该作者
walton1226 发表于 2021-3-25 17:23
TIM_ARRPreloadConfig(TIM1,ENABLE);

谢谢  屏蔽 //RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX,ENABLE);   正常输出了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

15

主题

113

帖子

2

粉丝