Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Sat Dec 08 01:53:36 2018 +0000
Revision:
12:fd1fd1857628
Parent:
11:01dcfb29fbc4
Child:
15:aed8f326c949
Added buck/boost modes.

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 6:39442d493098 30 #include "Ticker.h"
mfwic 1:9f8583ba2431 31
mfwic 6:39442d493098 32 Ticker drt;
mfwic 7:860b3a8275cb 33 unsigned int oldTime=0;
mfwic 6:39442d493098 34
mfwic 6:39442d493098 35 /*******************************************************************************
mfwic 6:39442d493098 36 drtInt - Display Refresh Timer interrupt handler
mfwic 6:39442d493098 37 *******************************************************************************/
mfwic 6:39442d493098 38 // real time clock interrupt to flash the LED
mfwic 6:39442d493098 39 void drtInt(void)
mfwic 6:39442d493098 40 {
mfwic 6:39442d493098 41 updateReady = TRUE;
mfwic 6:39442d493098 42 }
mfwic 6:39442d493098 43
mfwic 6:39442d493098 44 /*******************************************************************************
mfwic 6:39442d493098 45 initDRT - Create Display Refresh Timer interrupt
mfwic 6:39442d493098 46 *******************************************************************************/
mfwic 6:39442d493098 47 // initialize display refresh timer (DRT)
mfwic 6:39442d493098 48 void initDRT(void)
mfwic 6:39442d493098 49 {
mfwic 6:39442d493098 50 drt.attach_us(&drtInt, UPDATE_REFRESH_DELAY_US);
mfwic 6:39442d493098 51 }
mfwic 6:39442d493098 52
mfwic 6:39442d493098 53 /*******************************************************************************
mfwic 6:39442d493098 54 refreshData - Refresh voltage and current readings to the terminal
mfwic 6:39442d493098 55 *******************************************************************************/
mfwic 11:01dcfb29fbc4 56 void refreshData(struct adcValues avals){
mfwic 8:d3d7dca419b3 57 //loopTime = masterTimer.read_ms() - oldTime;
mfwic 8:d3d7dca419b3 58 //oldTime = masterTimer.read_ms();
mfwic 8:d3d7dca419b3 59
mfwic 11:01dcfb29fbc4 60 struct displayValues dvals = calcDisplayValues(avals);
mfwic 7:860b3a8275cb 61
mfwic 11:01dcfb29fbc4 62 double pwr_out=dvals.v12f*dvals.i12f;
mfwic 12:fd1fd1857628 63 double pwr_in=dvals.v48f*(dvals.i48f);
mfwic 7:860b3a8275cb 64 double pwr_eff=100*pwr_out/pwr_in;
mfwic 7:860b3a8275cb 65
mfwic 11:01dcfb29fbc4 66 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 67 //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 68 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 69 sprintf(strbuf, "Power Out = %4.1f W, Power In = %4.1f W \r\n", pwr_out, pwr_in);
mfwic 7:860b3a8275cb 70 sendSerial(strbuf);
mfwic 7:860b3a8275cb 71 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 72 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 73 sprintf(strbuf, "Power Efficiency = %2.2f percent \r\n\r\n", pwr_eff);
mfwic 7:860b3a8275cb 74 sendSerial(strbuf);
mfwic 7:860b3a8275cb 75 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 6:39442d493098 76 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 77 sprintf(strbuf, "wr_out_code=%d, en_out_code=%d ", wr_out_code, en_out_code);
mfwic 6:39442d493098 78 sendSerial(strbuf);
mfwic 6:39442d493098 79 }
mfwic 6:39442d493098 80
mfwic 6:39442d493098 81 /*******************************************************************************
mfwic 6:39442d493098 82 updateTerminal - Save cursor, write data, restore cursor.
mfwic 6:39442d493098 83 *******************************************************************************/
mfwic 11:01dcfb29fbc4 84 void updateTerminal(struct adcValues avals){
mfwic 6:39442d493098 85 //get cursor pos, store in CUR_POS
mfwic 6:39442d493098 86 sprintf( strbuf, "%c7", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 87 sendSerial(strbuf);
mfwic 6:39442d493098 88 //move cursor to DATA_ROW
mfwic 8:d3d7dca419b3 89 sprintf( strbuf, "%c[3;0f", 27 ); // ESC=27, Move cursor position = [line;columnf
mfwic 6:39442d493098 90 sendSerial(strbuf);
mfwic 6:39442d493098 91 //write data
mfwic 11:01dcfb29fbc4 92 refreshData(avals);
mfwic 6:39442d493098 93 //move cursor to CUR_POS
mfwic 6:39442d493098 94 sprintf( strbuf, "%c8", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 95 sendSerial(strbuf);
mfwic 6:39442d493098 96 }
mfwic 6:39442d493098 97
mfwic 6:39442d493098 98 /*******************************************************************************
mfwic 6:39442d493098 99 clrScrn - clears terminal and moves cursor to upper-left corner
mfwic 6:39442d493098 100 *******************************************************************************/
mfwic 1:9f8583ba2431 101 // clears terminal
mfwic 1:9f8583ba2431 102 void clrScrn(void){
mfwic 1:9f8583ba2431 103 sprintf( strbuf, "%c[2J", 27 ); // ESC=27, Clear screen = [2J
mfwic 1:9f8583ba2431 104 sendSerial(strbuf);
mfwic 1:9f8583ba2431 105 sprintf( strbuf, "%c[f", 27 ); // ESC=27, Move cursor to upper-left corner = [f
mfwic 1:9f8583ba2431 106 sendSerial(strbuf);
mfwic 1:9f8583ba2431 107 }
mfwic 1:9f8583ba2431 108
mfwic 6:39442d493098 109 /*******************************************************************************
mfwic 6:39442d493098 110 menuRedraw - Write menu to terminal
mfwic 6:39442d493098 111 *******************************************************************************/
mfwic 1:9f8583ba2431 112 // clears terminal and re-draws main menu
mfwic 8:d3d7dca419b3 113 void menuRedraw(bool prompt){
mfwic 1:9f8583ba2431 114 clrScrn();
mfwic 7:860b3a8275cb 115
mfwic 7:860b3a8275cb 116 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 117 sendSerial(strbuf);
mfwic 7:860b3a8275cb 118
mfwic 9:816b9a4e4f21 119 sprintf(strbuf, " Agility Power Systems DCM1 0.5\r\n\r\n");
mfwic 7:860b3a8275cb 120 sendSerial(strbuf);
mfwic 7:860b3a8275cb 121
mfwic 7:860b3a8275cb 122 sprintf( strbuf, "%c[0m", 27 ); // ESC=27, Normal
mfwic 7:860b3a8275cb 123 sendSerial(strbuf);
mfwic 7:860b3a8275cb 124 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 1:9f8583ba2431 125 sendSerial(strbuf);
mfwic 6:39442d493098 126
mfwic 11:01dcfb29fbc4 127 struct adcValues avals = getADCresults();
mfwic 11:01dcfb29fbc4 128 refreshData(avals);
mfwic 6:39442d493098 129
mfwic 12:fd1fd1857628 130 sprintf(strbuf, "\r\n BRDS");
mfwic 1:9f8583ba2431 131 sendSerial(strbuf);
mfwic 12:fd1fd1857628 132 sprintf(strbuf, "\r\n MULT");
mfwic 1:9f8583ba2431 133 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 134 sprintf(strbuf, "\r\n ALLOFF");
mfwic 1:9f8583ba2431 135 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 136 sprintf(strbuf, "\r\n RUN [xx]");
mfwic 1:9f8583ba2431 137 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 138 sprintf(strbuf, "\r\n STOP");
mfwic 1:9f8583ba2431 139 sendSerial(strbuf);
mfwic 3:d8948c5b2951 140
mfwic 8:d3d7dca419b3 141 if(prompt){
mfwic 8:d3d7dca419b3 142 menuPrompt(MENU_DCM1);
mfwic 8:d3d7dca419b3 143 }
mfwic 3:d8948c5b2951 144 }
mfwic 3:d8948c5b2951 145
mfwic 6:39442d493098 146 /*******************************************************************************
mfwic 6:39442d493098 147 menuPrompt - Write menu prompt to terminal
mfwic 6:39442d493098 148 *******************************************************************************/
mfwic 3:d8948c5b2951 149 // sends carriage return and linefeed and prompt character
mfwic 3:d8948c5b2951 150 void menuPrompt(int menuType)
mfwic 3:d8948c5b2951 151 {
mfwic 3:d8948c5b2951 152 char strMenu[30] ={0};
mfwic 3:d8948c5b2951 153
mfwic 3:d8948c5b2951 154 switch(menuType)
mfwic 3:d8948c5b2951 155 {
mfwic 3:d8948c5b2951 156 case MENU_DCM1: strcpy(strMenu,"DCM1"); break;
mfwic 3:d8948c5b2951 157 case MENU_CALIBRATE: strcpy(strMenu,"CAL"); break;
mfwic 3:d8948c5b2951 158 case MENU_TEST: strcpy(strMenu,"TEST"); break;
mfwic 3:d8948c5b2951 159 case MENU_MAIN: strcpy(strMenu,"MAIN"); break;
mfwic 3:d8948c5b2951 160 default: strcpy(strMenu,"UNDF"); break;
mfwic 3:d8948c5b2951 161 }
mfwic 3:d8948c5b2951 162
mfwic 3:d8948c5b2951 163 // append the CR,LF and the ready character
mfwic 3:d8948c5b2951 164 if(serialStatus.computer)
mfwic 3:d8948c5b2951 165 {
mfwic 3:d8948c5b2951 166 sendSerial("\r");
mfwic 3:d8948c5b2951 167 }
mfwic 3:d8948c5b2951 168 else
mfwic 3:d8948c5b2951 169 {
mfwic 3:d8948c5b2951 170 // adds a carrot so you know you are talking in terminal
mfwic 3:d8948c5b2951 171 sprintf(strbuf,"\n\r%s>",strMenu);
mfwic 3:d8948c5b2951 172 sendSerial(strbuf);
mfwic 3:d8948c5b2951 173 // sendSerial("\n\r>");
mfwic 3:d8948c5b2951 174 }
mfwic 8:d3d7dca419b3 175 }
mfwic 8:d3d7dca419b3 176
mfwic 8:d3d7dca419b3 177 void splash_screen(void)
mfwic 8:d3d7dca419b3 178 {
mfwic 8:d3d7dca419b3 179 clrScrn();
mfwic 8:d3d7dca419b3 180 sprintf(strbuf," ___ _ ___ __ ____ _____ __ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 181 sprintf(strbuf," / | ____ _(_) (_) /___ __ / __ \\____ _ _____ _____ / ___/__ _______/ /____ ____ ___ _____\r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 182 sprintf(strbuf," / /| |/ __ `/ / / / __/ / / / / /_/ / __ \\ | /| / / _ \\/ ___/ \\__ \\/ / / / ___/ __/ _ \\/ __ `__ \\/ ___/\r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 183 sprintf(strbuf," / ___ / /_/ / / / / /_/ /_/ / / ____/ /_/ / |/ |/ / __/ / ___/ / /_/ (__ ) /_/ __/ / / / / (__ ) \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 184 sprintf(strbuf,"/_/ |_\\__, /_/_/_/\\__/\\__, / /_/ \\____/|__/|__/\\___/_/ /____/\\__, /____/\\__/\\___/_/ /_/ /_/____/ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 185 sprintf(strbuf," /____/ /____/ /____/ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 186 }
mfwic 8:d3d7dca419b3 187 /*
mfwic 8:d3d7dca419b3 188 sprintf(strbuf," ___ _ ___ __ ____ _____ __ \r\n");
mfwic 8:d3d7dca419b3 189 sprintf(strbuf," / | ____ _(_) (_) /___ __ / __ \____ _ _____ _____ / ___/__ _______/ /____ ____ ___ _____\r\n");
mfwic 8:d3d7dca419b3 190 sprintf(strbuf," / /| |/ __ `/ / / / __/ / / / / /_/ / __ \ | /| / / _ \/ ___/ \__ \/ / / / ___/ __/ _ \/ __ `__ \/ ___/\r\n");
mfwic 8:d3d7dca419b3 191 sprintf(strbuf," / ___ / /_/ / / / / /_/ /_/ / / ____/ /_/ / |/ |/ / __/ / ___/ / /_/ (__ ) /_/ __/ / / / / (__ ) \r\n");
mfwic 8:d3d7dca419b3 192 sprintf(strbuf,"/_/ |_\__, /_/_/_/\__/\__, / /_/ \____/|__/|__/\___/_/ /____/\__, /____/\__/\___/_/ /_/ /_/____/ \r\n");
mfwic 8:d3d7dca419b3 193 sprintf(strbuf," /____/ /____/ /____/ \r\n");
mfwic 8:d3d7dca419b3 194 */