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 23:5cd74e296f59, committed 2017-06-22
- Comitter:
- tonnyleonard
- Date:
- Thu Jun 22 10:41:57 2017 +0000
- Parent:
- 22:9bba1417e4a4
- Commit message:
- Correct adc2 calibration offset and the dac1 calibration factor and offset, remove some junk comments
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jun 22 02:04:21 2017 +0000
+++ b/main.cpp Thu Jun 22 10:41:57 2017 +0000
@@ -97,7 +97,7 @@
//Array with adc1, adc2 & adc3 correction addition,
//experimentally determined (hardware offset voltage dependent)
-const float adc_corr[] = { 0, 0.022f, 0.062f, 0.022f};
+const float adc_corr[] = { 0, 0.022f, 0.022f, 0.022f};
//Enable ADC reading and printing to the serial interface
bool adc_en = true;
@@ -193,8 +193,6 @@
printf("E:Speed computation error, change of direction between readings!\n");
}
- //For debugging
- //printf("%lu microseconds, %ld steps: start:%lu stop%lu\n", deltaT, pos, pos1, pos2);
if (deltaT > 0) {
//speed computation in rot/s
speed = ((float) pos)*125.f/((float) deltaT); // (pulses/us)*1000000/8000 -> rot/s
@@ -233,8 +231,8 @@
printf("M:ADC false\n");
} else if (p1=strstr(message, "v=") != NULL) {
//Writing the dac1 value read from serial
- //The DCPS has 1.2V offset, so we have to remove it
- dac_val = (atof(message+p1+1)-1.2f)/15.9;
+ //The DCPS has 1V offset, so we have to remove it
+ dac_val = (atof(message+p1+1)-1.f)/15.51;
dac1.write(dac_val);
} else if (strcmp(message, "reset") == 0) {
//encoder related counters reset command
@@ -308,6 +306,7 @@
//Make sure the DCPS is off
relay1.write(0);
//Set the DCPS output to (0.32x3.3)x4.7+1 = ~6V
+ //These parameters are set for DCPS on load
dac1.write(0.32);
//counting on both A&B inputs (A at PA0, B at PA1), 4 ticks per cycle,
@@ -351,10 +350,6 @@
dir1 = __HAL_TIM_IS_TIM_COUNTING_DOWN(&timer2);
printf("P:%ldD:%sC:%d", count1, dir1==0 ? "+":"-", count2);
if (posIndex_en) {
- // Does not work if speed computation is enabled and uses wait(),
- // because speed computation may take too long and wait()
- // disables other interrupts, therefore the index pulse
- // interrupt as well.
if (count2 > 1) {
printf("Pi:%ld", (count1-count4) + (count2-1)*8000 + count3);
} else if (count2 < -1) {
@@ -366,20 +361,17 @@
}
if (speed_en) {
- //Print speed
- printf("S:%.3f%", speedRead()); // in rot/s
+ //Print speed in rot/s
+ printf("S:%.3f%", speedRead());
}
if (adc_en) {
//Print phase shift in Degrees, DCPS output voltage in Volts
// and current intensity in Ampers
+ // The dividing factors are hardware dependant
printf("F:%3.3fU:%3.3fI:%3.3f", (3.3f*ADC_read(adc1)+adc_corr[1])*125.62f,
(3.3f*ADC_read(adc2)+adc_corr[2])/0.207f,
3.3f*ADC_read(adc3)+adc_corr[3]);
- //Print DCPS output voltage in Volts
- //printf("U:%3.3f%", (3.3f*ADC_read(adc2)+0.062f)/0.207f);
- //Print current intensity in Ampers
- //printf("I:%3.3f%\n", 3.3f*ADC_read(adc3)+0.022f);
}
printf("\n");