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:
13:e08e3540c30b
Parent:
12:8c355d78e081
Child:
14:e5f5b345b2fe
--- a/main.cpp	Fri Jun 02 18:14:16 2017 +0000
+++ b/main.cpp	Fri Jun 02 21:30:49 2017 +0000
@@ -93,9 +93,10 @@
 float speedLast=0;
 
 float dac_val=0;
+float dac2_val=0;
 float adc3_val=0;
 
-volatile bool adc3_en = false;
+volatile bool adc3_en = true;
 int16_t lines = 4;
 
 //TIM1 to be used with the interrupt for the encoder's index pulses
@@ -187,7 +188,7 @@
             lines = 4;
             printf("false\r\n");
         } else if (p1=strstr(message, "DAC=") != NULL) {
-            dac_val = atof(message+p1+3);
+            dac_val = (atof(message+p1+3)-0.5f)/15.61;
             dac2.write(dac_val);
             printf("Value to write to DAC: %f\r\n", dac_val*3.3f);
         } else if (strcmp(message, "reset") == 0) {
@@ -257,6 +258,7 @@
 
         //It resets the DAC1
         //dac1.free();
+        dac2_val = dac2.read();
 
         //It writes the DAC1 value as a 16bit number
         //dac1.write_u16(count3*2);
@@ -274,9 +276,9 @@
             dac1.write(adc3_val);
             
             printf("%ld%s passes=%d\r\n", count3, dir1==0 ? "+":"-", count2);
-            printf("Voltage ADC1= %3.3f%V, DAC=%f\r\n", adc1.read()*3.3f, dac2.read()*3.3f);
-            //printf("Vref: %f\r\n", vref.read());
-            printf("Voltage ADC2: %3.3f%V\r\n", adc2.read()*3.3f);
+            printf("Voltage ADC1= %3.3f%V, DAC=%f\r\n", adc1.read()*3.3f, dac2_val*3.3f);
+            printf("VOUT: %f\r\n", dac2_val*15.61+0.5);
+            printf("Voltage ADC2: %3.3f%V\r\n", (adc2.read()*3.3f+0.022)/0.207048458f);
 
             //printf("Vref(f): %f, Vref : %u, Temperature : %u\r\n",
             //         vref.read(), vref.read_u16(), tempint.read_u16());