Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Tue Jan 08 22:05:53 2019 +0000
Revision:
20:5de24e4ae1c5
Parent:
18:78e982f31c6b
Child:
22:2c37ac12746e
Corrected BusOut order

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfwic 1:9f8583ba2431 1 //-------------------------------------------------------------------------------
mfwic 1:9f8583ba2431 2 //
mfwic 1:9f8583ba2431 3 // Treehouse Inc.
mfwic 1:9f8583ba2431 4 // Colorado Springs, Colorado
mfwic 1:9f8583ba2431 5 //
mfwic 1:9f8583ba2431 6 // Copyright (c) 2016 by Treehouse Designs Inc.
mfwic 1:9f8583ba2431 7 //
mfwic 1:9f8583ba2431 8 // This code is the property of Treehouse, Inc. (Treehouse) and may not be redistributed
mfwic 1:9f8583ba2431 9 // in any form without prior written permission from the copyright holder, Treehouse.
mfwic 1:9f8583ba2431 10 //
mfwic 1:9f8583ba2431 11 // The above copyright notice and this permission notice shall be included in
mfwic 1:9f8583ba2431 12 // all copies or substantial portions of the Software.
mfwic 1:9f8583ba2431 13 //
mfwic 1:9f8583ba2431 14 //-------------------------------------------------------------------------------
mfwic 1:9f8583ba2431 15 //
mfwic 1:9f8583ba2431 16 // REVISION HISTORY:
mfwic 1:9f8583ba2431 17 //
mfwic 1:9f8583ba2431 18 // $Author: $
mfwic 1:9f8583ba2431 19 // $Rev: $
mfwic 1:9f8583ba2431 20 // $Date: $
mfwic 1:9f8583ba2431 21 // $URL: $
mfwic 1:9f8583ba2431 22 //
mfwic 1:9f8583ba2431 23 //-------------------------------------------------------------------------------
mfwic 1:9f8583ba2431 24
mfwic 1:9f8583ba2431 25 #include "mbed.h"
mfwic 6:39442d493098 26 #include "globals.h"
mfwic 1:9f8583ba2431 27 #include "serial.h"
mfwic 1:9f8583ba2431 28 #include "menu.h"
mfwic 11:01dcfb29fbc4 29 #include "adc.h"
mfwic 15:aed8f326c949 30 #include "boards.h"
mfwic 6:39442d493098 31 #include "Ticker.h"
mfwic 15:aed8f326c949 32 #include "stdlib.h"
mfwic 18:78e982f31c6b 33 #include "lut.h"
mfwic 1:9f8583ba2431 34
mfwic 6:39442d493098 35 Ticker drt;
mfwic 7:860b3a8275cb 36 unsigned int oldTime=0;
mfwic 6:39442d493098 37
mfwic 6:39442d493098 38 /*******************************************************************************
mfwic 6:39442d493098 39 drtInt - Display Refresh Timer interrupt handler
mfwic 6:39442d493098 40 *******************************************************************************/
mfwic 6:39442d493098 41 // real time clock interrupt to flash the LED
mfwic 6:39442d493098 42 void drtInt(void)
mfwic 6:39442d493098 43 {
mfwic 6:39442d493098 44 updateReady = TRUE;
mfwic 6:39442d493098 45 }
mfwic 6:39442d493098 46
mfwic 6:39442d493098 47 /*******************************************************************************
mfwic 6:39442d493098 48 initDRT - Create Display Refresh Timer interrupt
mfwic 6:39442d493098 49 *******************************************************************************/
mfwic 6:39442d493098 50 // initialize display refresh timer (DRT)
mfwic 6:39442d493098 51 void initDRT(void)
mfwic 6:39442d493098 52 {
mfwic 6:39442d493098 53 drt.attach_us(&drtInt, UPDATE_REFRESH_DELAY_US);
mfwic 6:39442d493098 54 }
mfwic 6:39442d493098 55
mfwic 6:39442d493098 56 /*******************************************************************************
mfwic 15:aed8f326c949 57 refreshStatus - Refresh status info to the terminal
mfwic 15:aed8f326c949 58 *******************************************************************************/
mfwic 15:aed8f326c949 59 void refreshStatus(struct statusValues statVals){
mfwic 15:aed8f326c949 60
mfwic 16:5791665200cb 61 char strbuf_mode[15] = {0};
mfwic 16:5791665200cb 62 char strbuf_running[16] = {0};
mfwic 16:5791665200cb 63 char strbuf_v48[15] = {0};
mfwic 16:5791665200cb 64 char strbuf_v24[15] = {0};
mfwic 16:5791665200cb 65 char strbuf_v12[15] = {0};
mfwic 16:5791665200cb 66 char strbuf_blank[50] = {0};
mfwic 16:5791665200cb 67
mfwic 15:aed8f326c949 68 if(buck){
mfwic 16:5791665200cb 69 sprintf(strbuf_mode, "Buck Mode | ");
mfwic 15:aed8f326c949 70 }else{
mfwic 16:5791665200cb 71 sprintf(strbuf_mode, "Boost Mode | ");
mfwic 15:aed8f326c949 72 }
mfwic 16:5791665200cb 73 //sendSerial(strbuf);
mfwic 16:5791665200cb 74
mfwic 16:5791665200cb 75 if(running){
mfwic 16:5791665200cb 76 sprintf(strbuf_running, "Running | ");
mfwic 16:5791665200cb 77 }else{
mfwic 16:5791665200cb 78 sprintf(strbuf_running, "NOT Running | ");
mfwic 16:5791665200cb 79 }
mfwic 16:5791665200cb 80 //sendSerial(strbuf);
mfwic 15:aed8f326c949 81
mfwic 15:aed8f326c949 82 if(statVals.V48_IS_HI){
mfwic 16:5791665200cb 83 sprintf(strbuf_v48, "V48 HIGH | ");
mfwic 15:aed8f326c949 84 }else if(statVals.V48_IS_LO){
mfwic 16:5791665200cb 85 sprintf(strbuf_v48, "V48 LOW | ");
mfwic 15:aed8f326c949 86 }else{
mfwic 16:5791665200cb 87 // sprintf(strbuf, "V48 OK | ");
mfwic 16:5791665200cb 88 sprintf(strbuf_v48, "");
mfwic 16:5791665200cb 89 sprintf(strbuf_blank, " ");
mfwic 15:aed8f326c949 90 }
mfwic 16:5791665200cb 91 //sendSerial(strbuf);
mfwic 15:aed8f326c949 92
mfwic 15:aed8f326c949 93 if(statVals.V24_IS_HI){
mfwic 16:5791665200cb 94 sprintf(strbuf_v24, "V24 HIGH | ");
mfwic 15:aed8f326c949 95 }else if(statVals.V24_IS_LO){
mfwic 16:5791665200cb 96 sprintf(strbuf_v24, "V24 LOW | ");
mfwic 15:aed8f326c949 97 }else{
mfwic 16:5791665200cb 98 // sprintf(strbuf, "V24 OK | ");
mfwic 16:5791665200cb 99 sprintf(strbuf_v24, "");
mfwic 16:5791665200cb 100 sprintf(strbuf_blank, strcat(strbuf_blank, " "));
mfwic 15:aed8f326c949 101 }
mfwic 16:5791665200cb 102 //sendSerial(strbuf);
mfwic 15:aed8f326c949 103
mfwic 15:aed8f326c949 104 if(statVals.V12_IS_HI){
mfwic 16:5791665200cb 105 sprintf(strbuf_v12, "V12 HIGH ");
mfwic 15:aed8f326c949 106 }else if(statVals.V24_IS_LO){
mfwic 16:5791665200cb 107 sprintf(strbuf_v12, "V12 LOW ");
mfwic 15:aed8f326c949 108 }else{
mfwic 16:5791665200cb 109 // sprintf(strbuf, "V12 OK | ");
mfwic 16:5791665200cb 110 sprintf(strbuf_v12, "");
mfwic 16:5791665200cb 111 sprintf(strbuf_blank, strcat(strbuf_blank, " "));
mfwic 15:aed8f326c949 112 }
mfwic 16:5791665200cb 113 //sendSerial(strbuf);
mfwic 15:aed8f326c949 114
mfwic 16:5791665200cb 115 //move cursor to STATUS_ROW and write status info
mfwic 16:5791665200cb 116 //char row = STATUS_ROW + '0';
mfwic 16:5791665200cb 117 sprintf( strbuf, "%c[9;0f", 27); // ESC=27, Move cursor position = [line;columnf
mfwic 16:5791665200cb 118 sendSerial(strbuf);
mfwic 15:aed8f326c949 119
mfwic 16:5791665200cb 120 sprintf(strbuf, "Status: %s%s%s%s%s%s\r\n\r\n", strbuf_mode, strbuf_running, strbuf_v48, strbuf_v24, strbuf_v12, strbuf_blank);
mfwic 15:aed8f326c949 121 sendSerial(strbuf);
mfwic 15:aed8f326c949 122
mfwic 15:aed8f326c949 123 }
mfwic 15:aed8f326c949 124
mfwic 15:aed8f326c949 125 /*******************************************************************************
mfwic 6:39442d493098 126 refreshData - Refresh voltage and current readings to the terminal
mfwic 6:39442d493098 127 *******************************************************************************/
mfwic 15:aed8f326c949 128 void refreshData(struct adcValues adcVals){
mfwic 8:d3d7dca419b3 129 //loopTime = masterTimer.read_ms() - oldTime;
mfwic 8:d3d7dca419b3 130 //oldTime = masterTimer.read_ms();
mfwic 8:d3d7dca419b3 131
mfwic 15:aed8f326c949 132 struct displayValues dvals = calcDisplayValues(adcVals);
mfwic 7:860b3a8275cb 133
mfwic 11:01dcfb29fbc4 134 double pwr_out=dvals.v12f*dvals.i12f;
mfwic 12:fd1fd1857628 135 double pwr_in=dvals.v48f*(dvals.i48f);
mfwic 7:860b3a8275cb 136 double pwr_eff=100*pwr_out/pwr_in;
mfwic 7:860b3a8275cb 137
mfwic 16:5791665200cb 138 //move cursor to DATA_ROW and write data
mfwic 16:5791665200cb 139 //row = DATA_ROW + '0';
mfwic 16:5791665200cb 140 sprintf( strbuf, "%c[10;0f", 27); // ESC=27, Move cursor position = [line;columnf
mfwic 16:5791665200cb 141 sendSerial(strbuf);
mfwic 16:5791665200cb 142
mfwic 18:78e982f31c6b 143 sprintf(strbuf, "V48=%2.1f, I48=%3.1f | V24=%2.1f, I24=%3.1f | V12=%2.1f, I12=%3.2f \r\n", dvals.v48f, dvals.i48f, dvals.v24f, dvals.i24f, dvals.v12f, dvals.i12f);
mfwic 8:d3d7dca419b3 144 //sprintf(strbuf, "V48=%2.1f, I48=%2.2f | V24=%2.1f, I24=%2.2f | V12=%2.1f, I12=%2.2f || loop=%d \r\n", v48f, i48f, v24f, i24f, v12f, i12f, loopTime);
mfwic 7:860b3a8275cb 145 sendSerial(strbuf);
mfwic 18:78e982f31c6b 146 //sprintf(strbuf, "adcVals.i12 = %d \r\n", adcVals.i12);
mfwic 18:78e982f31c6b 147 //sendSerial(strbuf);
mfwic 8:d3d7dca419b3 148 sprintf(strbuf, "Power Out = %4.1f W, Power In = %4.1f W \r\n", pwr_out, pwr_in);
mfwic 7:860b3a8275cb 149 sendSerial(strbuf);
mfwic 7:860b3a8275cb 150 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 151 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 152 sprintf(strbuf, "Power Efficiency = %2.2f percent \r\n\r\n", pwr_eff);
mfwic 7:860b3a8275cb 153 sendSerial(strbuf);
mfwic 7:860b3a8275cb 154 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 6:39442d493098 155 sendSerial(strbuf);
mfwic 18:78e982f31c6b 156 sprintf(strbuf, "BRDS_code=%d, MULT_code=%d \r\n", wr_out_code, en_out_code);
mfwic 6:39442d493098 157 sendSerial(strbuf);
mfwic 6:39442d493098 158 }
mfwic 6:39442d493098 159
mfwic 6:39442d493098 160 /*******************************************************************************
mfwic 6:39442d493098 161 updateTerminal - Save cursor, write data, restore cursor.
mfwic 6:39442d493098 162 *******************************************************************************/
mfwic 15:aed8f326c949 163 void updateTerminal(struct adcValues adcVals, struct statusValues statVals){
mfwic 6:39442d493098 164 //get cursor pos, store in CUR_POS
mfwic 6:39442d493098 165 sprintf( strbuf, "%c7", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 166 sendSerial(strbuf);
mfwic 15:aed8f326c949 167
mfwic 15:aed8f326c949 168 refreshStatus(statVals);
mfwic 15:aed8f326c949 169 refreshData(adcVals);
mfwic 15:aed8f326c949 170
mfwic 6:39442d493098 171 //move cursor to CUR_POS
mfwic 6:39442d493098 172 sprintf( strbuf, "%c8", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 173 sendSerial(strbuf);
mfwic 6:39442d493098 174 }
mfwic 6:39442d493098 175
mfwic 6:39442d493098 176 /*******************************************************************************
mfwic 6:39442d493098 177 clrScrn - clears terminal and moves cursor to upper-left corner
mfwic 6:39442d493098 178 *******************************************************************************/
mfwic 1:9f8583ba2431 179 // clears terminal
mfwic 1:9f8583ba2431 180 void clrScrn(void){
mfwic 1:9f8583ba2431 181 sprintf( strbuf, "%c[2J", 27 ); // ESC=27, Clear screen = [2J
mfwic 1:9f8583ba2431 182 sendSerial(strbuf);
mfwic 1:9f8583ba2431 183 sprintf( strbuf, "%c[f", 27 ); // ESC=27, Move cursor to upper-left corner = [f
mfwic 1:9f8583ba2431 184 sendSerial(strbuf);
mfwic 1:9f8583ba2431 185 }
mfwic 1:9f8583ba2431 186
mfwic 6:39442d493098 187 /*******************************************************************************
mfwic 6:39442d493098 188 menuRedraw - Write menu to terminal
mfwic 6:39442d493098 189 *******************************************************************************/
mfwic 1:9f8583ba2431 190 // clears terminal and re-draws main menu
mfwic 8:d3d7dca419b3 191 void menuRedraw(bool prompt){
mfwic 1:9f8583ba2431 192 clrScrn();
mfwic 16:5791665200cb 193 menu_banner();
mfwic 7:860b3a8275cb 194
mfwic 7:860b3a8275cb 195 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 196 sendSerial(strbuf);
mfwic 7:860b3a8275cb 197
mfwic 20:5de24e4ae1c5 198 sprintf(strbuf, " Agility Power Systems DCM1 v0.9 LUT v%1.1f\r\n\r\n", LUT_VER);
mfwic 7:860b3a8275cb 199 sendSerial(strbuf);
mfwic 7:860b3a8275cb 200
mfwic 7:860b3a8275cb 201 sprintf( strbuf, "%c[0m", 27 ); // ESC=27, Normal
mfwic 7:860b3a8275cb 202 sendSerial(strbuf);
mfwic 18:78e982f31c6b 203 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, Black Text
mfwic 1:9f8583ba2431 204 sendSerial(strbuf);
mfwic 6:39442d493098 205
mfwic 15:aed8f326c949 206 struct adcValues adcVals = getADCresults();
mfwic 15:aed8f326c949 207 struct statusValues statVals = checkLevels(adcVals);
mfwic 15:aed8f326c949 208 refreshStatus(statVals);
mfwic 15:aed8f326c949 209 refreshData(adcVals);
mfwic 6:39442d493098 210
mfwic 16:5791665200cb 211 sprintf(strbuf, "\r\nCommands: (Not Case-Sensitive)");
mfwic 16:5791665200cb 212 sendSerial(strbuf);
mfwic 18:78e982f31c6b 213 sprintf(strbuf, "\r\n MENU");
mfwic 18:78e982f31c6b 214 sendSerial(strbuf);
mfwic 12:fd1fd1857628 215 sprintf(strbuf, "\r\n BRDS");
mfwic 1:9f8583ba2431 216 sendSerial(strbuf);
mfwic 12:fd1fd1857628 217 sprintf(strbuf, "\r\n MULT");
mfwic 1:9f8583ba2431 218 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 219 sprintf(strbuf, "\r\n ALLOFF");
mfwic 1:9f8583ba2431 220 sendSerial(strbuf);
mfwic 16:5791665200cb 221 sprintf(strbuf, "\r\n RUN");
mfwic 16:5791665200cb 222 sendSerial(strbuf);
mfwic 16:5791665200cb 223 sprintf(strbuf, "\r\n STOP\r\n");
mfwic 16:5791665200cb 224 sendSerial(strbuf);
mfwic 16:5791665200cb 225 sprintf(strbuf, "\r\n Type \'=number\' after BRDS or MULT to enter value.");
mfwic 1:9f8583ba2431 226 sendSerial(strbuf);
mfwic 18:78e982f31c6b 227 sprintf(strbuf, "\r\n e.g. BRDS=4095 will enable all boards.\r\n");
mfwic 16:5791665200cb 228 sendSerial(strbuf);
mfwic 16:5791665200cb 229 sprintf(strbuf, "\r\n Type \'?\' at end of BRDS or MULT to get status.");
mfwic 16:5791665200cb 230 sendSerial(strbuf);
mfwic 16:5791665200cb 231 sprintf(strbuf, "\r\n e.g. BRDS? will print value of BRDS.\r\n");
mfwic 1:9f8583ba2431 232 sendSerial(strbuf);
mfwic 3:d8948c5b2951 233
mfwic 8:d3d7dca419b3 234 if(prompt){
mfwic 8:d3d7dca419b3 235 menuPrompt(MENU_DCM1);
mfwic 8:d3d7dca419b3 236 }
mfwic 3:d8948c5b2951 237 }
mfwic 3:d8948c5b2951 238
mfwic 6:39442d493098 239 /*******************************************************************************
mfwic 15:aed8f326c949 240 sendLevelsWarning
mfwic 15:aed8f326c949 241 *******************************************************************************/
mfwic 15:aed8f326c949 242 void sendLevelsWarning(void){
mfwic 15:aed8f326c949 243 sprintf(strbuf, "\r\nSome voltage levels are out of range. I would look into it if I were you.\r\n");
mfwic 15:aed8f326c949 244 sendSerial(strbuf);
mfwic 15:aed8f326c949 245 }
mfwic 15:aed8f326c949 246
mfwic 15:aed8f326c949 247 /*******************************************************************************
mfwic 6:39442d493098 248 menuPrompt - Write menu prompt to terminal
mfwic 6:39442d493098 249 *******************************************************************************/
mfwic 3:d8948c5b2951 250 // sends carriage return and linefeed and prompt character
mfwic 3:d8948c5b2951 251 void menuPrompt(int menuType)
mfwic 3:d8948c5b2951 252 {
mfwic 3:d8948c5b2951 253 char strMenu[30] ={0};
mfwic 3:d8948c5b2951 254
mfwic 3:d8948c5b2951 255 switch(menuType)
mfwic 3:d8948c5b2951 256 {
mfwic 3:d8948c5b2951 257 case MENU_DCM1: strcpy(strMenu,"DCM1"); break;
mfwic 3:d8948c5b2951 258 case MENU_CALIBRATE: strcpy(strMenu,"CAL"); break;
mfwic 3:d8948c5b2951 259 case MENU_TEST: strcpy(strMenu,"TEST"); break;
mfwic 3:d8948c5b2951 260 case MENU_MAIN: strcpy(strMenu,"MAIN"); break;
mfwic 3:d8948c5b2951 261 default: strcpy(strMenu,"UNDF"); break;
mfwic 3:d8948c5b2951 262 }
mfwic 3:d8948c5b2951 263
mfwic 3:d8948c5b2951 264 // append the CR,LF and the ready character
mfwic 3:d8948c5b2951 265 if(serialStatus.computer)
mfwic 3:d8948c5b2951 266 {
mfwic 3:d8948c5b2951 267 sendSerial("\r");
mfwic 3:d8948c5b2951 268 }
mfwic 3:d8948c5b2951 269 else
mfwic 3:d8948c5b2951 270 {
mfwic 3:d8948c5b2951 271 // adds a carrot so you know you are talking in terminal
mfwic 3:d8948c5b2951 272 sprintf(strbuf,"\n\r%s>",strMenu);
mfwic 3:d8948c5b2951 273 sendSerial(strbuf);
mfwic 3:d8948c5b2951 274 // sendSerial("\n\r>");
mfwic 3:d8948c5b2951 275 }
mfwic 8:d3d7dca419b3 276 }
mfwic 8:d3d7dca419b3 277
mfwic 16:5791665200cb 278 void menu_banner(void)
mfwic 8:d3d7dca419b3 279 {
mfwic 8:d3d7dca419b3 280 clrScrn();
mfwic 18:78e982f31c6b 281 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, Black Text
mfwic 18:78e982f31c6b 282 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 283 sprintf(strbuf," ___ _ ___ __ ____ _____ __ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 284 sprintf(strbuf," / | ____ _(_) (_) /___ __ / __ \\____ _ _____ _____ / ___/__ _______/ /____ ____ ___ _____\r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 285 sprintf(strbuf," / /| |/ __ `/ / / / __/ / / / / /_/ / __ \\ | /| / / _ \\/ ___/ \\__ \\/ / / / ___/ __/ _ \\/ __ `__ \\/ ___/\r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 286 sprintf(strbuf," / ___ / /_/ / / / / /_/ /_/ / / ____/ /_/ / |/ |/ / __/ / ___/ / /_/ (__ ) /_/ __/ / / / / (__ ) \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 287 sprintf(strbuf,"/_/ |_\\__, /_/_/_/\\__/\\__, / /_/ \\____/|__/|__/\\___/_/ /____/\\__, /____/\\__/\\___/_/ /_/ /_/____/ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 288 sprintf(strbuf," /____/ /____/ /____/ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 289 }
mfwic 8:d3d7dca419b3 290 /*
mfwic 8:d3d7dca419b3 291 sprintf(strbuf," ___ _ ___ __ ____ _____ __ \r\n");
mfwic 8:d3d7dca419b3 292 sprintf(strbuf," / | ____ _(_) (_) /___ __ / __ \____ _ _____ _____ / ___/__ _______/ /____ ____ ___ _____\r\n");
mfwic 8:d3d7dca419b3 293 sprintf(strbuf," / /| |/ __ `/ / / / __/ / / / / /_/ / __ \ | /| / / _ \/ ___/ \__ \/ / / / ___/ __/ _ \/ __ `__ \/ ___/\r\n");
mfwic 8:d3d7dca419b3 294 sprintf(strbuf," / ___ / /_/ / / / / /_/ /_/ / / ____/ /_/ / |/ |/ / __/ / ___/ / /_/ (__ ) /_/ __/ / / / / (__ ) \r\n");
mfwic 8:d3d7dca419b3 295 sprintf(strbuf,"/_/ |_\__, /_/_/_/\__/\__, / /_/ \____/|__/|__/\___/_/ /____/\__, /____/\__/\___/_/ /_/ /_/____/ \r\n");
mfwic 8:d3d7dca419b3 296 sprintf(strbuf," /____/ /____/ /____/ \r\n");
mfwic 8:d3d7dca419b3 297 */