Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Wed Dec 05 00:20:34 2018 +0000
Revision:
7:860b3a8275cb
Parent:
6:39442d493098
Child:
8:d3d7dca419b3
Added power efficiency calcs.; Changed color of text sent to terminal.; Fixed loop timer.

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 6:39442d493098 29 #include "Ticker.h"
mfwic 1:9f8583ba2431 30
mfwic 6:39442d493098 31 Ticker drt;
mfwic 7:860b3a8275cb 32 unsigned int oldTime=0;
mfwic 6:39442d493098 33
mfwic 6:39442d493098 34 /*******************************************************************************
mfwic 6:39442d493098 35 drtInt - Display Refresh Timer interrupt handler
mfwic 6:39442d493098 36 *******************************************************************************/
mfwic 6:39442d493098 37 // real time clock interrupt to flash the LED
mfwic 6:39442d493098 38 void drtInt(void)
mfwic 6:39442d493098 39 {
mfwic 6:39442d493098 40 updateReady = TRUE;
mfwic 6:39442d493098 41 }
mfwic 6:39442d493098 42
mfwic 6:39442d493098 43 /*******************************************************************************
mfwic 6:39442d493098 44 initDRT - Create Display Refresh Timer interrupt
mfwic 6:39442d493098 45 *******************************************************************************/
mfwic 6:39442d493098 46 // initialize display refresh timer (DRT)
mfwic 6:39442d493098 47 void initDRT(void)
mfwic 6:39442d493098 48 {
mfwic 6:39442d493098 49 drt.attach_us(&drtInt, UPDATE_REFRESH_DELAY_US);
mfwic 6:39442d493098 50 }
mfwic 6:39442d493098 51
mfwic 6:39442d493098 52 /*******************************************************************************
mfwic 6:39442d493098 53 refreshData - Refresh voltage and current readings to the terminal
mfwic 6:39442d493098 54 *******************************************************************************/
mfwic 6:39442d493098 55 void refreshData(void){
mfwic 7:860b3a8275cb 56 loopTime = masterTimer.read_ms() - oldTime;
mfwic 7:860b3a8275cb 57 oldTime = masterTimer.read_ms();
mfwic 7:860b3a8275cb 58
mfwic 7:860b3a8275cb 59 double v48f = 48*(v48/2048);
mfwic 7:860b3a8275cb 60 double v24f = 24*(v48/2048);
mfwic 7:860b3a8275cb 61 double v12f = 12*(v48/2048);
mfwic 7:860b3a8275cb 62 double i48f = i48/40;
mfwic 7:860b3a8275cb 63 double i24f = i24/40;
mfwic 7:860b3a8275cb 64 double i12f = i12/40;
mfwic 7:860b3a8275cb 65 double pwr_out=v12f*i12f;
mfwic 7:860b3a8275cb 66 double pwr_in=v48f*(i48f-0.25);
mfwic 7:860b3a8275cb 67 double pwr_eff=100*pwr_out/pwr_in;
mfwic 7:860b3a8275cb 68
mfwic 7:860b3a8275cb 69 sprintf(strbuf, "V48=%2.2f, I48=%2.2f | V24=%2.2f, I24=%2.2f | V12=%2.2f, I12=%2.2f || loop=%d \r\n", v48f, i48f, v24f, i24f, v12f, i12f, loopTime);
mfwic 7:860b3a8275cb 70 sendSerial(strbuf);
mfwic 7:860b3a8275cb 71 sprintf(strbuf, "Power Out = %4.1f W, Power In = %4.1f W, ", pwr_out, pwr_in);
mfwic 7:860b3a8275cb 72 sendSerial(strbuf);
mfwic 7:860b3a8275cb 73 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 74 sendSerial(strbuf);
mfwic 7:860b3a8275cb 75 sprintf(strbuf, "Power Efficiency = %2.2f percent\r\n", pwr_eff);
mfwic 7:860b3a8275cb 76 sendSerial(strbuf);
mfwic 7:860b3a8275cb 77 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 6:39442d493098 78 sendSerial(strbuf);
mfwic 6:39442d493098 79 //sprintf(strbuf, "thermCode=%d, binCode=%d", thermCode[17], binCode[6]);
mfwic 6:39442d493098 80 sprintf(strbuf, "wr_out_code=%d, en_out_code=%d", wr_out_code, en_out_code);
mfwic 6:39442d493098 81 sendSerial(strbuf);
mfwic 6:39442d493098 82 }
mfwic 6:39442d493098 83
mfwic 6:39442d493098 84 /*******************************************************************************
mfwic 6:39442d493098 85 updateTerminal - Save cursor, write data, restore cursor.
mfwic 6:39442d493098 86 *******************************************************************************/
mfwic 6:39442d493098 87 void updateTerminal(void){
mfwic 6:39442d493098 88 //get cursor pos, store in CUR_POS
mfwic 6:39442d493098 89 sprintf( strbuf, "%c7", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 90 sendSerial(strbuf);
mfwic 6:39442d493098 91 //move cursor to DATA_ROW
mfwic 6:39442d493098 92 sprintf( strbuf, "%c[2;0f", 27 ); // ESC=27, Move cursor position = [line;columnf
mfwic 6:39442d493098 93 sendSerial(strbuf);
mfwic 6:39442d493098 94 //write data
mfwic 6:39442d493098 95 refreshData();
mfwic 6:39442d493098 96 //move cursor to CUR_POS
mfwic 6:39442d493098 97 sprintf( strbuf, "%c8", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 98 sendSerial(strbuf);
mfwic 6:39442d493098 99 }
mfwic 6:39442d493098 100
mfwic 6:39442d493098 101 /*******************************************************************************
mfwic 6:39442d493098 102 clrScrn - clears terminal and moves cursor to upper-left corner
mfwic 6:39442d493098 103 *******************************************************************************/
mfwic 1:9f8583ba2431 104 // clears terminal
mfwic 1:9f8583ba2431 105 void clrScrn(void){
mfwic 1:9f8583ba2431 106 sprintf( strbuf, "%c[2J", 27 ); // ESC=27, Clear screen = [2J
mfwic 1:9f8583ba2431 107 sendSerial(strbuf);
mfwic 1:9f8583ba2431 108 sprintf( strbuf, "%c[f", 27 ); // ESC=27, Move cursor to upper-left corner = [f
mfwic 1:9f8583ba2431 109 sendSerial(strbuf);
mfwic 1:9f8583ba2431 110 }
mfwic 1:9f8583ba2431 111
mfwic 6:39442d493098 112 /*******************************************************************************
mfwic 6:39442d493098 113 menuRedraw - Write menu to terminal
mfwic 6:39442d493098 114 *******************************************************************************/
mfwic 1:9f8583ba2431 115 // clears terminal and re-draws main menu
mfwic 1:9f8583ba2431 116 void menuRedraw(void){
mfwic 1:9f8583ba2431 117 clrScrn();
mfwic 7:860b3a8275cb 118
mfwic 7:860b3a8275cb 119 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 120 sendSerial(strbuf);
mfwic 7:860b3a8275cb 121
mfwic 7:860b3a8275cb 122 sprintf(strbuf, "Agility Power Systems DCM1 Menu 0.35\r\n");
mfwic 7:860b3a8275cb 123 sendSerial(strbuf);
mfwic 7:860b3a8275cb 124
mfwic 7:860b3a8275cb 125 sprintf( strbuf, "%c[0m", 27 ); // ESC=27, Normal
mfwic 7:860b3a8275cb 126 sendSerial(strbuf);
mfwic 7:860b3a8275cb 127 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 1:9f8583ba2431 128 sendSerial(strbuf);
mfwic 6:39442d493098 129
mfwic 6:39442d493098 130 refreshData();
mfwic 6:39442d493098 131
mfwic 1:9f8583ba2431 132 sprintf(strbuf, "\r\nMULT");
mfwic 1:9f8583ba2431 133 sendSerial(strbuf);
mfwic 1:9f8583ba2431 134 sprintf(strbuf, "\r\nBRDS");
mfwic 1:9f8583ba2431 135 sendSerial(strbuf);
mfwic 1:9f8583ba2431 136 sprintf(strbuf, "\r\nALLOFF");
mfwic 1:9f8583ba2431 137 sendSerial(strbuf);
mfwic 1:9f8583ba2431 138 sprintf(strbuf, "\r\nRUN [xx]");
mfwic 1:9f8583ba2431 139 sendSerial(strbuf);
mfwic 1:9f8583ba2431 140 sprintf(strbuf, "\r\nSTOP");
mfwic 1:9f8583ba2431 141 sendSerial(strbuf);
mfwic 3:d8948c5b2951 142
mfwic 3:d8948c5b2951 143 menuPrompt(MENU_DCM1);
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_DIFFERENTIAL: strcpy(strMenu,"DIFF"); break;
mfwic 3:d8948c5b2951 158 //case MENU_SINGLE: strcpy(strMenu,"SINGLE"); break;
mfwic 3:d8948c5b2951 159 //case MENU_DUAL: strcpy(strMenu,"DUAL"); break;
mfwic 3:d8948c5b2951 160 //case MENU_INVERT: strcpy(strMenu,"INVERT"); break;
mfwic 3:d8948c5b2951 161 //case MENU_SETTINGS: strcpy(strMenu,"SET"); break;
mfwic 3:d8948c5b2951 162 //case MENU_SETTINGS_CHAN1: strcpy(strMenu,"SET CHAN1"); break;
mfwic 3:d8948c5b2951 163 //case MENU_SETTINGS_CHAN2: strcpy(strMenu,"SET CHAN2"); break;
mfwic 3:d8948c5b2951 164 //case MENU_SETTINGS_CLOCK: strcpy(strMenu,"SET CLOCK"); break;
mfwic 3:d8948c5b2951 165 case MENU_CALIBRATE: strcpy(strMenu,"CAL"); break;
mfwic 3:d8948c5b2951 166 case MENU_TEST: strcpy(strMenu,"TEST"); break;
mfwic 3:d8948c5b2951 167 case MENU_MAIN: strcpy(strMenu,"MAIN"); break;
mfwic 3:d8948c5b2951 168 default: strcpy(strMenu,"UNDF"); break;
mfwic 3:d8948c5b2951 169 }
mfwic 3:d8948c5b2951 170
mfwic 3:d8948c5b2951 171 // append the CR,LF and the ready character
mfwic 3:d8948c5b2951 172 if(serialStatus.computer)
mfwic 3:d8948c5b2951 173 {
mfwic 3:d8948c5b2951 174 sendSerial("\r");
mfwic 3:d8948c5b2951 175 }
mfwic 3:d8948c5b2951 176 else
mfwic 3:d8948c5b2951 177 {
mfwic 3:d8948c5b2951 178 // adds a carrot so you know you are talking in terminal
mfwic 3:d8948c5b2951 179 sprintf(strbuf,"\n\r%s>",strMenu);
mfwic 3:d8948c5b2951 180 sendSerial(strbuf);
mfwic 3:d8948c5b2951 181 // sendSerial("\n\r>");
mfwic 3:d8948c5b2951 182 }
mfwic 1:9f8583ba2431 183 }