4 Rotary encoders with 5110 LCD display. For Nucleo boards

Dependencies:   N5110 mbed

Committer:
triochi
Date:
Mon Oct 24 17:21:58 2016 +0000
Revision:
10:65e7ceb96b39
Parent:
7:62c2c1382d86
finally working 4 encoders

Who changed what in which revision?

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