【E240】STM32 EC11编码器示例代码

2021-08-17 09:56:57      索炜达电子      912     

项目编号:E240

文件大小:551K

源码说明:带中文注释

开发环境:C编译器

简要概述

EC11 编码器

首先来看下 EC11 旋转编码器旋转时的逻辑分析仪波形图: 

【E240】STM32 EC11编码器示例代码

通过逻辑分析仪波形图可以看出,旋转编码器正转(顺时针)旋转时 CLK 先由高变为低,旋转编码器反转(逆时针)旋转时 Dt 先由高变为低。下面就思考下怎么实现代码判断正反转。

首先配置 CLK 和 DT 为下降沿外部中断触发,也就是出现下降沿时触发中断;这里我们要判断正反转,只需要在 CLK 的中断回调函数中判断 DT 的电平高低即可判断出旋转的方向,当 CLK 中断触发时如果 DT 为高电平则为正转,如果为低电平则为反转。

文件列表:

目录│文件列表:

 └ stm32_-led_-ec11

    │ .mxproject

    │ .stm32ignore

    │ 74HC595D-EC11.ioc

    │ EC11-1.png

    │ Makefile

    │ startup_stm32f410rx.s

    │ STM32F410RBTx_FLASH.ld

    │ STM32Make.make

    ├ .vscode

    │  │ c_cpp_properties.json

    │  │ launch.json

    │  │ settings.json

    │  └ tasks.json

    ├ Core

    │  ├ Inc

    │  │  │ gpio.h

    │  │  │ led74hc595.h

    │  │  │ main.h

    │  │  │ spi.h

    │  │  │ stm32f4xx_hal_conf.h

    │  │  │ stm32f4xx_it.h

    │  │  └ usart.h

    │  └ Src

    │     │ gpio.c

    │     │ led74hc595.c

    │     │ main.c

    │     │ spi.c

    │     │ stm32f4xx_hal_msp.c

    │     │ stm32f4xx_it.c

    │     │ system_stm32f4xx.c

    │     └ usart.c

    └ Drivers

       ├ CMSIS

       │  ├ Device

       │  │  └ ST

       │  │     └ STM32F4xx

       │  │        └ Include

       │  │           │ stm32f410rx.h

       │  │           │ stm32f4xx.h

       │  │           └ system_stm32f4xx.h

       │  └ Include

       │     │ cmsis_armcc.h

       │     │ cmsis_armclang.h

       │     │ cmsis_compiler.h

       │     │ cmsis_gcc.h

       │     │ cmsis_iccarm.h

       │     │ cmsis_version.h

       │     │ core_armv8mbl.h

       │     │ core_armv8mml.h

       │     │ core_cm0.h

       │     │ core_cm0plus.h

       │     │ core_cm1.h

       │     │ core_cm23.h

       │     │ core_cm3.h

       │     │ core_cm33.h

       │     │ core_cm4.h

       │     │ core_cm7.h

       │     │ core_sc000.h

       │     │ core_sc300.h

       │     │ mpu_armv7.h

       │     │ mpu_armv8.h

       │     └ tz_context.h

       └ STM32F4xx_HAL_Driver

          ├ Inc

          │  │ stm32f4xx_hal.h

          │  │ stm32f4xx_hal_cortex.h

          │  │ stm32f4xx_hal_def.h

          │  │ stm32f4xx_hal_dma.h

          │  │ stm32f4xx_hal_dma_ex.h

          │  │ stm32f4xx_hal_exti.h

          │  │ stm32f4xx_hal_flash.h

          │  │ stm32f4xx_hal_flash_ex.h

          │  │ stm32f4xx_hal_flash_ramfunc.h

          │  │ stm32f4xx_hal_gpio.h

          │  │ stm32f4xx_hal_gpio_ex.h

          │  │ stm32f4xx_hal_pwr.h

          │  │ stm32f4xx_hal_pwr_ex.h

          │  │ stm32f4xx_hal_rcc.h

          │  │ stm32f4xx_hal_rcc_ex.h

          │  │ stm32f4xx_hal_spi.h

          │  │ stm32f4xx_hal_tim.h

          │  │ stm32f4xx_hal_tim_ex.h

          │  │ stm32f4xx_hal_uart.h

          │  └ Legacy

          │     └ stm32_hal_legacy.h

          └ Src

             │ stm32f4xx_hal.c

             │ stm32f4xx_hal_cortex.c

             │ stm32f4xx_hal_dma.c

             │ stm32f4xx_hal_dma_ex.c

             │ stm32f4xx_hal_exti.c

             │ stm32f4xx_hal_flash.c

             │ stm32f4xx_hal_flash_ex.c

             │ stm32f4xx_hal_flash_ramfunc.c

             │ stm32f4xx_hal_gpio.c

             │ stm32f4xx_hal_pwr.c

             │ stm32f4xx_hal_pwr_ex.c

             │ stm32f4xx_hal_rcc.c

             │ stm32f4xx_hal_rcc_ex.c

             │ stm32f4xx_hal_spi.c

             │ stm32f4xx_hal_tim.c

             │ stm32f4xx_hal_tim_ex.c

             └ stm32f4xx_hal_uart.c

TAGEC11
  • 12 次
  • 1 分