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 /* Includes ------------------------------------------------------------------*/
schille 0:5067873a2400 2 #include "mbed.h"
schille 0:5067873a2400 3 #include "stm32f4xx_hal_tim.h"
schille 0:5067873a2400 4
schille 0:5067873a2400 5 /* Private variables ---------------------------------------------------------*/
schille 0:5067873a2400 6 TIM_Encoder_InitTypeDef encoder1, encoder2;
schille 0:5067873a2400 7 TIM_HandleTypeDef timer1, timer2;
schille 0:5067873a2400 8
schille 0:5067873a2400 9 /* Private function prototypes -----------------------------------------------*/
schille 0:5067873a2400 10 void EncoderInit(TIM_Encoder_InitTypeDef * encoder, TIM_HandleTypeDef * timer, TIM_TypeDef * TIMx, uint32_t maxcount, uint32_t encmode);
schille 0:5067873a2400 11
schille 0:5067873a2400 12
schille 0:5067873a2400 13 Serial pc(USBTX, USBRX);
schille 0:5067873a2400 14
schille 0:5067873a2400 15 int main(void)
schille 0:5067873a2400 16 {
schille 0:5067873a2400 17 uint16_t count1=0, count2=0;
schille 0:5067873a2400 18 pc.printf("\e[1;1H\e[2J");
schille 0:5067873a2400 19
schille 0:5067873a2400 20 /* Initialize Timer as Encoder */
schille 0:5067873a2400 21
schille 0:5067873a2400 22 EncoderInit(&encoder1, &timer1, TIM1, 65535, TIM_ENCODERMODE_TI2);
schille 0:5067873a2400 23 EncoderInit(&encoder2, &timer2, TIM3, 65535, TIM_ENCODERMODE_TI2);
schille 0:5067873a2400 24
schille 0:5067873a2400 25 while (1)
schille 0:5067873a2400 26 {
schille 0:5067873a2400 27 count1=__HAL_TIM_GET_COUNTER(&timer1); /* Read Counter Value */
schille 0:5067873a2400 28 count2=__HAL_TIM_GET_COUNTER(&timer2); /* Read Counter Value */
schille 0:5067873a2400 29 printf("COUNT1 %d COUNT2 %d\r\n", count1, count2);
schille 0:5067873a2400 30
schille 0:5067873a2400 31 wait(0.1);
schille 0:5067873a2400 32 }
schille 0:5067873a2400 33 }