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
main.cpp
00001 //------------------------------------------------------------------------------- 00002 // 00003 // Treehouse Designs Inc. 00004 // Colorado Springs, Colorado 00005 // 00006 // Copyright (c) 2016 by Treehouse Designs Inc. 00007 // Copyright (c) 2018 by Agility Power Systems Inc. 00008 // 00009 // This code is the property of Treehouse Designs, Inc. (Treehouse) and 00010 // Agility Power Systems Inc. (Agility) and may not be redistributed 00011 // in any form without prior written permission from 00012 // both copyright holders, Treehouse and Agility. 00013 // 00014 // The above copyright notice and this permission notice shall be included in 00015 // all copies or substantial portions of the Software. 00016 // 00017 // 00018 //------------------------------------------------------------------------------- 00019 // 00020 // REVISION HISTORY: 00021 // 00022 // $Author: $ 00023 // $Rev: $ 00024 // $Date: $ 00025 // $URL: $ 00026 // 00027 //------------------------------------------------------------------------------- 00028 00029 #include "mbed.h" 00030 #include "math.h" 00031 #include "globals.h" 00032 #include "parameters.h" 00033 #include "all_io.h" 00034 #include "stdio.h" 00035 #include "stdlib.h" 00036 #include "serial.h" 00037 #include "adc.h" 00038 #include "adc_defs.h" 00039 #include "menu.h" 00040 #include "boards.h" 00041 #include "command.h" 00042 00043 unsigned int en_out_code; 00044 unsigned int wr_out_code; 00045 unsigned int max_boards = 13; 00046 unsigned int max_rows = 2048; 00047 //unsigned int bCodeArray[2048][13]; 00048 unsigned int bCodeRow[13]; 00049 00050 unsigned short my12=0; 00051 volatile bool updateReady = FALSE; 00052 unsigned int loopTime = 0; 00053 bool raw = FALSE; 00054 bool running = FALSE; 00055 bool testing = FALSE; 00056 bool buck = TRUE; 00057 00058 double CURRENT_48_OFFSET = 33940; 00059 double CURRENT_24_OFFSET = 33580; 00060 double CURRENT_12_OFFSET = 33256; 00061 00062 unsigned short row = 0; 00063 int row_test = 0; 00064 int row_print = 0; 00065 00066 Timer masterTimer; 00067 00068 int main() 00069 { 00070 myled = 0; 00071 extchlat = OFF; 00072 wr_out_code = setBoardEnables(ALLON); 00073 en_out_code = setBoardWeights(32); 00074 running = FALSE; 00075 00076 initSerial(); 00077 00078 initDRT(); // Display Refresh Timer 00079 00080 initADC(); 00081 00082 struct adcValues adcVals = getADCresults(); 00083 struct displayValues dispVals = calcDisplayValues(adcVals); 00084 struct statusValues statVals = checkLevels(adcVals); 00085 00086 row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR); 00087 unsigned int old_row = row; 00088 00089 menu_banner(); 00090 //initBoards(adcVals); 00091 sprintf(strbuf, "\r\nPress Enter to continue"); 00092 sendSerial(strbuf); 00093 while(waitCommand()){ // Wait for user to press Enter 00094 } 00095 00096 menuRedraw(WITH_PROMPT); 00097 00098 initBoards(adcVals); 00099 00100 while (1) 00101 { 00102 adcVals = getADCresults(); 00103 00104 dispVals = calcDisplayValues(adcVals); 00105 00106 statVals = checkLevels(adcVals); 00107 00108 processCommand(); 00109 00110 // Select RUN from menu to activate running mode. 00111 // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode. 00112 // CAL and UNCAL do not change state of running or testing. 00113 if(adcVals.i12 < CURRENT_12_OFFSET){ 00114 row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR); 00115 //updateControls(CURRENT_12_OFFSET-adcVals.i12); 00116 buck = TRUE; 00117 }else{ 00118 //row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR)); 00119 row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR)); 00120 //updateControls(adcVals.i12-CURRENT_12_OFFSET); 00121 buck = FALSE; 00122 } 00123 row_test = abs((int)(row-old_row)); 00124 if(running){ 00125 //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode. 00126 if(row_test>ROW_HYSTERESIS){ 00127 old_row = row; 00128 //updateControls(CURRENT_12_OFFSET-adcVals.i12); 00129 if(row<=1023){ 00130 updateControls(row); 00131 } 00132 row_print = row; 00133 myled = !myled; 00134 }//else if(row_test<=ROW_HYSTERESIS){ 00135 // old_row = row; 00136 // updateControls(row); 00137 //} 00138 //count++; 00139 }else if(!testing){ 00140 row_test = abs((int)(my12-old_row)); 00141 if(row_test>ROW_HYSTERESIS){ 00142 old_row = my12; 00143 //updateControls(CURRENT_12_OFFSET-adcVals.i12); 00144 if(row<=1023){ 00145 //updateControls(row); 00146 updateControls(my12); 00147 } 00148 row_print = my12; 00149 myled = !myled; 00150 } 00151 } 00152 00153 if(updateReady){ 00154 updateReady = FALSE; 00155 updateTerminal(adcVals, statVals); // May want to gate this call when we run a headless system. 00156 //loopTime = masterTimer.read_ms();// - loopTime; 00157 //myled = !myled; 00158 00159 } 00160 }//end while(1) 00161 }//end void main(void) 00162
Generated on Sat Aug 27 2022 12:36:03 by
1.7.2