找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4914|回复: 0
收起左侧

STM32F4正交解码编码器源码

[复制链接]
ID:343556 发表于 2018-10-8 12:49 | 显示全部楼层 |阅读模式
STM32F4  正交解码编码器

单片机源程序:
  1. #include "sys.h"
  2. #include "ENCODER.h"



  3. //TIM5_CH1 ----- PA0
  4. //TIM5_CH2 ----- PA1

  5. void Encoder_Configuration(void)//编码器模式
  6. {
  7.     GPIO_InitTypeDef gpio;
  8.    
  9.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOC,ENABLE);
  10.     RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM5|RCC_APB1Periph_TIM3 ,ENABLE);
  11.    
  12.     gpio.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  13.     gpio.GPIO_Mode = GPIO_Mode_AF;
  14.     gpio.GPIO_OType = GPIO_OType_PP;
  15.     gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
  16.     gpio.GPIO_Speed = GPIO_Speed_100MHz;
  17.    
  18.      GPIO_Init(GPIOA,&gpio);
  19.     gpio.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;       
  20.         GPIO_Init(GPIOC,&gpio);

  21.     GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,  GPIO_AF_TIM5);
  22.     GPIO_PinAFConfig(GPIOA, GPIO_PinSource1,  GPIO_AF_TIM5);
  23.    
  24.         GPIO_PinAFConfig(GPIOC, GPIO_PinSource6,  GPIO_AF_TIM3);
  25.     GPIO_PinAFConfig(GPIOC, GPIO_PinSource7,  GPIO_AF_TIM3);
  26.        
  27.     TIM_EncoderInterfaceConfig(TIM5, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
  28.         TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
  29.     TIM_Cmd(TIM5, ENABLE);
  30.                     TIM_Cmd(TIM3, ENABLE);
  31. }
复制代码

所有资料51hei提供下载:
正交解码编码器.rar (479.76 KB, 下载次数: 124)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表