打印

GD32E103R 无法产生互补PWM波?

[复制链接]
1829|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xiaobai032|  楼主 | 2018-12-13 23:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本人使用TIM0的CH0产生互补PWM波形。PA8为TIM0CH0,PB13为TM0CH0N。本人之前用GD32F207C已实现,但换了芯片,库函数也变了,有的函数没找到,所以无法实现。程序如下,请各位大侠看一下。
#include "gd32e10x.h"

#include <stdio.h>
#include "main.h"




int compare ;


void TIM0_init()
{
  timer_parameter_struct tim0_int;// TIM0³õʼ»¯²ÎÊý
        timer_break_parameter_struct tim0_DT; //TIM0ËÀÇø²ÎÊý
        timer_oc_parameter_struct   tim0_OC; // ??1????
  tim0_int.period   = 1200;// 120M?????100k
        tim0_int.prescaler = 0;//??????120M
  tim0_int.clockdivision = TIMER_CKDIV_DIV1;//??????120M
        tim0_int.alignedmode = TIMER_COUNTER_EDGE;//????
        tim0_int.counterdirection = TIMER_COUNTER_UP;
        timer_init(TIMER0,&tim0_int);
       
       
       
  tim0_DT.runoffstate = TIMER_ROS_STATE_ENABLE;
        tim0_DT.ideloffstate = TIMER_IOS_STATE_ENABLE;
//        tim0_DT.TIMER_LOCKLevel = TIMER_LOCK_LEVEL_OFF;
        tim0_DT.deadtime   = 12;
        tim0_DT.breakstate = TIMER_BREAK_DISABLE;
        tim0_DT.breakpolarity = TIMER_BREAK_POLARITY_LOW;
        tim0_DT.outputautostate = TIMER_OUTAUTO_DISABLE ;
  timer_break_config(TIMER0,&tim0_DT);
       
       
       

        tim0_OC.outputstate = TIMER_CCX_ENABLE;//??????
        tim0_OC.outputnstate = TIMER_CCXN_ENABLE;//????????

        tim0_OC.ocpolarity = TIMER_OC_POLARITY_HIGH;//????????
        tim0_OC.ocnpolarity = TIMER_OCN_POLARITY_HIGH;//????????
        tim0_OC.ocidlestate = TIMER_OC_IDLE_STATE_LOW;//???????
        tim0_OC.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;//??????
  timer_channel_output_config(TIMER0,TIMER_CH_0,&tim0_OC);
        timer_channel_output_mode_config(TIMER0,TIMER_CH_0,TIMER_OC_MODE_PWM0);
        timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_0,compare);
        timer_channel_output_shadow_config(TIMER0,TIMER_CH_0,TIMER_OC_SHADOW_ENABLE);//??????
        timer_auto_reload_shadow_enable(TIMER0);
  timer_enable(TIMER0);
        timer_channel_output_state_config(TIMER0,TIMER_CH_0,TIMER_CCX_ENABLE);
        timer_channel_complementary_output_state_config(TIMER0,TIMER_CH_0,TIMER_CCXN_ENABLE);
//         timer_input_trigger_source_select
//        TIMER_CtrlPWMOutputs(TIMER1,ENABLE);//??ON,OC??(BDTR)
//        TIMER_CC_PreloadControl(TIMER1,ENABLE);
}


void  PWM_GPIO_init()
{
  
        rcu_periph_clock_enable(TIMER0);
        rcu_periph_clock_enable(GPIOA);
        rcu_periph_clock_enable(GPIOB);
        rcu_periph_clock_enable(RCU_AF);
        gpio_init(GPIOA,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_8);
        gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_13);
  
}

int main(void)
{
        compare = 800;
       
        PWM_GPIO_init();
        TIM0_init();
        while(1)
        {
    compare = 800;
                timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_0,compare);
       
        }
   
}

沙发
keaibukelian| | 2018-12-14 11:34 | 只看该作者
互补因该是可以的

使用特权

评论回复
板凳
xiaobai032|  楼主 | 2018-12-14 18:48 | 只看该作者

功能已经是可以,但不知道程序为什么实现不了

使用特权

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

本版积分规则

15

主题

48

帖子

2

粉丝