Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
Slord2142
Date:
Wed Mar 06 22:32:31 2019 +0000
Revision:
30:d8721a46ee03
Parent:
26:55e8e1a9cc84
Removed extraneous comments from all files

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 21:fe0ea1860c9f 41 en_out = 32;
mfwic 26:55e8e1a9cc84 42 setBoardEnables(16383);
mfwic 21:fe0ea1860c9f 43
mfwic 15:aed8f326c949 44 }
mfwic 15:aed8f326c949 45
mfwic 6:39442d493098 46 /*******************************************************************************
mfwic 6:39442d493098 47 delay
mfwic 6:39442d493098 48 *******************************************************************************/
mfwic 0:44a3005d4f20 49 void delay(long ticks)
mfwic 0:44a3005d4f20 50 {
mfwic 0:44a3005d4f20 51 long i;
mfwic 0:44a3005d4f20 52 for(i=0;i<ticks;i++);
mfwic 0:44a3005d4f20 53 }
mfwic 0:44a3005d4f20 54
mfwic 6:39442d493098 55 /*******************************************************************************
mfwic 25:8bcc8bea0e31 56 setBoardControls
mfwic 25:8bcc8bea0e31 57 *******************************************************************************/
mfwic 25:8bcc8bea0e31 58 void setBoardControls(unsigned int tCode)
mfwic 25:8bcc8bea0e31 59 {
mfwic 25:8bcc8bea0e31 60 for(unsigned int b=0; b<max_boards; b++){
mfwic 26:55e8e1a9cc84 61 //wr_out = 0;
mfwic 26:55e8e1a9cc84 62 en_out_code = bCodeRow[b];
mfwic 26:55e8e1a9cc84 63
mfwic 26:55e8e1a9cc84 64 wr_out_code = 1<<b;
mfwic 26:55e8e1a9cc84 65 wr_out = ~wr_out_code;
mfwic 26:55e8e1a9cc84 66 en_out = en_out_code;
mfwic 26:55e8e1a9cc84 67
mfwic 26:55e8e1a9cc84 68 wait_us(250);
mfwic 26:55e8e1a9cc84 69 }
mfwic 26:55e8e1a9cc84 70 for(unsigned int b=max_boards; b<13; 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 = 0;
mfwic 26:55e8e1a9cc84 75
mfwic 26:55e8e1a9cc84 76 wait_us(250);
mfwic 25:8bcc8bea0e31 77 }
mfwic 25:8bcc8bea0e31 78 }
mfwic 25:8bcc8bea0e31 79
mfwic 25:8bcc8bea0e31 80 /*******************************************************************************
mfwic 6:39442d493098 81 setBoardEnables
mfwic 6:39442d493098 82 *******************************************************************************/
mfwic 6:39442d493098 83 unsigned int setBoardEnables(unsigned int tCode)
mfwic 0:44a3005d4f20 84 {
mfwic 25:8bcc8bea0e31 85 wr_out = tCode;
mfwic 25:8bcc8bea0e31 86 unsigned int en_out_save = en_out;
mfwic 25:8bcc8bea0e31 87 en_out = 0;
mfwic 25:8bcc8bea0e31 88 wr_out = ~tCode;
mfwic 25:8bcc8bea0e31 89 en_out = en_out_save;
mfwic 25:8bcc8bea0e31 90 return tCode;
mfwic 0:44a3005d4f20 91 }
mfwic 0:44a3005d4f20 92
mfwic 6:39442d493098 93 /*******************************************************************************
mfwic 6:39442d493098 94 setBoardWeights
mfwic 6:39442d493098 95 *******************************************************************************/
mfwic 6:39442d493098 96 unsigned int setBoardWeights(unsigned int bCode)
mfwic 0:44a3005d4f20 97 {
mfwic 25:8bcc8bea0e31 98 en_out = bCode;
mfwic 0:44a3005d4f20 99 toggleLatchSignal();
mfwic 6:39442d493098 100 return bCode;
mfwic 0:44a3005d4f20 101 }
mfwic 0:44a3005d4f20 102
mfwic 6:39442d493098 103 /*******************************************************************************
mfwic 6:39442d493098 104 toggleLatchSignal
mfwic 6:39442d493098 105 *******************************************************************************/
mfwic 0:44a3005d4f20 106 void toggleLatchSignal(void){
mfwic 0:44a3005d4f20 107 extchlat = OFF;
mfwic 0:44a3005d4f20 108 extchlat = ON;
mfwic 0:44a3005d4f20 109 extchlat = OFF;
mfwic 0:44a3005d4f20 110 }
mfwic 1:9f8583ba2431 111
mfwic 1:9f8583ba2431 112 /************************************************************
mfwic 1:9f8583ba2431 113 * Routine: checkRange
mfwic 1:9f8583ba2431 114 * Input: setval
mfwic 1:9f8583ba2431 115 * limlo -- low limit
mfwic 1:9f8583ba2431 116 * limhi -- high limit
mfwic 1:9f8583ba2431 117 * Returns: 1 if entry validates and is written
mfwic 1:9f8583ba2431 118 * 0 if entry fails
mfwic 1:9f8583ba2431 119 * -1 if it slips past
mfwic 1:9f8583ba2431 120 * Description:
mfwic 1:9f8583ba2431 121 * Checks if setvalue is between the given limits.
mfwic 1:9f8583ba2431 122 *
mfwic 1:9f8583ba2431 123 **************************************************************/
mfwic 1:9f8583ba2431 124 int checkRange(int setvalue, int limlo, int limhi)
mfwic 1:9f8583ba2431 125 {
mfwic 6:39442d493098 126 if ((setvalue >= limlo) && (setvalue <= limhi)){
mfwic 1:9f8583ba2431 127 return 1;
mfwic 6:39442d493098 128 }else{
mfwic 1:9f8583ba2431 129 return 0;
mfwic 1:9f8583ba2431 130 }
mfwic 4:db38665c3727 131 }
mfwic 4:db38665c3727 132
mfwic 6:39442d493098 133 /*******************************************************************************
mfwic 6:39442d493098 134 startConverter
mfwic 6:39442d493098 135 *******************************************************************************/
mfwic 4:db38665c3727 136 void startConverter(unsigned int reg)
mfwic 4:db38665c3727 137 {
mfwic 15:aed8f326c949 138 if(!running){
mfwic 15:aed8f326c949 139 running = TRUE;
mfwic 15:aed8f326c949 140 // Fire in the hole!
mfwic 15:aed8f326c949 141 wr_out_code = setBoardEnables(reg);
mfwic 6:39442d493098 142
mfwic 15:aed8f326c949 143 sprintf(strbuf, "\r\nConverter started");
mfwic 15:aed8f326c949 144 sendSerial(strbuf);
mfwic 15:aed8f326c949 145 }
mfwic 4:db38665c3727 146 }
mfwic 4:db38665c3727 147
mfwic 6:39442d493098 148 /*******************************************************************************
mfwic 6:39442d493098 149 stopConverter - stop the converter and set outputs to 0
mfwic 6:39442d493098 150 *******************************************************************************/
mfwic 4:db38665c3727 151 void stopConverter(void)
mfwic 4:db38665c3727 152 {
mfwic 15:aed8f326c949 153 if(running){
mfwic 21:fe0ea1860c9f 154 en_out = 32;
mfwic 21:fe0ea1860c9f 155 wr_out_code = setBoardEnables(ALLON);
mfwic 15:aed8f326c949 156 running = FALSE;
mfwic 15:aed8f326c949 157 sprintf(strbuf, "\r\nConverter stopped");
mfwic 15:aed8f326c949 158 sendSerial(strbuf);
mfwic 15:aed8f326c949 159 }
mfwic 4:db38665c3727 160 }
mfwic 4:db38665c3727 161
mfwic 6:39442d493098 162 /*******************************************************************************
mfwic 15:aed8f326c949 163 checkLevels
mfwic 15:aed8f326c949 164 *******************************************************************************/
mfwic 15:aed8f326c949 165 struct statusValues checkLevels(struct adcValues adcVals){
mfwic 15:aed8f326c949 166
mfwic 15:aed8f326c949 167 struct statusValues statVals;
mfwic 15:aed8f326c949 168
mfwic 15:aed8f326c949 169 // Check 48V levels
mfwic 15:aed8f326c949 170 if(adcVals.v48 > V48_HI){
mfwic 15:aed8f326c949 171 statVals.V48_IS_HI = TRUE;
mfwic 15:aed8f326c949 172 statVals.V48_IS_LO = FALSE;
mfwic 15:aed8f326c949 173 }else if(adcVals.v48 < V48_LO){
mfwic 15:aed8f326c949 174 statVals.V48_IS_HI = FALSE;
mfwic 15:aed8f326c949 175 statVals.V48_IS_LO = TRUE;
mfwic 15:aed8f326c949 176 }else{
mfwic 15:aed8f326c949 177 statVals.V48_IS_HI = FALSE;
mfwic 15:aed8f326c949 178 statVals.V48_IS_LO = FALSE;
mfwic 15:aed8f326c949 179 }
mfwic 15:aed8f326c949 180
mfwic 15:aed8f326c949 181 // Check 24V levels
mfwic 15:aed8f326c949 182 if(adcVals.v24 > V24_HI){
mfwic 15:aed8f326c949 183 statVals.V24_IS_HI = TRUE;
mfwic 15:aed8f326c949 184 statVals.V24_IS_LO = FALSE;
mfwic 15:aed8f326c949 185 }else if(adcVals.v24 < V24_LO){
mfwic 15:aed8f326c949 186 statVals.V24_IS_HI = FALSE;
mfwic 15:aed8f326c949 187 statVals.V24_IS_LO = TRUE;
mfwic 15:aed8f326c949 188 }else{
mfwic 15:aed8f326c949 189 statVals.V24_IS_HI = FALSE;
mfwic 15:aed8f326c949 190 statVals.V24_IS_LO = FALSE;
mfwic 15:aed8f326c949 191 }
mfwic 15:aed8f326c949 192
mfwic 15:aed8f326c949 193 // Check 12V levels
mfwic 15:aed8f326c949 194 if(adcVals.v12 > V12_HI){
mfwic 15:aed8f326c949 195 statVals.V12_IS_HI = TRUE;
mfwic 15:aed8f326c949 196 statVals.V12_IS_LO = FALSE;
mfwic 15:aed8f326c949 197 }else if(adcVals.v12 < V12_LO){
mfwic 15:aed8f326c949 198 statVals.V12_IS_HI = FALSE;
mfwic 15:aed8f326c949 199 statVals.V12_IS_LO = TRUE;
mfwic 15:aed8f326c949 200 }else{
mfwic 15:aed8f326c949 201 statVals.V12_IS_HI = FALSE;
mfwic 15:aed8f326c949 202 statVals.V12_IS_LO = FALSE;
mfwic 15:aed8f326c949 203 }
mfwic 15:aed8f326c949 204 return statVals;
mfwic 15:aed8f326c949 205 }
mfwic 15:aed8f326c949 206
mfwic 15:aed8f326c949 207
mfwic 15:aed8f326c949 208 /*******************************************************************************
mfwic 6:39442d493098 209 updateControls
mfwic 6:39442d493098 210 *******************************************************************************/
mfwic 6:39442d493098 211 void updateControls(unsigned short ref){
mfwic 9:816b9a4e4f21 212
mfwic 25:8bcc8bea0e31 213 unsigned int tBuf = getLUT_thermCode(ref);
mfwic 25:8bcc8bea0e31 214 if(max_boards <= 3){
mfwic 25:8bcc8bea0e31 215 getLUT_binCodeArray(ref);
mfwic 25:8bcc8bea0e31 216 setBoardControls(tBuf);
mfwic 25:8bcc8bea0e31 217 }else{
mfwic 25:8bcc8bea0e31 218 wr_out_code = setBoardEnables(tBuf);
mfwic 26:55e8e1a9cc84 219 unsigned int bBuf = getLUT_binCode(ref);
mfwic 25:8bcc8bea0e31 220 en_out_code = setBoardWeights(bBuf);
mfwic 25:8bcc8bea0e31 221 }
mfwic 9:816b9a4e4f21 222 }
mfwic 9:816b9a4e4f21 223
mfwic 9:816b9a4e4f21 224 void XupdateControls(unsigned short ref){
mfwic 11:01dcfb29fbc4 225
mfwic 9:816b9a4e4f21 226 sprintf(strbuf, "refr=%d\r\n", ref);
mfwic 9:816b9a4e4f21 227 sendSerial(strbuf);
mfwic 9:816b9a4e4f21 228
mfwic 9:816b9a4e4f21 229 ref = ref/64;
mfwic 9:816b9a4e4f21 230
mfwic 9:816b9a4e4f21 231 sprintf(strbuf, "refc=%d\r\n", ref);
mfwic 9:816b9a4e4f21 232 sendSerial(strbuf);
mfwic 9:816b9a4e4f21 233
mfwic 9:816b9a4e4f21 234 sendSerial("enter updateControls\r\n");
mfwic 9:816b9a4e4f21 235 unsigned int cBuf = getLUT_thermCode(ref);
mfwic 9:816b9a4e4f21 236 sendSerial("cBuf1 updateControls\r\n");
mfwic 9:816b9a4e4f21 237 wr_out_code = setBoardEnables(cBuf);
mfwic 9:816b9a4e4f21 238 sendSerial("wr_out_code updateControls\r\n");
mfwic 9:816b9a4e4f21 239
mfwic 9:816b9a4e4f21 240 cBuf = getLUT_binCode(ref);
mfwic 9:816b9a4e4f21 241 sendSerial("cBuf2 updateControls\r\n");
mfwic 9:816b9a4e4f21 242 en_out_code = setBoardWeights(cBuf);
mfwic 9:816b9a4e4f21 243 sendSerial("en_out_code updateControls\r\n");
mfwic 9:816b9a4e4f21 244
mfwic 9:816b9a4e4f21 245 wait(0.5);
mfwic 1:9f8583ba2431 246 }