Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Sat Mar 09 21:01:45 2019 +0000
Revision:
42:3ae73b61f657
Child:
43:291bbdba48f3
Removed V24, I24, I48.; Commented out en_out and wr_out.; Compiles

Who changed what in which revision?

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