標(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)有成功,有大佬能幫忙看下么
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_2);
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period = 65535-1;
TIM_TimeBaseInitStructure.TIM_Prescaler = 1-1;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICFilter = 0xF;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICFilter = 0xF;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
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