# drv_pulse_encoder **Repository Path**: liuc0721/drv_pulse_encoder ## Basic Information - **Project Name**: drv_pulse_encoder - **Description**: 基于AT32的RT-thread脉冲编码驱动 - **Primary Language**: C - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2022-05-21 - **Last Updated**: 2023-01-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # drv_pulse_encoder #### 介绍 基于AT32F407的RT-thread的脉冲编码器驱动。 系统版本:RT-thread V4.1.0 功能:通过 RT-Thread 提供的 I/O 设备管理接口来访问脉冲编码器设备,实现正交编码测速。 参考链接:https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/pulse_encoder/pulse_encoder 问题: 在RT-thread提供的bsp中,在STM32中有脉冲编码器的驱动bsp\stm32\libraries\HAL_Drivers\drv_pulse_encoder.c 在at32中没有发现脉冲编码器对应的驱动。 解决: 在at32提供的固件库中有定时器编码模式的接口,于是自己根据STM32提供的驱动进行了相应修改测试。 #### 使用说明 1、 修改文件at32_msp.c,进行引脚初始化 ``` #ifdef RT_USING_PULSE_ENCODER void at32_msp_encoder_init(void *instance) { gpio_init_type gpio_init_struct; tmr_type *tmr_x = (tmr_type *)instance; gpio_default_para_init(&gpio_init_struct); gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; if(tmr_x == TMR4) { /* tmr4 clock enable */ crm_periph_clock_enable(CRM_TMR4_PERIPH_CLOCK, TRUE); /* gpiob clock enable */ crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE); /* gpiob configuration: tmr4 channel and channe2 as encoder function push-pull */ gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7; gpio_init(GPIOB, &gpio_init_struct); } /* add others */ } #endif /* RT_USING_PULSE_ENCODER */ ``` 2、 增加drv_pulse_encoder.c和drv_pulse_encoder.h 3、 开发应用测试 ### 联系方式 邮箱:307526315@qq.com