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:
2:958e9094b198
Parent:
1:a611582bffa7
Child:
4:4f115819171f
--- a/main.cpp	Wed Mar 08 21:37:30 2017 +0000
+++ b/main.cpp	Sat Mar 11 22:56:39 2017 +0000
@@ -21,34 +21,26 @@
 #include "mbed.h"
 #include "Encoder.h"
 
-TIM_Encoder_InitTypeDef encoder1, encoder2; // encoder3, encoder4;
-TIM_HandleTypeDef timer1,  timer2; //  timer3,  timer4;
+TIM_Encoder_InitTypeDef encoder1, encoder2;
+TIM_HandleTypeDef timer1,  timer2;
 
 int main()
 {
-    //examples
     
     //counting on A-input only, 2 ticks per cycle, rolls over at 100
     EncoderInit(&encoder1, &timer1, TIM1, 0xffff, TIM_ENCODERMODE_TI12);
 
     //counting on both A&B inputs, 4 ticks per cycle, full 32-bit count
+    //For L432KC to work with TIM2 one needs to reassign the system ticker 
+    //from TIM2 to TIM7 in TARGET/../device/hal_tick.h
     EncoderInit(&encoder2, &timer2, TIM2, 0xffffffff, TIM_ENCODERMODE_TI12);
-
-    //counting on B-input only, 2 ticks per cycle, full 16-bit count
-    //EncoderInit(&encoder3, &timer3, TIM3, 0xffff, TIM_ENCODERMODE_TI2);
     
-    //counting on both A&B inputs, 4 ticks per cycle, full 16-bit count
-    //EncoderInit(&encoder4, &timer4, TIM4, 0xffff, TIM_ENCODERMODE_TI12);
-    
-    //TIM5 is used by mbed for systick
-    //EncoderInit(encoder2, timer2, TIM5, 0xffffffff, TIM_ENCODERMODE_TI12);
-    
-    printf("STM HAL encoder demo\n\r");
+    printf("\n\rSTM HAL encoder demo\n\r");
     
     while(1) {
-        uint16_t count1=0; // count3=0, count4=0;
+        uint16_t count1=0;
         uint32_t count2=0;
-        int8_t dir1, dir2; // dir3, dir4;
+        int8_t dir1, dir2;
 
         
         //OK 401 411 446 TICKER 030
@@ -63,23 +55,8 @@
         count2=__HAL_TIM_GET_COUNTER(&timer2);
         dir2 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer2);
 
-        //OK 401 411 446 030
-        //count3=TIM3->CNT;
-        //dir3=TIM3->CR1&TIM_CR1_DIR;
-        //count3=__HAL_TIM_GET_COUNTER(&timer3);
-        //dir3 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer3);
-
-        //OK 401 411 446 N/A 030
-        //count4=TIM4->CNT;
-        //dir4=TIM4->CR1&TIM_CR1_DIR;
-        //count4=__HAL_TIM_GET_COUNTER(&timer4);
-        //dir4 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer4);
-
-        //TICKER 401 411 446 N/A 030
-//        count5=__HAL_TIM_GET_COUNTER(&timer5);
-//        dir5 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer5);
         
         printf("%d%s %d%s\r\n", count1, dir1==0 ? "+":"-", count2, dir2==0 ? "+":"-" );
-        wait(0.5);
+        wait(0.1);
     }
 }