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:
6:5d4c09973041
Parent:
5:29372f6cb533
Child:
7:7f59b69d8895
--- a/main.cpp	Sat May 13 23:47:38 2017 +0000
+++ b/main.cpp	Sun May 14 21:44:05 2017 +0000
@@ -20,11 +20,16 @@
 
 #include "mbed.h"
 #include "Encoder.h"
+#include "inttypes.h"
 
 TIM_Encoder_InitTypeDef encoder1;
 TIM_HandleTypeDef timer2;
 InterruptIn event(PA_8);
 DigitalOut led(LED1);
+AnalogIn adc1(PA_3); //ADC1_IN8
+AnalogIn adc2(PA_5); //ADC1_IN10
+AnalogIn adc3(PA_6); //ADC1_IN11
+AnalogOut dac1(PA_4); // DAC1_OUT1
 uint32_t count1=0;
 int16_t count2=0;
 int16_t count3=0;
@@ -71,10 +76,13 @@
     
     printf("\n\rSTM HAL encoder with ADC and DAC\n\r");
     
+    //printf("%" PRIu32 "\n", UINT32_MAX);
+    
     while(1) {
         uint32_t count3=0;
         
         int8_t dir1;
+        uint16_t voltage1=0;
 
 
         //OK 401 411 446 NOK 030
@@ -82,9 +90,14 @@
         //dir1=TIM2->CR1&TIM_CR1_DIR;
         count3=__HAL_TIM_GET_COUNTER(&timer2);
         dir1 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer2);
-
+        voltage1=adc1.read_u16();
+        dac1.write_u16(count3*2);
         
         printf("%ld%s passes=%d short=%ld\r\n", count1+count3, dir1==0 ? "+":"-", count2, count3);
-        wait(0.1);
+        printf("Voltage= %d, DAC=%f\r\n", voltage1, dac1.read()*3.3);
+        printf("percentage: %3.3f%%\r\n", adc2.read()*100.0f);
+        printf("percentage: %3.3f%%\r\n", adc3.read()*100.0f);
+
+        wait(2.1);
     }
 }