打印

请教兆易FAE关于GD32E505RBT6 SHRTIME占空比丢失问题

[复制链接]
12872|33
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
我在使用SHRTIME配置互补带死区的PWM时发现在输出PWM存在占空比丢失问题。在官方给的例程中也发现有同样问题。请求技术支持或单片机大牛帮忙分析分析。


使用特权

评论回复
沙发
夏洛克达尔|  楼主 | 2022-3-6 15:09 | 只看该作者

请教兆易FAE关于GD32E505RBT6 SHRTIME占空比丢失问题

代码如下
void shrtimer_config1(void)
{
/* -----------------------------------------------------------------------
    fSHRTIMER_CK:120MHz, from CK_SYS
    ST2_CHO_O: set request at Slave_TIMER2 compare 0 event, reset request at Slave_TIMER2 compare 1 event
    ST2_CH1_O: the waveform is complementary to channel 0
  ----------------------------------------------------------------------- */
    shrtimer_baseinit_parameter_struct baseinit_para;
    shrtimer_timerinit_parameter_struct timerinit_para;
    shrtimer_timercfg_parameter_struct timercfg_para;
    shrtimer_comparecfg_parameter_struct comparecfg_para;
    shrtimer_channel_outputcfg_parameter_struct outcfg_para;
    shrtimer_deadtimecfg_parameter_struct deadtimecfg_para;
          shrtimer_synccfg_parameter_struct synccfg_para;
       
          rcu_periph_clock_enable(RCU_GPIOB);
    rcu_periph_clock_enable(RCU_AF);

          gpio_afio_port_config(AFIO_PB12_SHRTIMER_CFG, ENABLE);
    gpio_afio_port_config(AFIO_PB13_SHRTIMER_CFG, ENABLE);
    gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_12);
    gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_13);
       
                gpio_afio_port_config(AFIO_PB14_SHRTIMER_CFG, ENABLE);
    gpio_afio_port_config(AFIO_PB15_SHRTIMER_CFG, ENABLE);
    gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_14);
    gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_15);       

    /* clock config */
    rcu_periph_clock_enable(RCU_SHRTIMER);
    rcu_shrtimer_clock_config(RCU_SHRTIMERSRC_CKSYS);

    /* periodic DLL calibration */
    shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_16384_PERIOD);
    while(RESET == shrtimer_common_flag_get(SHRTIMER0, SHRTIMER_FLAG_DLLCAL));

    /* Slave_TIMER2,3 time base clock config  */
    shrtimer_baseinit_struct_para_init(&baseinit_para);
    baseinit_para.period = LLCFPWMMAX;   //
    baseinit_para.prescaler = SHRTIMER_PRESCALER_MUL16;
    baseinit_para.repetitioncounter = 0;
    baseinit_para.counter_mode = SHRTIMER_COUNTER_MODE_CONTINOUS;
    shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &baseinit_para);
                shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &baseinit_para);

//          shrtimer_synccfg_struct_para_init(&synccfg_para);
//    synccfg_para.input_source = SHRTIMER_SYNCINPUTSOURCE_INTERNAL;
//    shrtimer_synchronization_config(SHRTIMER0, &synccfg_para);

    /* initialize Slave_TIMER2,3 to work in waveform mode */
    shrtimer_timerinit_struct_para_init(&timerinit_para);
    timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;
    timerinit_para.dac_trigger = SHRTIMER_DAC_TRIGGER_NONE;
    timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED;
    timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_DISABLED;
    timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;
    timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;
    timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;
    timerinit_para.update_selection = SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;
    shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timerinit_para);
    shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &timerinit_para);   
    /* configure the general behavior of a Slave_TIMER2,3 which work in waveform mode */
    shrtimer_timercfg_struct_para_init(&timercfg_para);
    timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_NONE;
    timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_ENABLED;
    timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;
    timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_NONE;
    timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READWRITE;
    timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_DISABLED;
    timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timercfg_para);
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &timercfg_para);  
               
    shrtimer_deadtimercfg_struct_para_init(&deadtimecfg_para);
    deadtimecfg_para.fallingsign_protect = SHRTIMER_DEADTIME_FALLINGSIGN_PROTECT_DISABLE;
    deadtimecfg_para.falling_protect = SHRTIMER_DEADTIME_FALLING_PROTECT_DISABLE;
    deadtimecfg_para.falling_sign = SHRTIMER_DEADTIME_FALLINGSIGN_POSITIVE;
    deadtimecfg_para.falling_value = 200;
    deadtimecfg_para.prescaler = SHRTIMER_DEADTIME_PRESCALER_MUL16;
    deadtimecfg_para.risingsign_protect = SHRTIMER_DEADTIME_RISINGSIGN_PROTECT_DISABLE;
    deadtimecfg_para.rising_protect = SHRTIMER_DEADTIME_RISING_PROTECT_DISABLE;
    deadtimecfg_para.rising_sign = SHRTIMER_DEADTIME_RISINGSIGN_POSITIVE;
    deadtimecfg_para.rising_value = 200;
    shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &deadtimecfg_para);
    shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &deadtimecfg_para);   
    /* configures the compare unit of a Slave_TIMER2,3 which work in waveform mode */
    shrtimer_comparecfg_struct_para_init(&comparecfg_para);
    comparecfg_para.compare_value = 100;
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_COMPARE0, &comparecfg_para);
    comparecfg_para.compare_value = 100 + ((LLCFPWMMAX)/2);
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_COMPARE1, &comparecfg_para);
               
                comparecfg_para.compare_value = 100;
                shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_COMPARE0, &comparecfg_para);
    comparecfg_para.compare_value = 100 + ((LLCFPWMMAX)/2);
                shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_COMPARE1, &comparecfg_para);

    /* configures the ST2_CH0_O/ST2_CH1_O output of a Slave_TIMER2 work in waveform mode */
                /* configures the ST3_CH0_O/ST3_CH1_O output of a Slave_TIMER3 work in waveform mode */
    shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_NONE;
    outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_CMP1;
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH1, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_ST3_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_ST3_CH1, &outcfg_para);

    /* enable output channel */
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH0);
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH1);
                shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST3_CH0);
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST3_CH1);
    /* enable a counter */
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST2_COUNTER);
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST3_COUNTER);               
}

使用特权

评论回复
板凳
夏洛克达尔|  楼主 | 2022-3-6 15:18 | 只看该作者
图片中4个通道分别为ST2_CH0,CH1。ST3_CH0,CH1。每个通道都会占空比有丢失的情况。
代码按照官方例程SHRTIMER0_complementary_output改的,将官方例程烧进单片机里也会出现这个问题?

faa8ce60d8bb204592b345fb0c5585f.jpg (170.61 KB )

faa8ce60d8bb204592b345fb0c5585f.jpg

使用特权

评论回复
地板
夏洛克达尔|  楼主 | 2022-3-6 16:47 | 只看该作者
void shrtimer_config1(void)
{
/* -----------------------------------------------------------------------
    fSHRTIMER_CK:120MHz, from CK_SYS
    ST2_CHO_O: set request at Slave_TIMER2 compare 0 event, reset request at Slave_TIMER2 compare 1 event
    ST2_CH1_O: the waveform is complementary to channel 0
  ----------------------------------------------------------------------- */
    shrtimer_baseinit_parameter_struct baseinit_para;
    shrtimer_timerinit_parameter_struct timerinit_para;
    shrtimer_timercfg_parameter_struct timercfg_para;
    shrtimer_comparecfg_parameter_struct comparecfg_para;
    shrtimer_channel_outputcfg_parameter_struct outcfg_para;
    shrtimer_deadtimecfg_parameter_struct deadtimecfg_para;
          shrtimer_synccfg_parameter_struct synccfg_para;
       
          rcu_periph_clock_enable(RCU_GPIOB);
    rcu_periph_clock_enable(RCU_AF);

          gpio_afio_port_config(AFIO_PB12_SHRTIMER_CFG, ENABLE);
    gpio_afio_port_config(AFIO_PB13_SHRTIMER_CFG, ENABLE);
    gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_12);
    gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_13);
       
                gpio_afio_port_config(AFIO_PB14_SHRTIMER_CFG, ENABLE);
    gpio_afio_port_config(AFIO_PB15_SHRTIMER_CFG, ENABLE);
    gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_14);
    gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_15);       
   
    /* clock config */
    rcu_periph_clock_enable(RCU_SHRTIMER);
    rcu_shrtimer_clock_config(RCU_SHRTIMERSRC_CKSYS);
   
    /* periodic DLL calibration */
    shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_16384_PERIOD);
    while(RESET == shrtimer_common_flag_get(SHRTIMER0, SHRTIMER_FLAG_DLLCAL));
   
    /* Slave_TIMER2,3 time base clock config  */
    shrtimer_baseinit_struct_para_init(&baseinit_para);
    baseinit_para.period = LLCFPWMMAX;   //
    baseinit_para.prescaler = SHRTIMER_PRESCALER_MUL16;
    baseinit_para.repetitioncounter = 0;
    baseinit_para.counter_mode = SHRTIMER_COUNTER_MODE_CONTINOUS;
    shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &baseinit_para);
                shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &baseinit_para);
   
//          shrtimer_synccfg_struct_para_init(&synccfg_para);
//    synccfg_para.input_source = SHRTIMER_SYNCINPUTSOURCE_INTERNAL;
//    shrtimer_synchronization_config(SHRTIMER0, &synccfg_para);

    /* initialize Slave_TIMER2,3 to work in waveform mode */
    shrtimer_timerinit_struct_para_init(&timerinit_para);
    timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;
    timerinit_para.dac_trigger = SHRTIMER_DAC_TRIGGER_NONE;
    timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED;
    timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_DISABLED;
    timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;
    timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;
    timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;
    timerinit_para.update_selection = SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;
    shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timerinit_para);
    shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &timerinit_para);   
    /* configure the general behavior of a Slave_TIMER2,3 which work in waveform mode */
    shrtimer_timercfg_struct_para_init(&timercfg_para);
    timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_NONE;
    timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_ENABLED;
    timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;
    timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_NONE;
    timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READWRITE;
    timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_DISABLED;
    timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timercfg_para);
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &timercfg_para);  
               
    shrtimer_deadtimercfg_struct_para_init(&deadtimecfg_para);
    deadtimecfg_para.fallingsign_protect = SHRTIMER_DEADTIME_FALLINGSIGN_PROTECT_DISABLE;
    deadtimecfg_para.falling_protect = SHRTIMER_DEADTIME_FALLING_PROTECT_DISABLE;
    deadtimecfg_para.falling_sign = SHRTIMER_DEADTIME_FALLINGSIGN_POSITIVE;
    deadtimecfg_para.falling_value = 200;
    deadtimecfg_para.prescaler = SHRTIMER_DEADTIME_PRESCALER_MUL16;
    deadtimecfg_para.risingsign_protect = SHRTIMER_DEADTIME_RISINGSIGN_PROTECT_DISABLE;
    deadtimecfg_para.rising_protect = SHRTIMER_DEADTIME_RISING_PROTECT_DISABLE;
    deadtimecfg_para.rising_sign = SHRTIMER_DEADTIME_RISINGSIGN_POSITIVE;
    deadtimecfg_para.rising_value = 200;
    shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &deadtimecfg_para);
    shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &deadtimecfg_para);   
    /* configures the compare unit of a Slave_TIMER2,3 which work in waveform mode */
    shrtimer_comparecfg_struct_para_init(&comparecfg_para);
    comparecfg_para.compare_value = 100;
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_COMPARE0, &comparecfg_para);
    comparecfg_para.compare_value = 100 + ((LLCFPWMMAX)/2);
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_COMPARE1, &comparecfg_para);
               
                comparecfg_para.compare_value = 100;
                shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_COMPARE0, &comparecfg_para);
    comparecfg_para.compare_value = 100 + ((LLCFPWMMAX)/2);
                shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_COMPARE1, &comparecfg_para);
   
    /* configures the ST2_CH0_O/ST2_CH1_O output of a Slave_TIMER2 work in waveform mode */
                /* configures the ST3_CH0_O/ST3_CH1_O output of a Slave_TIMER3 work in waveform mode */
    shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_NONE;
    outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_CMP1;
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_PER;
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH1, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_ST3_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_ST3_CH1, &outcfg_para);
   
    /* enable output channel */
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH0);
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH1);
                shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST3_CH0);
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST3_CH1);
    /* enable a counter */
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST2_COUNTER);
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST3_COUNTER);               
}


使用特权

评论回复
5
sxy4517| | 2022-3-6 22:19 | 只看该作者
楼主是驱动什么?

使用特权

评论回复
6
lfgaijf| | 2022-3-21 23:49 | 只看该作者
本帖最后由 lfgaijf 于 2022-3-22 08:54 编辑

我也遇到了,就离谱。 这个就只在例程的基础上把频率降了一点。
mcu型号是gd32 e503cet6 ,用的例程是shrtimer complementary output,也就是互补输出加死区的例程。
问题和楼主一样,都是有一个周期少了一个下降沿,reset失效,这用来驱动mos管必炸机。

70053d144550e88aeaa21ebc243c545.jpg (435.54 KB )

70053d144550e88aeaa21ebc243c545.jpg

使用特权

评论回复
7
lfgaijf| | 2022-3-22 00:02 | 只看该作者
大哥您解决了吗,看你变量名是在做谐振变换器,我也是做开关电源的,交流一下。qq 865358482

使用特权

评论回复
8
lifeforrent| | 2022-3-22 16:32 | 只看该作者
我在E503Z-EVAL板子用楼主的代码测试波形是正确的。

使用特权

评论回复
9
lfgaijf| | 2022-3-24 22:17 | 只看该作者
发现这个bug触发规律是这样的,成对出现。从示波器图上可以看到-17ms和4us会出现这种无法置0的现象,719ms到736ms又是另一对。
以下是我对shrtimer的配置。
void shrtimer_config_duli(void)
{
/* -----------------------------------------------------------------------
    fSHRTIMER_CK:180MHz, from CK_SYS
    waveform period: 384/(180M*64)=33.3ns
    ST0_CHO_O: set request at Slave_TIMER0 compare 0 event, reset request at Slave_TIMER0 compare 1 event
    ST0_CH1_O: set request at Slave_TIMER0 compare 2 event, reset request at Slave_TIMER0 compare 3 event
  ----------------------------------------------------------------------- */
    shrtimer_baseinit_parameter_struct baseinit_para;
    shrtimer_timerinit_parameter_struct timerinit_para;
    shrtimer_timercfg_parameter_struct timercfg_para;
    shrtimer_comparecfg_parameter_struct comparecfg_para;
    shrtimer_channel_outputcfg_parameter_struct outcfg_para;

    /* clock config */
    rcu_periph_clock_enable(RCU_SHRTIMER);
    rcu_shrtimer_clock_config(RCU_SHRTIMERSRC_CKSYS);

    /* periodic DLL calibration */
    shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_16384_PERIOD);
    while(RESET == shrtimer_common_flag_get(SHRTIMER0, SHRTIMER_FLAG_DLLCAL));

    /* Slave_TIMER0 time base clock config  */
    shrtimer_baseinit_struct_para_init(&baseinit_para);
    baseinit_para.period = 15999;
    baseinit_para.prescaler = SHRTIMER_PRESCALER_MUL4;
    baseinit_para.repetitioncounter = 0;
    baseinit_para.counter_mode = SHRTIMER_COUNTER_MODE_CONTINOUS;
    shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &baseinit_para);

    /* initialize Slave_TIMER0 to work in waveform mode */
    shrtimer_timerinit_struct_para_init(&timerinit_para);
    timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;
    timerinit_para.dac_trigger = SHRTIMER_DAC_TRIGGER_NONE;
    timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED;
    timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_DISABLED;
    timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;
    timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;
    timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;
    timerinit_para.update_selection = SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;
    shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &timerinit_para);

    /* configure the general behavior of a Slave_TIMER0 which work in waveform mode */
    shrtimer_timercfg_struct_para_init(&timercfg_para);
    timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_NONE;
    timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_DISABLED;
    timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;
    timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_NONE;
    timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READWRITE;
    timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_DISABLED;
    timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &timercfg_para);

    /* configures the compare unit of a Slave_TIMER0 which work in waveform mode */
    shrtimer_comparecfg_struct_para_init(&comparecfg_para);
    comparecfg_para.compare_value = 100;
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE0, &comparecfg_para);
    comparecfg_para.compare_value = 1100;
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE1, &comparecfg_para);
               
    comparecfg_para.compare_value = 5000;
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE2, &comparecfg_para);
    comparecfg_para.compare_value = 15550;
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE3, &comparecfg_para);

    /* configures the ST0_CH0_O output of a Slave_TIMER0 work in waveform mode */
    shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_NONE;
    outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_CMP1;
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST0_CH0, &outcfg_para);

    /* configures the ST0_CH1_O output of a Slave_TIMER0 work in waveform mode */
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_CMP3;
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP2;
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST0_CH1, &outcfg_para);

    /* enable output channel */
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST0_CH0);
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST0_CH1);
    /* enable a counter */
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST0_COUNTER);
}

使用特权

评论回复
10
tpgf| | 2022-4-2 17:18 | 只看该作者
就是波形丢失了是吗

使用特权

评论回复
11
wakayi| | 2022-4-2 17:29 | 只看该作者
是不是产生了竞争现象啊

使用特权

评论回复
12
wowu| | 2022-4-2 17:37 | 只看该作者
这些全是配置代码吗

使用特权

评论回复
13
renzheshengui| | 2022-4-2 17:43 | 只看该作者
会不会是示波器引入的干扰啊

使用特权

评论回复
14
xiaoqizi| | 2022-4-2 17:53 | 只看该作者
这个问题的原因可是不好找

使用特权

评论回复
15
木木guainv| | 2022-4-2 18:01 | 只看该作者
这是多快的速度啊

使用特权

评论回复
16
CharryW| | 2022-4-7 16:27 | 只看该作者
可以试下把初始化时的周期校准改成单次校准,这个周期出现可能是周期校准导致的。

使用特权

评论回复
17
loala| | 2022-4-7 16:42 | 只看该作者
shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_16384_PERIOD);这一句,改成

    shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_ONCE);

使用特权

评论回复
18
lfgaijf| | 2022-4-21 07:03 | 只看该作者
loala 发表于 2022-4-7 16:42
shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_16384_PERIOD);这一句,改成

    shrti ...

已经按您的说法解决,非常感谢

使用特权

评论回复
19
廖为情| | 2022-4-21 09:20 | 只看该作者
国产进口MCU,GD现货,有技术支持,有需要的小伙伴加微信,L18121451280 廖**

使用特权

评论回复
20
JIA XUAN| | 2022-4-21 14:40 | 只看该作者
准备用这个片子替代stmG474呢,多亏楼上两个细心的坛友发现这个bug,否则同步整流炸机没商量,希望官方能重视此问题。

使用特权

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

本版积分规则

1

主题

4

帖子

0

粉丝