Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Tue Jan 22 19:56:22 2019 +0000
Revision:
26:55e8e1a9cc84
Parent:
25:8bcc8bea0e31
Child:
30:d8721a46ee03
Sent to customer for demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfwic 0:44a3005d4f20 1 //-------------------------------------------------------------------------------
mfwic 0:44a3005d4f20 2 //
mfwic 0:44a3005d4f20 3 // Treehouse Designs Inc.
mfwic 0:44a3005d4f20 4 // Colorado Springs, Colorado
mfwic 0:44a3005d4f20 5 //
mfwic 0:44a3005d4f20 6 // Copyright (c) 2016 by Treehouse Designs Inc.
mfwic 0:44a3005d4f20 7 // Copyright (c) 2018 by Agility Power Systems Inc.
mfwic 0:44a3005d4f20 8 //
mfwic 0:44a3005d4f20 9 // This code is the property of Treehouse Designs, Inc. (Treehouse) and
mfwic 0:44a3005d4f20 10 // Agility Power Systems Inc. (Agility) and may not be redistributed
mfwic 0:44a3005d4f20 11 // in any form without prior written permission from
mfwic 0:44a3005d4f20 12 // both copyright holders, Treehouse and Agility.
mfwic 0:44a3005d4f20 13 //
mfwic 0:44a3005d4f20 14 // The above copyright notice and this permission notice shall be included in
mfwic 0:44a3005d4f20 15 // all copies or substantial portions of the Software.
mfwic 0:44a3005d4f20 16 //
mfwic 0:44a3005d4f20 17 //
mfwic 0:44a3005d4f20 18 //-------------------------------------------------------------------------------
mfwic 0:44a3005d4f20 19 //
mfwic 0:44a3005d4f20 20 // REVISION HISTORY:
mfwic 0:44a3005d4f20 21 //
mfwic 0:44a3005d4f20 22 // $Author: $
mfwic 0:44a3005d4f20 23 // $Rev: $
mfwic 0:44a3005d4f20 24 // $Date: $
mfwic 0:44a3005d4f20 25 // $URL: $
mfwic 0:44a3005d4f20 26 //
mfwic 0:44a3005d4f20 27 //-------------------------------------------------------------------------------
mfwic 0:44a3005d4f20 28
mfwic 0:44a3005d4f20 29 #include "mbed.h"
mfwic 0:44a3005d4f20 30 #include "globals.h"
mfwic 11:01dcfb29fbc4 31 #include "parameters.h"
mfwic 0:44a3005d4f20 32 #include "boards.h"
mfwic 11:01dcfb29fbc4 33 #include "lut.h"
mfwic 0:44a3005d4f20 34 #include "all_io.h"
mfwic 0:44a3005d4f20 35 #include "serial.h"
mfwic 0:44a3005d4f20 36 #include "stdio.h"
mfwic 0:44a3005d4f20 37
mfwic 0:44a3005d4f20 38 unsigned int boardEnableBits;
mfwic 0:44a3005d4f20 39
mfwic 15:aed8f326c949 40 void initBoards(struct adcValues adcVals){
mfwic 22:2c37ac12746e 41 /*
mfwic 15:aed8f326c949 42 sprintf(strbuf, "\r\nV48_HI=%d\r\n", V48_HI);
mfwic 15:aed8f326c949 43 sendSerial(strbuf);
mfwic 15:aed8f326c949 44 sprintf(strbuf, "\r\nV48=%d\r\n", adcVals.v48);
mfwic 15:aed8f326c949 45 sendSerial(strbuf);
mfwic 15:aed8f326c949 46 sprintf(strbuf, "\r\nV48_LO=%d\r\n", V48_LO);
mfwic 15:aed8f326c949 47 sendSerial(strbuf);
mfwic 22:2c37ac12746e 48 */
mfwic 21:fe0ea1860c9f 49 en_out = 32;
mfwic 26:55e8e1a9cc84 50 setBoardEnables(16383);
mfwic 21:fe0ea1860c9f 51
mfwic 15:aed8f326c949 52 }
mfwic 15:aed8f326c949 53
mfwic 6:39442d493098 54 /*******************************************************************************
mfwic 6:39442d493098 55 delay
mfwic 6:39442d493098 56 *******************************************************************************/
mfwic 0:44a3005d4f20 57 void delay(long ticks)
mfwic 0:44a3005d4f20 58 {
mfwic 0:44a3005d4f20 59 long i;
mfwic 0:44a3005d4f20 60 for(i=0;i<ticks;i++);
mfwic 0:44a3005d4f20 61 }
mfwic 0:44a3005d4f20 62
mfwic 6:39442d493098 63 /*******************************************************************************
mfwic 25:8bcc8bea0e31 64 setBoardControls
mfwic 25:8bcc8bea0e31 65 *******************************************************************************/
mfwic 25:8bcc8bea0e31 66 void setBoardControls(unsigned int tCode)
mfwic 25:8bcc8bea0e31 67 {
mfwic 25:8bcc8bea0e31 68 for(unsigned int b=0; b<max_boards; b++){
mfwic 26:55e8e1a9cc84 69 //wr_out = 0;
mfwic 26:55e8e1a9cc84 70 en_out_code = bCodeRow[b];
mfwic 26:55e8e1a9cc84 71
mfwic 26:55e8e1a9cc84 72 wr_out_code = 1<<b;
mfwic 26:55e8e1a9cc84 73 wr_out = ~wr_out_code;
mfwic 26:55e8e1a9cc84 74 en_out = en_out_code;
mfwic 26:55e8e1a9cc84 75
mfwic 26:55e8e1a9cc84 76 wait_us(250);
mfwic 26:55e8e1a9cc84 77
mfwic 26:55e8e1a9cc84 78 //sprintf(strbuf, "en_out=%d wr_out=%d\r\n", en_out_code, wr_out_code);
mfwic 26:55e8e1a9cc84 79 //sendSerial(strbuf);
mfwic 26:55e8e1a9cc84 80 }
mfwic 26:55e8e1a9cc84 81 for(unsigned int b=max_boards; b<13; b++){
mfwic 26:55e8e1a9cc84 82
mfwic 26:55e8e1a9cc84 83 wr_out_code = 1<<b;
mfwic 26:55e8e1a9cc84 84 wr_out = ~wr_out_code;
mfwic 26:55e8e1a9cc84 85 en_out = 0;
mfwic 26:55e8e1a9cc84 86
mfwic 26:55e8e1a9cc84 87 wait_us(250);
mfwic 26:55e8e1a9cc84 88
mfwic 26:55e8e1a9cc84 89 //sprintf(strbuf, "en_out=%d wr_out=%d\r\n", en_out_code, wr_out_code);
mfwic 26:55e8e1a9cc84 90 //sendSerial(strbuf);
mfwic 25:8bcc8bea0e31 91 }
mfwic 25:8bcc8bea0e31 92 }
mfwic 25:8bcc8bea0e31 93
mfwic 25:8bcc8bea0e31 94 /*******************************************************************************
mfwic 6:39442d493098 95 setBoardEnables
mfwic 6:39442d493098 96 *******************************************************************************/
mfwic 6:39442d493098 97 unsigned int setBoardEnables(unsigned int tCode)
mfwic 0:44a3005d4f20 98 {
mfwic 25:8bcc8bea0e31 99 wr_out = tCode;
mfwic 25:8bcc8bea0e31 100 unsigned int en_out_save = en_out;
mfwic 25:8bcc8bea0e31 101 en_out = 0;
mfwic 25:8bcc8bea0e31 102 wr_out = ~tCode;
mfwic 25:8bcc8bea0e31 103 en_out = en_out_save;
mfwic 25:8bcc8bea0e31 104 return tCode;
mfwic 0:44a3005d4f20 105 }
mfwic 0:44a3005d4f20 106
mfwic 6:39442d493098 107 /*******************************************************************************
mfwic 6:39442d493098 108 setBoardWeights
mfwic 6:39442d493098 109 *******************************************************************************/
mfwic 6:39442d493098 110 unsigned int setBoardWeights(unsigned int bCode)
mfwic 0:44a3005d4f20 111 {
mfwic 25:8bcc8bea0e31 112 en_out = bCode;
mfwic 0:44a3005d4f20 113 toggleLatchSignal();
mfwic 6:39442d493098 114 return bCode;
mfwic 0:44a3005d4f20 115 }
mfwic 0:44a3005d4f20 116
mfwic 6:39442d493098 117 /*******************************************************************************
mfwic 6:39442d493098 118 toggleLatchSignal
mfwic 6:39442d493098 119 *******************************************************************************/
mfwic 0:44a3005d4f20 120 void toggleLatchSignal(void){
mfwic 0:44a3005d4f20 121 extchlat = OFF;
mfwic 0:44a3005d4f20 122 extchlat = ON;
mfwic 0:44a3005d4f20 123 extchlat = OFF;
mfwic 0:44a3005d4f20 124 }
mfwic 1:9f8583ba2431 125
mfwic 1:9f8583ba2431 126 /************************************************************
mfwic 1:9f8583ba2431 127 * Routine: checkRange
mfwic 1:9f8583ba2431 128 * Input: setval
mfwic 1:9f8583ba2431 129 * limlo -- low limit
mfwic 1:9f8583ba2431 130 * limhi -- high limit
mfwic 1:9f8583ba2431 131 * Returns: 1 if entry validates and is written
mfwic 1:9f8583ba2431 132 * 0 if entry fails
mfwic 1:9f8583ba2431 133 * -1 if it slips past
mfwic 1:9f8583ba2431 134 * Description:
mfwic 1:9f8583ba2431 135 * Checks if setvalue is between the given limits.
mfwic 1:9f8583ba2431 136 *
mfwic 1:9f8583ba2431 137 **************************************************************/
mfwic 1:9f8583ba2431 138 int checkRange(int setvalue, int limlo, int limhi)
mfwic 1:9f8583ba2431 139 {
mfwic 6:39442d493098 140 if ((setvalue >= limlo) && (setvalue <= limhi)){
mfwic 1:9f8583ba2431 141 return 1;
mfwic 6:39442d493098 142 }else{
mfwic 12:fd1fd1857628 143 //showRangeError(0, 0, setvalue);
mfwic 1:9f8583ba2431 144 return 0;
mfwic 1:9f8583ba2431 145 }
mfwic 4:db38665c3727 146 }
mfwic 4:db38665c3727 147
mfwic 6:39442d493098 148 /*******************************************************************************
mfwic 6:39442d493098 149 startConverter
mfwic 6:39442d493098 150 *******************************************************************************/
mfwic 4:db38665c3727 151 void startConverter(unsigned int reg)
mfwic 4:db38665c3727 152 {
mfwic 15:aed8f326c949 153 if(!running){
mfwic 15:aed8f326c949 154 running = TRUE;
mfwic 15:aed8f326c949 155 // Fire in the hole!
mfwic 15:aed8f326c949 156 wr_out_code = setBoardEnables(reg);
mfwic 6:39442d493098 157
mfwic 15:aed8f326c949 158 sprintf(strbuf, "\r\nConverter started");
mfwic 15:aed8f326c949 159 sendSerial(strbuf);
mfwic 15:aed8f326c949 160 }
mfwic 4:db38665c3727 161 }
mfwic 4:db38665c3727 162
mfwic 6:39442d493098 163 /*******************************************************************************
mfwic 6:39442d493098 164 stopConverter - stop the converter and set outputs to 0
mfwic 6:39442d493098 165 *******************************************************************************/
mfwic 4:db38665c3727 166 void stopConverter(void)
mfwic 4:db38665c3727 167 {
mfwic 15:aed8f326c949 168 if(running){
mfwic 21:fe0ea1860c9f 169 en_out = 32;
mfwic 21:fe0ea1860c9f 170 wr_out_code = setBoardEnables(ALLON);
mfwic 15:aed8f326c949 171 running = FALSE;
mfwic 15:aed8f326c949 172 sprintf(strbuf, "\r\nConverter stopped");
mfwic 15:aed8f326c949 173 sendSerial(strbuf);
mfwic 15:aed8f326c949 174 }
mfwic 4:db38665c3727 175 }
mfwic 4:db38665c3727 176
mfwic 6:39442d493098 177 /*******************************************************************************
mfwic 15:aed8f326c949 178 checkLevels
mfwic 15:aed8f326c949 179 *******************************************************************************/
mfwic 15:aed8f326c949 180 struct statusValues checkLevels(struct adcValues adcVals){
mfwic 15:aed8f326c949 181
mfwic 15:aed8f326c949 182 struct statusValues statVals;
mfwic 15:aed8f326c949 183
mfwic 15:aed8f326c949 184 // Check 48V levels
mfwic 15:aed8f326c949 185 if(adcVals.v48 > V48_HI){
mfwic 17:454afe56eedb 186 //if(buck){
mfwic 17:454afe56eedb 187 // stopConverter();
mfwic 17:454afe56eedb 188 //}
mfwic 15:aed8f326c949 189 statVals.V48_IS_HI = TRUE;
mfwic 15:aed8f326c949 190 statVals.V48_IS_LO = FALSE;
mfwic 15:aed8f326c949 191 }else if(adcVals.v48 < V48_LO){
mfwic 17:454afe56eedb 192 //if(buck){
mfwic 17:454afe56eedb 193 // stopConverter();
mfwic 17:454afe56eedb 194 //}
mfwic 15:aed8f326c949 195 statVals.V48_IS_HI = FALSE;
mfwic 15:aed8f326c949 196 statVals.V48_IS_LO = TRUE;
mfwic 15:aed8f326c949 197 }else{
mfwic 15:aed8f326c949 198 statVals.V48_IS_HI = FALSE;
mfwic 15:aed8f326c949 199 statVals.V48_IS_LO = FALSE;
mfwic 15:aed8f326c949 200 }
mfwic 15:aed8f326c949 201
mfwic 15:aed8f326c949 202 // Check 24V levels
mfwic 15:aed8f326c949 203 if(adcVals.v24 > V24_HI){
mfwic 15:aed8f326c949 204 statVals.V24_IS_HI = TRUE;
mfwic 15:aed8f326c949 205 statVals.V24_IS_LO = FALSE;
mfwic 15:aed8f326c949 206 }else if(adcVals.v24 < V24_LO){
mfwic 15:aed8f326c949 207 statVals.V24_IS_HI = FALSE;
mfwic 15:aed8f326c949 208 statVals.V24_IS_LO = TRUE;
mfwic 15:aed8f326c949 209 }else{
mfwic 15:aed8f326c949 210 statVals.V24_IS_HI = FALSE;
mfwic 15:aed8f326c949 211 statVals.V24_IS_LO = FALSE;
mfwic 15:aed8f326c949 212 }
mfwic 15:aed8f326c949 213
mfwic 15:aed8f326c949 214 // Check 12V levels
mfwic 15:aed8f326c949 215 if(adcVals.v12 > V12_HI){
mfwic 17:454afe56eedb 216 //if(!buck){
mfwic 17:454afe56eedb 217 // stopConverter();
mfwic 17:454afe56eedb 218 //}
mfwic 15:aed8f326c949 219 statVals.V12_IS_HI = TRUE;
mfwic 15:aed8f326c949 220 statVals.V12_IS_LO = FALSE;
mfwic 15:aed8f326c949 221 }else if(adcVals.v12 < V12_LO){
mfwic 17:454afe56eedb 222 //if(!buck){
mfwic 17:454afe56eedb 223 // stopConverter();
mfwic 17:454afe56eedb 224 //}
mfwic 15:aed8f326c949 225 statVals.V12_IS_HI = FALSE;
mfwic 15:aed8f326c949 226 statVals.V12_IS_LO = TRUE;
mfwic 15:aed8f326c949 227 }else{
mfwic 15:aed8f326c949 228 statVals.V12_IS_HI = FALSE;
mfwic 15:aed8f326c949 229 statVals.V12_IS_LO = FALSE;
mfwic 15:aed8f326c949 230 }
mfwic 15:aed8f326c949 231 return statVals;
mfwic 15:aed8f326c949 232 }
mfwic 15:aed8f326c949 233
mfwic 15:aed8f326c949 234
mfwic 15:aed8f326c949 235 /*******************************************************************************
mfwic 6:39442d493098 236 updateControls
mfwic 6:39442d493098 237 *******************************************************************************/
mfwic 6:39442d493098 238 void updateControls(unsigned short ref){
mfwic 9:816b9a4e4f21 239
mfwic 25:8bcc8bea0e31 240 unsigned int tBuf = getLUT_thermCode(ref);
mfwic 25:8bcc8bea0e31 241 if(max_boards <= 3){
mfwic 25:8bcc8bea0e31 242 getLUT_binCodeArray(ref);
mfwic 25:8bcc8bea0e31 243 setBoardControls(tBuf);
mfwic 25:8bcc8bea0e31 244 }else{
mfwic 25:8bcc8bea0e31 245 wr_out_code = setBoardEnables(tBuf);
mfwic 26:55e8e1a9cc84 246 unsigned int bBuf = getLUT_binCode(ref);
mfwic 25:8bcc8bea0e31 247 en_out_code = setBoardWeights(bBuf);
mfwic 26:55e8e1a9cc84 248 //sprintf(strbuf, "en_out=%d wr_out=%d\r\n", en_out_code, wr_out_code);
mfwic 26:55e8e1a9cc84 249 //sendSerial(strbuf);
mfwic 25:8bcc8bea0e31 250 }
mfwic 9:816b9a4e4f21 251 }
mfwic 9:816b9a4e4f21 252
mfwic 9:816b9a4e4f21 253 void XupdateControls(unsigned short ref){
mfwic 11:01dcfb29fbc4 254
mfwic 9:816b9a4e4f21 255 sprintf(strbuf, "refr=%d\r\n", ref);
mfwic 9:816b9a4e4f21 256 sendSerial(strbuf);
mfwic 9:816b9a4e4f21 257
mfwic 9:816b9a4e4f21 258 ref = ref/64;
mfwic 9:816b9a4e4f21 259
mfwic 9:816b9a4e4f21 260 sprintf(strbuf, "refc=%d\r\n", ref);
mfwic 9:816b9a4e4f21 261 sendSerial(strbuf);
mfwic 9:816b9a4e4f21 262
mfwic 9:816b9a4e4f21 263 sendSerial("enter updateControls\r\n");
mfwic 9:816b9a4e4f21 264 unsigned int cBuf = getLUT_thermCode(ref);
mfwic 9:816b9a4e4f21 265 sendSerial("cBuf1 updateControls\r\n");
mfwic 9:816b9a4e4f21 266 wr_out_code = setBoardEnables(cBuf);
mfwic 9:816b9a4e4f21 267 sendSerial("wr_out_code updateControls\r\n");
mfwic 9:816b9a4e4f21 268
mfwic 9:816b9a4e4f21 269 cBuf = getLUT_binCode(ref);
mfwic 9:816b9a4e4f21 270 sendSerial("cBuf2 updateControls\r\n");
mfwic 9:816b9a4e4f21 271 en_out_code = setBoardWeights(cBuf);
mfwic 9:816b9a4e4f21 272 sendSerial("en_out_code updateControls\r\n");
mfwic 9:816b9a4e4f21 273
mfwic 9:816b9a4e4f21 274 wait(0.5);
mfwic 1:9f8583ba2431 275 }