A program to monitor some parameters for a motor

Dependencies:   mbed-dev BufferSerial

Thanks to David Lowe for https://developer.mbed.org/users/gregeric/code/Nucleo_Hello_Encoder/ which I adapted for the use of TIM2 32bit timer as an encoder reader on the Nucleo L432KC board.

Revision:
1:a611582bffa7
Parent:
0:789510d98ade
Child:
2:958e9094b198
--- a/main.cpp	Wed Mar 08 16:59:48 2017 +0000
+++ b/main.cpp	Wed Mar 08 21:37:30 2017 +0000
@@ -21,15 +21,15 @@
 #include "mbed.h"
 #include "Encoder.h"
 
-TIM_Encoder_InitTypeDef encoder2; // encoder3, encoder4;
-TIM_HandleTypeDef timer2; //  timer3,  timer4;
+TIM_Encoder_InitTypeDef encoder1, encoder2; // encoder3, encoder4;
+TIM_HandleTypeDef timer1,  timer2; //  timer3,  timer4;
 
 int main()
 {
     //examples
     
     //counting on A-input only, 2 ticks per cycle, rolls over at 100
-    //EncoderInit(&encoder1, &timer1, TIM1, 99, TIM_ENCODERMODE_TI1);
+    EncoderInit(&encoder1, &timer1, TIM1, 0xffff, TIM_ENCODERMODE_TI12);
 
     //counting on both A&B inputs, 4 ticks per cycle, full 32-bit count
     EncoderInit(&encoder2, &timer2, TIM2, 0xffffffff, TIM_ENCODERMODE_TI12);
@@ -46,16 +46,16 @@
     printf("STM HAL encoder demo\n\r");
     
     while(1) {
-        //uint16_t count1=0, count3=0, count4=0;
+        uint16_t count1=0; // count3=0, count4=0;
         uint32_t count2=0;
-        int8_t dir2; // dir3, dir4;
+        int8_t dir1, dir2; // dir3, dir4;
 
         
         //OK 401 411 446 TICKER 030
         //count1=TIM1->CNT;
         //dir1=TIM1->CR1&TIM_CR1_DIR;
-        //count1=__HAL_TIM_GET_COUNTER(&timer1);
-        //dir1 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer1);
+        count1= __HAL_TIM_GET_COUNTER(&timer1);
+        dir1 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer1);
 
         //OK 401 411 446 NOK 030
         //count2=TIM2->CNT;
@@ -79,7 +79,7 @@
 //        count5=__HAL_TIM_GET_COUNTER(&timer5);
 //        dir5 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer5);
         
-        printf("%d%s\r\n", count2, dir2==0 ? "+":"-" );
+        printf("%d%s %d%s\r\n", count1, dir1==0 ? "+":"-", count2, dir2==0 ? "+":"-" );
         wait(0.5);
     }
 }