Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Thu Dec 13 21:58:28 2018 +0000
Revision:
17:454afe56eedb
Parent:
15:aed8f326c949
Child:
20:5de24e4ae1c5
Removed voltage limit check to stop converter. Now just show voltage levels in status.; LUT v1p1.

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