標(biāo)題: 求助STM32F030F4P6單片機(jī)芯片使用EC11旋轉(zhuǎn)編碼器的代碼 [打印本頁(yè)]

作者: xuantian110    時(shí)間: 2023-3-16 23:04
標(biāo)題: 求助STM32F030F4P6單片機(jī)芯片使用EC11旋轉(zhuǎn)編碼器的代碼
主要功能是想實(shí)現(xiàn)使用EC11旋轉(zhuǎn)編碼器控制 LED燈的亮度,嘗試移植stm32f103的代碼,但是一直沒(méi)有成功,有大佬能幫忙看下么
  1. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  2.         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  3.         
  4.         GPIO_InitTypeDef GPIO_InitStructure;
  5.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  6.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  7.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  8.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  9.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  10.         
  11.         GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_1);
  12.   GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_2);
  13.         
  14.         TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
  15.         TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  16.         TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  17.         TIM_TimeBaseInitStructure.TIM_Period = 65535-1;
  18.         TIM_TimeBaseInitStructure.TIM_Prescaler = 1-1;
  19.         TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
  20.         TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
  21.         
  22.         TIM_ICInitTypeDef TIM_ICInitStructure;
  23.         TIM_ICStructInit(&TIM_ICInitStructure);
  24.         TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
  25.         TIM_ICInitStructure.TIM_ICFilter = 0xF;
  26.         TIM_ICInit(TIM3, &TIM_ICInitStructure);
  27.         
  28.         TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  29.         TIM_ICInitStructure.TIM_ICFilter = 0xF;
  30.         TIM_ICInit(TIM3, &TIM_ICInitStructure);
  31.         
  32.         TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
  33.         TIM_Cmd(TIM3, ENABLE);
復(fù)制代碼




作者: haxiny    時(shí)間: 2023-3-17 10:07
之前做過(guò)F030控制EC11編碼器。代碼放哪了不記得了。
作者: boboxuexi    時(shí)間: 2023-3-17 10:34
看我主頁(yè)
作者: GlenXu    時(shí)間: 2023-3-17 11:24
沒(méi)看見(jiàn)你讀計(jì)數(shù)器值,怎么知道錯(cuò)了。
兩外計(jì)數(shù)器要設(shè)初值(例如2000或10000,具體看你的脈沖速度),
否則新手不明白反轉(zhuǎn)一個(gè)脈沖就溢出或數(shù)字很大。
作者: jinhua1916    時(shí)間: 2023-4-8 18:23
編碼器調(diào)正弦波頻率;里面有介紹。在正點(diǎn)原子論壇搜索一下。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1