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:
- 22:2c37ac12746e
- Parent:
- 21:fe0ea1860c9f
- Child:
- 24:078f62c8d0ed
--- a/src/main.cpp Fri Jan 11 21:45:55 2019 +0000 +++ b/src/main.cpp Tue Jan 15 01:32:33 2019 +0000 @@ -27,6 +27,7 @@ //------------------------------------------------------------------------------- #include "mbed.h" +#include "math.h" #include "globals.h" #include "parameters.h" #include "all_io.h" @@ -51,7 +52,11 @@ double CURRENT_48_OFFSET = 33940; double CURRENT_24_OFFSET = 33580; -double CURRENT_12_OFFSET = 33380; +double CURRENT_12_OFFSET = 33256; + +unsigned short row = 0; +int row_test = 0; +int row_print = 0; Timer masterTimer; @@ -70,8 +75,12 @@ 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(); //initBoards(adcVals); sprintf(strbuf, "\r\nPress Enter to continue"); @@ -87,6 +96,8 @@ { adcVals = getADCresults(); + dispVals = calcDisplayValues(adcVals); + statVals = checkLevels(adcVals); processCommand(); @@ -94,15 +105,30 @@ // 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); + //updateControls(CURRENT_12_OFFSET-adcVals.i12); + buck = TRUE; + }else{ + row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR)); + //updateControls(adcVals.i12-CURRENT_12_OFFSET); + 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(adcVals.i12 < CURRENT_12_OFFSET){ - updateControls(CURRENT_12_OFFSET-adcVals.i12); - buck = TRUE; - }else{ - updateControls(adcVals.i12-CURRENT_12_OFFSET); - buck = FALSE; - } + if(row_test>ROW_HYSTERESIS){ + old_row = row; + //updateControls(CURRENT_12_OFFSET-adcVals.i12); + if(row<=1023){ + updateControls(row); + } + row_print = row; + myled = !myled; + }//else if(row_test<=ROW_HYSTERESIS){ + // old_row = row; + // updateControls(row); + //} //count++; }else if(!testing){ //updateControls(my12); @@ -112,7 +138,7 @@ updateReady = FALSE; updateTerminal(adcVals, statVals); // May want to gate this call when we run a headless system. //loopTime = masterTimer.read_ms();// - loopTime; - myled = !myled; + //myled = !myled; //sprintf(strbuf, "\r\nupdateControls ran %d times.\r\n", count); //sendSerial(strbuf); //count=0;