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
boards.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 "globals.h" 00031 #include "parameters.h" 00032 #include "boards.h" 00033 #include "lut.h" 00034 #include "all_io.h" 00035 #include "serial.h" 00036 #include "stdio.h" 00037 00038 unsigned int boardEnableBits; 00039 00040 void initBoards(struct adcValues adcVals){ 00041 /* 00042 sprintf(strbuf, "\r\nV48_HI=%d\r\n", V48_HI); 00043 sendSerial(strbuf); 00044 sprintf(strbuf, "\r\nV48=%d\r\n", adcVals.v48); 00045 sendSerial(strbuf); 00046 sprintf(strbuf, "\r\nV48_LO=%d\r\n", V48_LO); 00047 sendSerial(strbuf); 00048 */ 00049 en_out = 32; 00050 setBoardEnables(16383); 00051 00052 } 00053 00054 /******************************************************************************* 00055 delay 00056 *******************************************************************************/ 00057 void delay(long ticks) 00058 { 00059 long i; 00060 for(i=0;i<ticks;i++); 00061 } 00062 00063 /******************************************************************************* 00064 setBoardControls 00065 *******************************************************************************/ 00066 void setBoardControls(unsigned int tCode) 00067 { 00068 for(unsigned int b=0; b<max_boards; b++){ 00069 //wr_out = 0; 00070 en_out_code = bCodeRow[b]; 00071 00072 wr_out_code = 1<<b; 00073 wr_out = ~wr_out_code; 00074 en_out = en_out_code; 00075 00076 wait_us(250); 00077 00078 //sprintf(strbuf, "en_out=%d wr_out=%d\r\n", en_out_code, wr_out_code); 00079 //sendSerial(strbuf); 00080 } 00081 for(unsigned int b=max_boards; b<13; b++){ 00082 00083 wr_out_code = 1<<b; 00084 wr_out = ~wr_out_code; 00085 en_out = 0; 00086 00087 wait_us(250); 00088 00089 //sprintf(strbuf, "en_out=%d wr_out=%d\r\n", en_out_code, wr_out_code); 00090 //sendSerial(strbuf); 00091 } 00092 } 00093 00094 /******************************************************************************* 00095 setBoardEnables 00096 *******************************************************************************/ 00097 unsigned int setBoardEnables(unsigned int tCode) 00098 { 00099 wr_out = tCode; 00100 unsigned int en_out_save = en_out; 00101 en_out = 0; 00102 wr_out = ~tCode; 00103 en_out = en_out_save; 00104 return tCode; 00105 } 00106 00107 /******************************************************************************* 00108 setBoardWeights 00109 *******************************************************************************/ 00110 unsigned int setBoardWeights(unsigned int bCode) 00111 { 00112 en_out = bCode; 00113 toggleLatchSignal(); 00114 return bCode; 00115 } 00116 00117 /******************************************************************************* 00118 toggleLatchSignal 00119 *******************************************************************************/ 00120 void toggleLatchSignal(void){ 00121 extchlat = OFF; 00122 extchlat = ON; 00123 extchlat = OFF; 00124 } 00125 00126 /************************************************************ 00127 * Routine: checkRange 00128 * Input: setval 00129 * limlo -- low limit 00130 * limhi -- high limit 00131 * Returns: 1 if entry validates and is written 00132 * 0 if entry fails 00133 * -1 if it slips past 00134 * Description: 00135 * Checks if setvalue is between the given limits. 00136 * 00137 **************************************************************/ 00138 int checkRange(int setvalue, int limlo, int limhi) 00139 { 00140 if ((setvalue >= limlo) && (setvalue <= limhi)){ 00141 return 1; 00142 }else{ 00143 //showRangeError(0, 0, setvalue); 00144 return 0; 00145 } 00146 } 00147 00148 /******************************************************************************* 00149 startConverter 00150 *******************************************************************************/ 00151 void startConverter(unsigned int reg) 00152 { 00153 if(!running){ 00154 running = TRUE; 00155 // Fire in the hole! 00156 wr_out_code = setBoardEnables(reg); 00157 00158 sprintf(strbuf, "\r\nConverter started"); 00159 sendSerial(strbuf); 00160 } 00161 } 00162 00163 /******************************************************************************* 00164 stopConverter - stop the converter and set outputs to 0 00165 *******************************************************************************/ 00166 void stopConverter(void) 00167 { 00168 if(running){ 00169 en_out = 32; 00170 wr_out_code = setBoardEnables(ALLON); 00171 running = FALSE; 00172 sprintf(strbuf, "\r\nConverter stopped"); 00173 sendSerial(strbuf); 00174 } 00175 } 00176 00177 /******************************************************************************* 00178 checkLevels 00179 *******************************************************************************/ 00180 struct statusValues checkLevels(struct adcValues adcVals){ 00181 00182 struct statusValues statVals; 00183 00184 // Check 48V levels 00185 if(adcVals.v48 > V48_HI){ 00186 //if(buck){ 00187 // stopConverter(); 00188 //} 00189 statVals.V48_IS_HI = TRUE; 00190 statVals.V48_IS_LO = FALSE; 00191 }else if(adcVals.v48 < V48_LO){ 00192 //if(buck){ 00193 // stopConverter(); 00194 //} 00195 statVals.V48_IS_HI = FALSE; 00196 statVals.V48_IS_LO = TRUE; 00197 }else{ 00198 statVals.V48_IS_HI = FALSE; 00199 statVals.V48_IS_LO = FALSE; 00200 } 00201 00202 // Check 24V levels 00203 if(adcVals.v24 > V24_HI){ 00204 statVals.V24_IS_HI = TRUE; 00205 statVals.V24_IS_LO = FALSE; 00206 }else if(adcVals.v24 < V24_LO){ 00207 statVals.V24_IS_HI = FALSE; 00208 statVals.V24_IS_LO = TRUE; 00209 }else{ 00210 statVals.V24_IS_HI = FALSE; 00211 statVals.V24_IS_LO = FALSE; 00212 } 00213 00214 // Check 12V levels 00215 if(adcVals.v12 > V12_HI){ 00216 //if(!buck){ 00217 // stopConverter(); 00218 //} 00219 statVals.V12_IS_HI = TRUE; 00220 statVals.V12_IS_LO = FALSE; 00221 }else if(adcVals.v12 < V12_LO){ 00222 //if(!buck){ 00223 // stopConverter(); 00224 //} 00225 statVals.V12_IS_HI = FALSE; 00226 statVals.V12_IS_LO = TRUE; 00227 }else{ 00228 statVals.V12_IS_HI = FALSE; 00229 statVals.V12_IS_LO = FALSE; 00230 } 00231 return statVals; 00232 } 00233 00234 00235 /******************************************************************************* 00236 updateControls 00237 *******************************************************************************/ 00238 void updateControls(unsigned short ref){ 00239 00240 unsigned int tBuf = getLUT_thermCode(ref); 00241 if(max_boards <= 3){ 00242 getLUT_binCodeArray(ref); 00243 setBoardControls(tBuf); 00244 }else{ 00245 wr_out_code = setBoardEnables(tBuf); 00246 unsigned int bBuf = getLUT_binCode(ref); 00247 en_out_code = setBoardWeights(bBuf); 00248 //sprintf(strbuf, "en_out=%d wr_out=%d\r\n", en_out_code, wr_out_code); 00249 //sendSerial(strbuf); 00250 } 00251 } 00252 00253 void XupdateControls(unsigned short ref){ 00254 00255 sprintf(strbuf, "refr=%d\r\n", ref); 00256 sendSerial(strbuf); 00257 00258 ref = ref/64; 00259 00260 sprintf(strbuf, "refc=%d\r\n", ref); 00261 sendSerial(strbuf); 00262 00263 sendSerial("enter updateControls\r\n"); 00264 unsigned int cBuf = getLUT_thermCode(ref); 00265 sendSerial("cBuf1 updateControls\r\n"); 00266 wr_out_code = setBoardEnables(cBuf); 00267 sendSerial("wr_out_code updateControls\r\n"); 00268 00269 cBuf = getLUT_binCode(ref); 00270 sendSerial("cBuf2 updateControls\r\n"); 00271 en_out_code = setBoardWeights(cBuf); 00272 sendSerial("en_out_code updateControls\r\n"); 00273 00274 wait(0.5); 00275 }
Generated on Sat Aug 27 2022 12:36:03 by
1.7.2