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.
Dependencies: mbed
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 timer->Instance = TIMx; 00006 timer->Init.Period = maxcount; 00007 timer->Init.CounterMode = TIM_COUNTERMODE_UP; 00008 timer->Init.Prescaler = 0; 00009 timer->Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; 00010 00011 encoder->EncoderMode = encmode; 00012 00013 encoder->IC1Filter = 0x0F; 00014 encoder->IC1Polarity = TIM_INPUTCHANNELPOLARITY_RISING; 00015 encoder->IC1Prescaler = TIM_ICPSC_DIV1; 00016 encoder->IC1Selection = TIM_ICSELECTION_DIRECTTI; 00017 00018 encoder->IC2Filter = 0x0F; 00019 encoder->IC2Polarity = TIM_INPUTCHANNELPOLARITY_FALLING; 00020 encoder->IC2Prescaler = TIM_ICPSC_DIV1; 00021 encoder->IC2Selection = TIM_ICSELECTION_DIRECTTI; 00022 00023 if (HAL_TIM_Encoder_Init(timer, encoder) != HAL_OK) { 00024 //printf("Couldn't Init Encoder\r\n"); 00025 //while (1) {} 00026 } 00027 00028 if(HAL_TIM_Encoder_Start(timer,TIM_CHANNEL_1)!=HAL_OK) { 00029 //printf("Couldn't Start Encoder\r\n"); 00030 //while (1) {} 00031 } 00032 } 00033
Generated on Tue Jul 12 2022 17:56:30 by
1.7.2