最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

江科大學(xué)習(xí)筆記 _8.編碼器測(cè)速

2023-06-12 10:06 作者:自閉選手的Z23  | 我要投稿


1.?RCC時(shí)鐘,GPIO/TIM

2.?配置GPIO,輸入模式

3.?配置時(shí)基單元

4.?配置輸入捕獲單元

5.?配置編碼器模式

6.?TI_Cmd

?

?

1.RCC時(shí)鐘,GPIO/TIM

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

?

2.配置GPIO,輸入模式

GPIO_InitTypeDef GPIO_InitStruct;

????GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;

????GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;

????GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_InitStruct);

?

3.配置時(shí)基單元

????TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;

????TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;

????TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;

????TIM_TimeBaseInitStruct.TIM_Period = 65536 - 1;//ARR

????TIM_TimeBaseInitStruct.TIM_Prescaler = 1 - 1; //PSC

????TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0;

????TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct);

4.配置輸入捕獲單元

????TIM_ICInitTypeDef TIM_ICInitStruct;

????TIM_ICStructInit(&TIM_ICInitStruct);

????TIM_ICInitStruct.TIM_Channel = TIM_Channel_1;

????TIM_ICInitStruct.TIM_ICFilter = 0XF;

????TIM_ICInitStruct.TIM_ICPolarity = TIM_ICPolarity_Rising;

????TIM_ICInit(TIM3, &TIM_ICInitStruct);

????

????TIM_ICInitStruct.TIM_Channel = TIM_Channel_2;

????TIM_ICInitStruct.TIM_ICFilter = 0XF;

TIM_ICInit(TIM3, &TIM_ICInitStruct);

?

5.配置編碼器模式

TIM_EncoderInterfaceConfig(TIM3,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);

?

6.TI_Cmd

?

?

?


int16_t Encoder_Get(void)

{

???int16_t temp;

????

???temp = ?TIM_GetCounter(TIM3);

???TIM_SetCounter(TIM3, 0);

????

???return temp;

}

?

void TIM2_IRQHandler(void)

{

????

????if(TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)

????{?

????????Speed = Encoder_Get();

????????TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

????}

}

?

While(1)中顯示Speed


江科大學(xué)習(xí)筆記 _8.編碼器測(cè)速的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
徐水县| 肃北| 新余市| 阳朔县| 冀州市| 襄城县| 南充市| 山西省| 罗源县| 雷州市| 宁阳县| 广汉市| 新营市| 松阳县| 招远市| 汝南县| 邵东县| 广水市| 通江县| 贺兰县| 中西区| 苗栗市| 于田县| 娱乐| 新平| 昌吉市| 镇巴县| 宜君县| 县级市| 奉节县| 富平县| 达州市| 旺苍县| 江西省| 汉川市| 临沂市| 尚义县| 香港| 凤翔县| 南部县| 小金县|