问答

汇集网友智慧,解决技术难题

21ic问答首页 - gd32f30x:外部上升沿触发timer1_singlepulse模式错误

国产芯片 嵌入式 技术交流 兆易

gd32f30x:外部上升沿触发timer1_singlepulse模式错误

peikun2022-03-09
各位朋友大家好,我在使用gd32f30x的外部上升沿触发timer1_singlepulse模式时,出现timer1 ch2的pwm输出不规则的问题:
1.应用情况:外部触发频率:100kHz,输出pwm频率:100kHz,占空比3/20.
2.波形:蓝色:外部触发源 紫色:timer1 ch2输出pwm
3.配置代码:
    timer_initpara.prescaler         = 83;
    timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
    timer_initpara.counterdirection  = TIMER_COUNTER_UP;
    timer_initpara.period            = 19;
    timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
    timer_initpara.repetitioncounter = 0;
    timer_init(TIMER1,&timer_initpara);

    /* auto-reload preload disable */
    timer_auto_reload_shadow_disable(TIMER1);
   
     /* CH2 configuration in OC PWM0 mode */
    timer_ocinitpara.ocpolarity   = TIMER_OC_POLARITY_HIGH;
    timer_ocinitpara.ocnpolarity  = TIMER_OCN_POLARITY_HIGH;
    timer_ocinitpara.outputstate  = TIMER_CCX_ENABLE;
    timer_ocinitpara.outputnstate = TIMER_CCXN_DISABLE;
    timer_ocinitpara.ocidlestate  = TIMER_OC_IDLE_STATE_LOW;
    timer_ocinitpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
    timer_channel_output_config(TIMER1,TIMER_CH_2,&timer_ocinitpara);

    timer_channel_output_pulse_value_config(TIMER1,TIMER_CH_2,3);
    timer_channel_output_mode_config(TIMER1,TIMER_CH_2,TIMER_OC_MODE_PWM0);
    timer_channel_output_shadow_config(TIMER1,TIMER_CH_2,TIMER_OC_SHADOW_DISABLE);
   
    timer_channel_output_fast_config(TIMER1,TIMER_CH_2,TIMER_OC_FAST_ENABLE);

    /* TIMER1 CH0 input capture configuration */
    timer_icinitpara.icpolarity  = TIMER_IC_POLARITY_RISING;
    timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI;
    timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
    timer_icinitpara.icfilter    = 0x00;
    timer_input_capture_config(TIMER1,TIMER_CH_0,&timer_icinitpara);

    /* single pulse mode selection */
    timer_single_pulse_mode_config(TIMER1,TIMER_SP_MODE_SINGLE);
   
    /* slave mode selection : TIMER1 */
    /* TIMER1 input trigger : external trigger connected to CI0 */
    timer_input_trigger_source_select(TIMER1,TIMER_SMCFG_TRGSEL_CI0FE0);
    timer_slave_mode_select(TIMER1,TIMER_SLAVE_MODE_EVENT);

回答 +关注 15
8363人浏览 7人回答问题 分享 举报
7 个回答

您需要登录后才可以回复 登录 | 注册