PNI / Mbed 2 deprecated VSG_DataLogger1_VariableSpeed

Dependencies:   SDFileSystemVSG mbed

Fork of VSG_DataLogger1 by PNI

Files at this revision

API Documentation at this revision

Comitter:
jtrojan
Date:
Sat Sep 01 00:09:59 2018 +0000
Parent:
12:bdb601ce5dfd
Commit message:
changing data rate in timeout

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Aug 31 20:49:19 2018 +0000
+++ b/main.cpp	Sat Sep 01 00:09:59 2018 +0000
@@ -61,7 +61,7 @@
 SPI         mag(SPI_MOSI, SPI_MISO, SPI_SCK);
 SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCK, SD_CSN, "sd"); // the pinout on the mbed Cool Components workshop board
 Serial      console(PA_2, PA_3,115200); // debug port
-Ticker      magTimer;
+Timeout      magTimer;
 Timer       t;
 
 //-------------------- Variable speed settings------------------------
@@ -78,11 +78,28 @@
 //--------------------------------------------------------------------
 
 char takeAsample_F;
+int ncnt = 1;
+int magdt_n = 0;
 
 void sampletimer()
 {
+    if (ncnt < N_REPEAT_LOW) {
+        magTimer.attach(&sampletimer,magdt_low[magdt_n]);
+        }
+    
+    if (ncnt >= N_REPEAT_LOW) {
+        magTimer.attach(&sampletimer,magdt_high[magdt_n]);
+        }
+
+    ncnt++;
+    if (ncnt >= N_REPEAT_LOW+N_REPEAT_HIGH) {
+        ncnt=0;
+        magdt_n++;
+        if (magdt_n >= nspeeds) magdt_n=0;
+    }
+
     takeAsample_F = 1;
-//    printf("*");
+    //printf("*");
 }
 
 
@@ -138,7 +155,7 @@
     response = mag.write(PW_REGISTER);     // password register
     response = mag.write(PW);     // input password
     sel1a = 1;
-    
+
     printf("\r\nVSG Datalogger\r\n");
     printf("Timer interval = %f (sec)\r\n",SAMPLE_INTERVAL);
     printf("Cycle Counts = %d \r\n", CYCLE_COUNT);
@@ -211,7 +228,7 @@
     }
 
     // BIST Complete
-    
+
     // Set Cycle Count for all axes
     sel1a = 0;
     mcc_v = ((mag_cc[n_ss] >> 8) & 0xff);
@@ -222,7 +239,7 @@
         response = mag.write(lcc_v);
     }
     sel1a = 1;
-    
+
 
     //if (dbpin) printf("count,temp,X1a,Y1a,Z1a,X1b,Y1b,Z1b,X1c,Y1c,Z1c,X2a,Y2a,Z2a,X2b,Y2b,Z2b,X2c,Y2c,Z2c\r\n");
 
@@ -239,7 +256,7 @@
     //Now go read the STM internal channel selected above
     HAL_ADC_ConfigChannel(&hadc1, &sConfig);
     HAL_ADC_Start(&hadc1); // Start conversion
-    
+
     // MAIN LOOP
     while (count < MAX_COUNT) {
 
@@ -255,15 +272,15 @@
             //printf("high");
         }
 
-        
+
         tprev = t.read(); //time at start of loop
-        while(!takeAsample_F){
-             wait_us(10); // required
-             debugPin = 1;
+        while(!takeAsample_F) {
+            wait_us(10); // required
+            debugPin = 1;
         }
         takeAsample_F = 0;
         debugPin = 0;
-        
+
         sel1a = 0;
         response = mag.write(MAG_REG);     // Mag single measurement Register
         response = mag.write(ALL_AXES);     // start single measurement - all Axes
@@ -277,11 +294,11 @@
         HAL_ADC_Start(&hadc1); // Start conversion
 
         LED = 0;
-        while (!(rdy1a)){
+        while (!(rdy1a)) {
             wait_us(10);// spin here until all Data Ready signals go high
         }
         LED = 1;
-        
+
         sel1a = 0;
         response = mag.write(MX_REG);     // Read back mag data
         response = mag.write(0);
@@ -305,7 +322,7 @@
         sel1a = 1;
 
         if (islow < 1) { // try to change rate within 1.3s of reading data
-            // Set Cycle Count for all axes
+            /*// Set Cycle Count for all axes
             sel1a = 0;
             mcc_v = ((mag_cc[n_ss] >> 8) & 0xff);
             lcc_v = (mag_cc[n_ss] & 0xff);
@@ -314,14 +331,14 @@
                 response = mag.write(mcc_v);
                 response = mag.write(lcc_v);
             }
-            sel1a = 1;
+            sel1a = 1;*/
             // set next speed number
             n_ss++;
-            if (n_ss == nspeeds) n_ss = 0; // reset speed selector            
-            magTimer.attach(&sampletimer,magdt_low[n_ss]);
+            if (n_ss == nspeeds) n_ss = 0; // reset speed selector
+
         }
         if (nhigh < 1) { // try to change rate within 1.3s of reading data
-            magTimer.attach(&sampletimer,magdt_high[n_ss]);
+
         }
 
         // send/save data after receiving it
@@ -350,6 +367,7 @@
                     printf("%s",disp_buffer);
                 } else {
                     fprintf(sd,"%s",disp_buffer);
+                    //printf("%i ",ncnt);
                     printf("%s",disp_buffer);
                     //printf("%i\r\n",count);
                 }