问答

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

21ic问答首页 - GD32F103外部脉冲计数

国产芯片 GD32 timer SD32F103

GD32F103外部脉冲计数

yangfrch2022-12-20
参照GD32例程写了一个使用定时器对外部脉冲进行计数,无法正常运行,通一个芯片,使用STM32的库,ETR计数没有问题,求解
回答 +关注 14
2358人浏览 1人回答问题 分享 举报
1 个回答
  • static void Timer_Rcu_NvicIrq_Init(void)
    {
        rcu_periph_clock_enable(RCU_GPIOA);
        rcu_periph_clock_enable(RCU_AF);
        rcu_periph_clock_enable(RCU_TIMER1);
    }

    static void Timer_Gpio_Init(void)
    {
        gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
    }

    static void Timer_Config(void)
    {
        timer_parameter_struct timer_initpara;
        // timer_ic_parameter_struct timer_icinitpara;

        timer_deinit(TIMER1);
        /* initialize TIMER init parameter struct */
        timer_struct_para_init(&timer_initpara);
        /* TIMER1 configuration */
        timer_initpara.prescaler = 0;
        timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
        timer_initpara.counterdirection = TIMER_COUNTER_UP;
        timer_initpara.period = 0xffff;
        timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
        timer_init(TIMER1, &timer_initpara);

        /* 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_EXTERNAL0);
        timer_external_clock_mode1_config(TIMER1, TIMER_EXT_TRI_PSC_OFF, TIMER_ETP_RISING, 0);

        timer_enable(TIMER1);
    }

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