GD32F330 Timer16 无法输出PWM

[复制链接]
155|4
 楼主 | 2018-6-7 10:50 | 显示全部楼层 |阅读模式
需要用到PB9 Timer16_CH0,参考例程Timer1_CH3的配置,以下同样的配置,PB9不能输出PWM,PB11有PWM输出,是不是Timer16有特殊的设置?求解。。。


#if 1
        rcu_periph_clock_enable(RCU_GPIOB);
        gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_9);
        gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_9);
        //gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_9);
        gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_9);

       
        timer_oc_parameter_struct timer_ocintpara;
        timer_parameter_struct timer_initpara;

        rcu_periph_clock_enable(RCU_TIMER16);

        timer_deinit(TIMER16);
        timer_initpara.prescaler         = 1;
        timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
        timer_initpara.counterdirection  = TIMER_COUNTER_UP;
        timer_initpara.period            = 2099;
        timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
        timer_initpara.repetitioncounter = 0;
        timer_init(TIMER16,&timer_initpara);
        timer_ocintpara.ocpolarity  = TIMER_OC_POLARITY_HIGH;
        timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
        timer_channel_output_config(TIMER16,TIMER_CH_0,&timer_ocintpara);
        timer_channel_output_pulse_value_config(TIMER16,TIMER_CH_0,1049);
        timer_channel_output_mode_config(TIMER16,TIMER_CH_0,TIMER_OC_MODE_PWM0);
        timer_channel_output_shadow_config(TIMER16,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);

        /* auto-reload preload enable */
        timer_auto_reload_shadow_enable(TIMER16);
        /* auto-reload preload enable */
        timer_enable(TIMER16);
#endif
        #if 1
        rcu_periph_clock_enable(RCU_GPIOB);
        gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_11);
        gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_11);
        gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_11);
        //memset((void*)timer_ocintpara,0,sizeof(timer_ocintpara));
        //memset((void*)timer_initpara,0,sizeof(timer_initpara));
        timer_oc_parameter_struct timer_ocintparaa;
        timer_parameter_struct timer_initparaa;

        rcu_periph_clock_enable(RCU_TIMER1);

        timer_deinit(TIMER1);
        timer_initparaa.prescaler         = 1;
        timer_initparaa.alignedmode       = TIMER_COUNTER_EDGE;
        timer_initparaa.counterdirection  = TIMER_COUNTER_UP;
        timer_initparaa.period            = 2099;
        timer_initparaa.clockdivision     = TIMER_CKDIV_DIV1;
        timer_initparaa.repetitioncounter = 0;
        timer_init(TIMER1,&timer_initparaa);
        timer_ocintparaa.ocpolarity  = TIMER_OC_POLARITY_HIGH;
        timer_ocintparaa.outputstate = TIMER_CCX_ENABLE;
        timer_channel_output_config(TIMER1,TIMER_CH_3,&timer_ocintparaa);
        timer_channel_output_pulse_value_config(TIMER1,TIMER_CH_3,1049);
        timer_channel_output_mode_config(TIMER1,TIMER_CH_3,TIMER_OC_MODE_PWM0);
        timer_channel_output_shadow_config(TIMER1,TIMER_CH_3,TIMER_OC_SHADOW_DISABLE);

        /* auto-reload preload enable */
        timer_auto_reload_shadow_enable(TIMER1);
        /* auto-reload preload enable */
        timer_enable(TIMER1);
#endif
 楼主 | 2018-6-7 11:07 | 显示全部楼层
http://bbs.21ic.com/forum.php?mod=attachment&aid=MTAzNzYzNHxjM2Q4ODlkOWQwNzMxMjU5OTYzNDM0ZmIxMDU0MDBjOXwxNTI5OTEyNDI5&request=yes&_f=.jpgattach://1037632.jpg

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主 | 2018-6-7 17:50 | 显示全部楼层
请教高人后,已解决
加个timer_primary_output_config(TIMER16, ENABLE);

评论

green1996 2018-6-8 09:19 回复TA
是的,他们的寄存器结构略有差别 
| 2018-6-11 21:48 | 显示全部楼层
这个主要取决于定时器的合理用的
扫描二维码,随时随地手机跟帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复

您需要登录后才可以回帖
登录 | 注册
高级模式
我要创建版块 申请成为版主

论坛热帖

分享 快速回复 返回顶部 返回列表