encoder

Dependencies:   mbed

Committer:
schille
Date:
Wed Apr 26 08:26:20 2017 +0000
Revision:
0:5067873a2400
mmn

Who changed what in which revision?

UserRevisionLine numberNew contents of line
schille 0:5067873a2400 1 #include "mbed.h"
schille 0:5067873a2400 2
schille 0:5067873a2400 3 void EncoderInit(TIM_Encoder_InitTypeDef * encoder, TIM_HandleTypeDef * timer, TIM_TypeDef * TIMx, uint32_t maxcount, uint32_t encmode)
schille 0:5067873a2400 4 {
schille 0:5067873a2400 5 timer->Instance = TIMx;
schille 0:5067873a2400 6 timer->Init.Period = maxcount;
schille 0:5067873a2400 7 timer->Init.CounterMode = TIM_COUNTERMODE_UP;
schille 0:5067873a2400 8 timer->Init.Prescaler = 0;
schille 0:5067873a2400 9 timer->Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
schille 0:5067873a2400 10
schille 0:5067873a2400 11 encoder->EncoderMode = encmode;
schille 0:5067873a2400 12
schille 0:5067873a2400 13 encoder->IC1Filter = 0x0F;
schille 0:5067873a2400 14 encoder->IC1Polarity = TIM_INPUTCHANNELPOLARITY_RISING;
schille 0:5067873a2400 15 encoder->IC1Prescaler = TIM_ICPSC_DIV1;
schille 0:5067873a2400 16 encoder->IC1Selection = TIM_ICSELECTION_DIRECTTI;
schille 0:5067873a2400 17
schille 0:5067873a2400 18 encoder->IC2Filter = 0x0F;
schille 0:5067873a2400 19 encoder->IC2Polarity = TIM_INPUTCHANNELPOLARITY_FALLING;
schille 0:5067873a2400 20 encoder->IC2Prescaler = TIM_ICPSC_DIV1;
schille 0:5067873a2400 21 encoder->IC2Selection = TIM_ICSELECTION_DIRECTTI;
schille 0:5067873a2400 22
schille 0:5067873a2400 23 if (HAL_TIM_Encoder_Init(timer, encoder) != HAL_OK) {
schille 0:5067873a2400 24 //printf("Couldn't Init Encoder\r\n");
schille 0:5067873a2400 25 //while (1) {}
schille 0:5067873a2400 26 }
schille 0:5067873a2400 27
schille 0:5067873a2400 28 if(HAL_TIM_Encoder_Start(timer,TIM_CHANNEL_1)!=HAL_OK) {
schille 0:5067873a2400 29 //printf("Couldn't Start Encoder\r\n");
schille 0:5067873a2400 30 //while (1) {}
schille 0:5067873a2400 31 }
schille 0:5067873a2400 32 }
schille 0:5067873a2400 33