找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5544|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

STM32F4正交解碼編碼器源碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:343556 發(fā)表于 2018-10-8 12:49 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
STM32F4  正交解碼編碼器

單片機(jī)源程序:
  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. }
復(fù)制代碼

所有資料51hei提供下載:
正交解碼編碼器.rar (479.76 KB, 下載次數(shù): 124)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表