Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Tue Dec 11 16:59:21 2018 +0000
Revision:
15:aed8f326c949
Parent:
12:fd1fd1857628
Child:
16:5791665200cb
Added voltage level checks.

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 1:9f8583ba2431 33
mfwic 6:39442d493098 34 Ticker drt;
mfwic 7:860b3a8275cb 35 unsigned int oldTime=0;
mfwic 6:39442d493098 36
mfwic 6:39442d493098 37 /*******************************************************************************
mfwic 6:39442d493098 38 drtInt - Display Refresh Timer interrupt handler
mfwic 6:39442d493098 39 *******************************************************************************/
mfwic 6:39442d493098 40 // real time clock interrupt to flash the LED
mfwic 6:39442d493098 41 void drtInt(void)
mfwic 6:39442d493098 42 {
mfwic 6:39442d493098 43 updateReady = TRUE;
mfwic 6:39442d493098 44 }
mfwic 6:39442d493098 45
mfwic 6:39442d493098 46 /*******************************************************************************
mfwic 6:39442d493098 47 initDRT - Create Display Refresh Timer interrupt
mfwic 6:39442d493098 48 *******************************************************************************/
mfwic 6:39442d493098 49 // initialize display refresh timer (DRT)
mfwic 6:39442d493098 50 void initDRT(void)
mfwic 6:39442d493098 51 {
mfwic 6:39442d493098 52 drt.attach_us(&drtInt, UPDATE_REFRESH_DELAY_US);
mfwic 6:39442d493098 53 }
mfwic 6:39442d493098 54
mfwic 6:39442d493098 55 /*******************************************************************************
mfwic 15:aed8f326c949 56 refreshStatus - Refresh status info to the terminal
mfwic 15:aed8f326c949 57 *******************************************************************************/
mfwic 15:aed8f326c949 58 void refreshStatus(struct statusValues statVals){
mfwic 15:aed8f326c949 59
mfwic 15:aed8f326c949 60 if(buck){
mfwic 15:aed8f326c949 61 sprintf(strbuf, "Buck Mode | ");
mfwic 15:aed8f326c949 62 }else{
mfwic 15:aed8f326c949 63 sprintf(strbuf, "Boost Mode | ");
mfwic 15:aed8f326c949 64 }
mfwic 15:aed8f326c949 65 sendSerial(strbuf);
mfwic 15:aed8f326c949 66
mfwic 15:aed8f326c949 67 if(statVals.V48_IS_HI){
mfwic 15:aed8f326c949 68 sprintf(strbuf, "V48 HIGH | ");
mfwic 15:aed8f326c949 69 sendSerial(strbuf);
mfwic 15:aed8f326c949 70 }else if(statVals.V48_IS_LO){
mfwic 15:aed8f326c949 71 sprintf(strbuf, "V48 LOW | ");
mfwic 15:aed8f326c949 72 sendSerial(strbuf);
mfwic 15:aed8f326c949 73 }else{
mfwic 15:aed8f326c949 74 sprintf(strbuf, "V48 OK | ");
mfwic 15:aed8f326c949 75 sendSerial(strbuf);
mfwic 15:aed8f326c949 76 }
mfwic 15:aed8f326c949 77
mfwic 15:aed8f326c949 78 if(statVals.V24_IS_HI){
mfwic 15:aed8f326c949 79 sprintf(strbuf, "V24 HIGH | ");
mfwic 15:aed8f326c949 80 sendSerial(strbuf);
mfwic 15:aed8f326c949 81 }else if(statVals.V24_IS_LO){
mfwic 15:aed8f326c949 82 sprintf(strbuf, "V24 LOW | ");
mfwic 15:aed8f326c949 83 sendSerial(strbuf);
mfwic 15:aed8f326c949 84 }else{
mfwic 15:aed8f326c949 85 sprintf(strbuf, "V24 OK | ");
mfwic 15:aed8f326c949 86 sendSerial(strbuf);
mfwic 15:aed8f326c949 87 }
mfwic 15:aed8f326c949 88
mfwic 15:aed8f326c949 89 if(statVals.V12_IS_HI){
mfwic 15:aed8f326c949 90 sprintf(strbuf, "V12 HIGH | ");
mfwic 15:aed8f326c949 91 sendSerial(strbuf);
mfwic 15:aed8f326c949 92 }else if(statVals.V24_IS_LO){
mfwic 15:aed8f326c949 93 sprintf(strbuf, "V12 LOW | ");
mfwic 15:aed8f326c949 94 sendSerial(strbuf);
mfwic 15:aed8f326c949 95 }else{
mfwic 15:aed8f326c949 96 sprintf(strbuf, "V12 OK | ");
mfwic 15:aed8f326c949 97 sendSerial(strbuf);
mfwic 15:aed8f326c949 98 }
mfwic 15:aed8f326c949 99
mfwic 15:aed8f326c949 100 if(running){
mfwic 15:aed8f326c949 101 sprintf(strbuf, "Running ");
mfwic 15:aed8f326c949 102 sendSerial(strbuf);
mfwic 15:aed8f326c949 103 }else{
mfwic 15:aed8f326c949 104 sprintf(strbuf, "NOT Running");
mfwic 15:aed8f326c949 105 sendSerial(strbuf);
mfwic 15:aed8f326c949 106 }
mfwic 15:aed8f326c949 107
mfwic 15:aed8f326c949 108 sprintf(strbuf, "\r\n");
mfwic 15:aed8f326c949 109 sendSerial(strbuf);
mfwic 15:aed8f326c949 110
mfwic 15:aed8f326c949 111 }
mfwic 15:aed8f326c949 112
mfwic 15:aed8f326c949 113 /*******************************************************************************
mfwic 6:39442d493098 114 refreshData - Refresh voltage and current readings to the terminal
mfwic 6:39442d493098 115 *******************************************************************************/
mfwic 15:aed8f326c949 116 void refreshData(struct adcValues adcVals){
mfwic 8:d3d7dca419b3 117 //loopTime = masterTimer.read_ms() - oldTime;
mfwic 8:d3d7dca419b3 118 //oldTime = masterTimer.read_ms();
mfwic 8:d3d7dca419b3 119
mfwic 15:aed8f326c949 120 struct displayValues dvals = calcDisplayValues(adcVals);
mfwic 7:860b3a8275cb 121
mfwic 11:01dcfb29fbc4 122 double pwr_out=dvals.v12f*dvals.i12f;
mfwic 12:fd1fd1857628 123 double pwr_in=dvals.v48f*(dvals.i48f);
mfwic 7:860b3a8275cb 124 double pwr_eff=100*pwr_out/pwr_in;
mfwic 7:860b3a8275cb 125
mfwic 11:01dcfb29fbc4 126 sprintf(strbuf, "V48=%2.1f, I48=%3.1f | V24=%2.1f, I24=%3.1f | V12=%2.1f, I12=%3.1f \r\n", dvals.v48f, dvals.i48f, dvals.v24f, dvals.i24f, dvals.v12f, dvals.i12f);
mfwic 8:d3d7dca419b3 127 //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 128 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 129 sprintf(strbuf, "Power Out = %4.1f W, Power In = %4.1f W \r\n", pwr_out, pwr_in);
mfwic 7:860b3a8275cb 130 sendSerial(strbuf);
mfwic 7:860b3a8275cb 131 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 132 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 133 sprintf(strbuf, "Power Efficiency = %2.2f percent \r\n\r\n", pwr_eff);
mfwic 7:860b3a8275cb 134 sendSerial(strbuf);
mfwic 7:860b3a8275cb 135 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 6:39442d493098 136 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 137 sprintf(strbuf, "wr_out_code=%d, en_out_code=%d ", wr_out_code, en_out_code);
mfwic 6:39442d493098 138 sendSerial(strbuf);
mfwic 6:39442d493098 139 }
mfwic 6:39442d493098 140
mfwic 6:39442d493098 141 /*******************************************************************************
mfwic 6:39442d493098 142 updateTerminal - Save cursor, write data, restore cursor.
mfwic 6:39442d493098 143 *******************************************************************************/
mfwic 15:aed8f326c949 144 void updateTerminal(struct adcValues adcVals, struct statusValues statVals){
mfwic 6:39442d493098 145 //get cursor pos, store in CUR_POS
mfwic 6:39442d493098 146 sprintf( strbuf, "%c7", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 147 sendSerial(strbuf);
mfwic 15:aed8f326c949 148
mfwic 15:aed8f326c949 149 //move cursor to STATUS_ROW and write status info
mfwic 15:aed8f326c949 150 char row = STATUS_ROW + '0';
mfwic 15:aed8f326c949 151 sprintf( strbuf, "%c[%c;0f", 27, row); // ESC=27, Move cursor position = [line;columnf
mfwic 6:39442d493098 152 sendSerial(strbuf);
mfwic 15:aed8f326c949 153 refreshStatus(statVals);
mfwic 15:aed8f326c949 154
mfwic 15:aed8f326c949 155 //move cursor to DATA_ROW and write data
mfwic 15:aed8f326c949 156 row = DATA_ROW + '0';
mfwic 15:aed8f326c949 157 sprintf( strbuf, "%c[%c;0f", 27, row); // ESC=27, Move cursor position = [line;columnf
mfwic 15:aed8f326c949 158 sendSerial(strbuf);
mfwic 15:aed8f326c949 159 refreshData(adcVals);
mfwic 15:aed8f326c949 160
mfwic 6:39442d493098 161 //move cursor to CUR_POS
mfwic 6:39442d493098 162 sprintf( strbuf, "%c8", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 163 sendSerial(strbuf);
mfwic 6:39442d493098 164 }
mfwic 6:39442d493098 165
mfwic 6:39442d493098 166 /*******************************************************************************
mfwic 6:39442d493098 167 clrScrn - clears terminal and moves cursor to upper-left corner
mfwic 6:39442d493098 168 *******************************************************************************/
mfwic 1:9f8583ba2431 169 // clears terminal
mfwic 1:9f8583ba2431 170 void clrScrn(void){
mfwic 1:9f8583ba2431 171 sprintf( strbuf, "%c[2J", 27 ); // ESC=27, Clear screen = [2J
mfwic 1:9f8583ba2431 172 sendSerial(strbuf);
mfwic 1:9f8583ba2431 173 sprintf( strbuf, "%c[f", 27 ); // ESC=27, Move cursor to upper-left corner = [f
mfwic 1:9f8583ba2431 174 sendSerial(strbuf);
mfwic 1:9f8583ba2431 175 }
mfwic 1:9f8583ba2431 176
mfwic 6:39442d493098 177 /*******************************************************************************
mfwic 6:39442d493098 178 menuRedraw - Write menu to terminal
mfwic 6:39442d493098 179 *******************************************************************************/
mfwic 1:9f8583ba2431 180 // clears terminal and re-draws main menu
mfwic 8:d3d7dca419b3 181 void menuRedraw(bool prompt){
mfwic 1:9f8583ba2431 182 clrScrn();
mfwic 7:860b3a8275cb 183
mfwic 7:860b3a8275cb 184 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 185 sendSerial(strbuf);
mfwic 7:860b3a8275cb 186
mfwic 15:aed8f326c949 187 sprintf(strbuf, " Agility Power Systems DCM1 0.6\r\n\r\n");
mfwic 7:860b3a8275cb 188 sendSerial(strbuf);
mfwic 7:860b3a8275cb 189
mfwic 7:860b3a8275cb 190 sprintf( strbuf, "%c[0m", 27 ); // ESC=27, Normal
mfwic 7:860b3a8275cb 191 sendSerial(strbuf);
mfwic 7:860b3a8275cb 192 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 1:9f8583ba2431 193 sendSerial(strbuf);
mfwic 6:39442d493098 194
mfwic 15:aed8f326c949 195 struct adcValues adcVals = getADCresults();
mfwic 15:aed8f326c949 196 struct statusValues statVals = checkLevels(adcVals);
mfwic 15:aed8f326c949 197 refreshStatus(statVals);
mfwic 15:aed8f326c949 198 refreshData(adcVals);
mfwic 6:39442d493098 199
mfwic 12:fd1fd1857628 200 sprintf(strbuf, "\r\n BRDS");
mfwic 1:9f8583ba2431 201 sendSerial(strbuf);
mfwic 12:fd1fd1857628 202 sprintf(strbuf, "\r\n MULT");
mfwic 1:9f8583ba2431 203 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 204 sprintf(strbuf, "\r\n ALLOFF");
mfwic 1:9f8583ba2431 205 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 206 sprintf(strbuf, "\r\n RUN [xx]");
mfwic 1:9f8583ba2431 207 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 208 sprintf(strbuf, "\r\n STOP");
mfwic 1:9f8583ba2431 209 sendSerial(strbuf);
mfwic 3:d8948c5b2951 210
mfwic 8:d3d7dca419b3 211 if(prompt){
mfwic 8:d3d7dca419b3 212 menuPrompt(MENU_DCM1);
mfwic 8:d3d7dca419b3 213 }
mfwic 3:d8948c5b2951 214 }
mfwic 3:d8948c5b2951 215
mfwic 6:39442d493098 216 /*******************************************************************************
mfwic 15:aed8f326c949 217 sendLevelsWarning
mfwic 15:aed8f326c949 218 *******************************************************************************/
mfwic 15:aed8f326c949 219 void sendLevelsWarning(void){
mfwic 15:aed8f326c949 220 sprintf(strbuf, "\r\nSome voltage levels are out of range. I would look into it if I were you.\r\n");
mfwic 15:aed8f326c949 221 sendSerial(strbuf);
mfwic 15:aed8f326c949 222 }
mfwic 15:aed8f326c949 223
mfwic 15:aed8f326c949 224 /*******************************************************************************
mfwic 6:39442d493098 225 menuPrompt - Write menu prompt to terminal
mfwic 6:39442d493098 226 *******************************************************************************/
mfwic 3:d8948c5b2951 227 // sends carriage return and linefeed and prompt character
mfwic 3:d8948c5b2951 228 void menuPrompt(int menuType)
mfwic 3:d8948c5b2951 229 {
mfwic 3:d8948c5b2951 230 char strMenu[30] ={0};
mfwic 3:d8948c5b2951 231
mfwic 3:d8948c5b2951 232 switch(menuType)
mfwic 3:d8948c5b2951 233 {
mfwic 3:d8948c5b2951 234 case MENU_DCM1: strcpy(strMenu,"DCM1"); break;
mfwic 3:d8948c5b2951 235 case MENU_CALIBRATE: strcpy(strMenu,"CAL"); break;
mfwic 3:d8948c5b2951 236 case MENU_TEST: strcpy(strMenu,"TEST"); break;
mfwic 3:d8948c5b2951 237 case MENU_MAIN: strcpy(strMenu,"MAIN"); break;
mfwic 3:d8948c5b2951 238 default: strcpy(strMenu,"UNDF"); break;
mfwic 3:d8948c5b2951 239 }
mfwic 3:d8948c5b2951 240
mfwic 3:d8948c5b2951 241 // append the CR,LF and the ready character
mfwic 3:d8948c5b2951 242 if(serialStatus.computer)
mfwic 3:d8948c5b2951 243 {
mfwic 3:d8948c5b2951 244 sendSerial("\r");
mfwic 3:d8948c5b2951 245 }
mfwic 3:d8948c5b2951 246 else
mfwic 3:d8948c5b2951 247 {
mfwic 3:d8948c5b2951 248 // adds a carrot so you know you are talking in terminal
mfwic 3:d8948c5b2951 249 sprintf(strbuf,"\n\r%s>",strMenu);
mfwic 3:d8948c5b2951 250 sendSerial(strbuf);
mfwic 3:d8948c5b2951 251 // sendSerial("\n\r>");
mfwic 3:d8948c5b2951 252 }
mfwic 8:d3d7dca419b3 253 }
mfwic 8:d3d7dca419b3 254
mfwic 8:d3d7dca419b3 255 void splash_screen(void)
mfwic 8:d3d7dca419b3 256 {
mfwic 8:d3d7dca419b3 257 clrScrn();
mfwic 8:d3d7dca419b3 258 sprintf(strbuf," ___ _ ___ __ ____ _____ __ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 259 sprintf(strbuf," / | ____ _(_) (_) /___ __ / __ \\____ _ _____ _____ / ___/__ _______/ /____ ____ ___ _____\r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 260 sprintf(strbuf," / /| |/ __ `/ / / / __/ / / / / /_/ / __ \\ | /| / / _ \\/ ___/ \\__ \\/ / / / ___/ __/ _ \\/ __ `__ \\/ ___/\r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 261 sprintf(strbuf," / ___ / /_/ / / / / /_/ /_/ / / ____/ /_/ / |/ |/ / __/ / ___/ / /_/ (__ ) /_/ __/ / / / / (__ ) \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 262 sprintf(strbuf,"/_/ |_\\__, /_/_/_/\\__/\\__, / /_/ \\____/|__/|__/\\___/_/ /____/\\__, /____/\\__/\\___/_/ /_/ /_/____/ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 263 sprintf(strbuf," /____/ /____/ /____/ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 264 }
mfwic 8:d3d7dca419b3 265 /*
mfwic 8:d3d7dca419b3 266 sprintf(strbuf," ___ _ ___ __ ____ _____ __ \r\n");
mfwic 8:d3d7dca419b3 267 sprintf(strbuf," / | ____ _(_) (_) /___ __ / __ \____ _ _____ _____ / ___/__ _______/ /____ ____ ___ _____\r\n");
mfwic 8:d3d7dca419b3 268 sprintf(strbuf," / /| |/ __ `/ / / / __/ / / / / /_/ / __ \ | /| / / _ \/ ___/ \__ \/ / / / ___/ __/ _ \/ __ `__ \/ ___/\r\n");
mfwic 8:d3d7dca419b3 269 sprintf(strbuf," / ___ / /_/ / / / / /_/ /_/ / / ____/ /_/ / |/ |/ / __/ / ___/ / /_/ (__ ) /_/ __/ / / / / (__ ) \r\n");
mfwic 8:d3d7dca419b3 270 sprintf(strbuf,"/_/ |_\__, /_/_/_/\__/\__, / /_/ \____/|__/|__/\___/_/ /____/\__, /____/\__/\___/_/ /_/ /_/____/ \r\n");
mfwic 8:d3d7dca419b3 271 sprintf(strbuf," /____/ /____/ /____/ \r\n");
mfwic 8:d3d7dca419b3 272 */