Progetto STM32 / Mbed 2 deprecated Encoder3

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Includes ------------------------------------------------------------------*/
00002 #include "mbed.h"
00003 #include "stm32f4xx_hal_tim.h"
00004 
00005 /* Private variables ---------------------------------------------------------*/
00006 TIM_Encoder_InitTypeDef encoder1, encoder2;
00007 TIM_HandleTypeDef timer1, timer2;
00008 
00009 /* Private function prototypes -----------------------------------------------*/
00010 void EncoderInit(TIM_Encoder_InitTypeDef * encoder, TIM_HandleTypeDef * timer, TIM_TypeDef * TIMx, uint32_t maxcount, uint32_t encmode);
00011 
00012 
00013 Serial pc(USBTX, USBRX);
00014 
00015 int main(void)
00016 {
00017     uint16_t count1=0, count2=0;
00018     pc.printf("\e[1;1H\e[2J");
00019 
00020 /* Initialize Timer as Encoder */
00021  
00022  EncoderInit(&encoder1, &timer1, TIM1, 65535, TIM_ENCODERMODE_TI2);
00023  EncoderInit(&encoder2, &timer2, TIM3, 65535, TIM_ENCODERMODE_TI2);
00024  
00025   while (1)
00026   {
00027     count1=__HAL_TIM_GET_COUNTER(&timer1); /* Read Counter Value */
00028     count2=__HAL_TIM_GET_COUNTER(&timer2); /* Read Counter Value */
00029     printf("COUNT1 %d COUNT2 %d\r\n", count1, count2);
00030     
00031     wait(0.1);
00032   }
00033 }