打印

GD32E503RCT6定时器互补输出实验?

[复制链接]
389|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
风雨同心|  楼主 | 2022-6-23 17:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
void shrtimer_config(void)
{
/* -----------------------------------------------------------------------
    fSHRTIMER_CK:180MHz, from CK_SYS
    waveform period: 11520/(180M*64)=1us
    ST0_CHO_O: set request at Slave_TIMER0 compare 0 event, reset request at Slave_TIMER0 compare 1 event
    ST0_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;

    /* 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 = 11520;
    baseinit_para.prescaler = SHRTIMER_PRESCALER_MUL64;
    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_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_TIMER0, &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 = 0x0040;
    deadtimecfg_para.prescaler = SHRTIMER_DEADTIME_PRESCALER_MUL8;
    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 = 0x0040;
    shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &deadtimecfg_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 = 1000;  这个值是根据什么定的
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE0, &comparecfg_para);
    comparecfg_para.compare_value = 6000; 这个值是调占空比吗?
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE1, &comparecfg_para);

    /* configures the ST0_CH0_O/ST0_CH1_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);
    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);
}

这个是官方的定时器互补输出实验,对设置的比较值的作用有点看不懂,请各位朋友帮忙解答一下,谢谢。

使用特权

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

本版积分规则

2

主题

2

帖子

0

粉丝