Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: src/main.cpp
- Revision:
- 43:291bbdba48f3
- Parent:
- 42:3ae73b61f657
- Child:
- 44:741ee27c8a34
--- a/src/main.cpp	Sat Mar 09 21:01:45 2019 +0000
+++ b/src/main.cpp	Sat Mar 09 21:16:38 2019 +0000
@@ -53,6 +53,12 @@
 bool running = FALSE;
 bool testing = FALSE;
 bool buck = TRUE;
+bool pcConnected = FALSE;
+unsigned int max_rows = 2048;
+unsigned int bCodeRow[13];
+unsigned int max_boards = 3;
+unsigned short row = 0;
+int row_test = 0;
 
 double CURRENT_48_OFFSET = 33940;
 double CURRENT_24_OFFSET = 33580;
@@ -75,9 +81,77 @@
     
     slowClk.attach(&slowFlip, 0.0003);
     fastClk.attach(&fastFlip, 0.00001);
+
+    running = FALSE;
+   
+    initSerial();
     
-    while(1){
-        checkFlip();
-    }
-    
-}
\ No newline at end of file
+    initDRT(); // Display Refresh Timer
+   
+    initADC();
+
+    struct adcValues adcVals = getADCresults();
+    struct displayValues dispVals = calcDisplayValues(adcVals);
+    struct statusValues statVals = checkLevels(adcVals);
+   
+    row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR);
+    unsigned int old_row = row;
+   
+    menu_banner();
+    sprintf(strbuf, "\r\nPress Enter to continue");
+    sendSerial(strbuf);
+    //while(waitCommand()){ // Wait for user to press Enter
+    //}
+   
+    menuRedraw(WITH_PROMPT);
+   
+    initBoards(adcVals);
+
+    while (1)
+    {
+      adcVals = getADCresults();
+      
+      dispVals = calcDisplayValues(adcVals);
+      
+      statVals = checkLevels(adcVals);
+      
+      processCommand();
+      
+      checkFlip();
+
+      // Select RUN from menu to activate running mode.
+      // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode.
+      // CAL and UNCAL do not change state of running or testing.
+      if(adcVals.i12 < CURRENT_12_OFFSET){    
+            row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR);
+            buck = TRUE;
+      }else{
+            row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR));
+            buck = FALSE;
+      }
+      row_test = abs((int)(row-old_row));
+      if(running){
+          //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode.
+          if(row_test>ROW_HYSTERESIS){
+             old_row = row;
+             if(row<=1023){
+                 updateControls(row);
+             }
+            }
+      }else if(!testing){
+          row_test = abs((int)(my12-old_row));
+          if(row_test>ROW_HYSTERESIS){
+             old_row = my12;
+             if(row<=1023){
+                 updateControls(my12);
+             }
+          }
+      }
+      
+      if(updateReady && pcConnected){
+         updateReady = FALSE;
+         updateTerminal(adcVals, statVals);  // May want to gate this call when we run a headless system.
+
+      }
+    }//end while(1)
+}//end void main(void)
\ No newline at end of file