Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of locate_by_hello_enc by
EncoderInit.cpp
00001 #include "mbed.h" 00002 00003 void EncoderInit(TIM_Encoder_InitTypeDef * encoder, TIM_HandleTypeDef * timer, TIM_TypeDef * TIMx, uint32_t maxcount, uint32_t encmode) 00004 { 00005 00006 timer->Instance = TIMx; 00007 timer->Init.Period = maxcount; 00008 timer->Init.CounterMode = TIM_COUNTERMODE_UP; 00009 timer->Init.Prescaler = 0; 00010 timer->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; 00011 00012 encoder->EncoderMode = encmode; 00013 00014 encoder->IC1Filter = 0x0F; 00015 encoder->IC1Polarity = TIM_INPUTCHANNELPOLARITY_RISING; 00016 encoder->IC1Prescaler = TIM_ICPSC_DIV4; 00017 encoder->IC1Selection = TIM_ICSELECTION_DIRECTTI; 00018 00019 encoder->IC2Filter = 0x0F; 00020 encoder->IC2Polarity = TIM_INPUTCHANNELPOLARITY_FALLING; 00021 encoder->IC2Prescaler = TIM_ICPSC_DIV4; 00022 encoder->IC2Selection = TIM_ICSELECTION_DIRECTTI; 00023 00024 00025 if (HAL_TIM_Encoder_Init(timer, encoder) != HAL_OK) { 00026 printf("Couldn't Init Encoder\r\n"); 00027 while (1) {} 00028 } 00029 00030 if(HAL_TIM_Encoder_Start(timer,TIM_CHANNEL_1)!=HAL_OK) { 00031 printf("Couldn't Start Encoder\r\n"); 00032 while (1) {} 00033 } 00034 } 00035
Generated on Sun Jul 17 2022 23:05:29 by
