Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
Slord2142
Date:
Wed Mar 06 23:37:45 2019 +0000
Revision:
32:05a15c208bfb
Parent:
31:be17caf56d22
Child:
33:6c7364ea360f
Child:
41:bd54c88e3334
Fixed bracket

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 22:2c37ac12746e 30 #include "math.h"
mfwic 0:44a3005d4f20 31 #include "globals.h"
mfwic 0:44a3005d4f20 32 #include "parameters.h"
mfwic 0:44a3005d4f20 33 #include "all_io.h"
mfwic 0:44a3005d4f20 34 #include "stdio.h"
mfwic 0:44a3005d4f20 35 #include "stdlib.h"
mfwic 0:44a3005d4f20 36 #include "serial.h"
mfwic 0:44a3005d4f20 37 #include "adc.h"
mfwic 14:e55ae9bb2a81 38 #include "adc_defs.h"
mfwic 2:46faae84b8b0 39 #include "menu.h"
mfwic 1:9f8583ba2431 40 #include "boards.h"
mfwic 8:d3d7dca419b3 41 #include "command.h"
mfwic 1:9f8583ba2431 42
mfwic 6:39442d493098 43 unsigned int en_out_code;
mfwic 6:39442d493098 44 unsigned int wr_out_code;
mfwic 25:8bcc8bea0e31 45 unsigned int max_boards = 13;
mfwic 25:8bcc8bea0e31 46 unsigned int max_rows = 2048;
mfwic 25:8bcc8bea0e31 47 unsigned int bCodeRow[13];
mfwic 25:8bcc8bea0e31 48
mfwic 6:39442d493098 49 unsigned short my12=0;
mfwic 6:39442d493098 50 volatile bool updateReady = FALSE;
mfwic 6:39442d493098 51 unsigned int loopTime = 0;
mfwic 8:d3d7dca419b3 52 bool raw = FALSE;
mfwic 11:01dcfb29fbc4 53 bool running = FALSE;
mfwic 12:fd1fd1857628 54 bool testing = FALSE;
mfwic 15:aed8f326c949 55 bool buck = TRUE;
mfwic 6:39442d493098 56
mfwic 17:454afe56eedb 57 double CURRENT_48_OFFSET = 33940;
mfwic 17:454afe56eedb 58 double CURRENT_24_OFFSET = 33580;
mfwic 22:2c37ac12746e 59 double CURRENT_12_OFFSET = 33256;
mfwic 22:2c37ac12746e 60
mfwic 22:2c37ac12746e 61 unsigned short row = 0;
mfwic 22:2c37ac12746e 62 int row_test = 0;
mfwic 22:2c37ac12746e 63 int row_print = 0;
mfwic 17:454afe56eedb 64
mfwic 6:39442d493098 65 Timer masterTimer;
mfwic 0:44a3005d4f20 66
mfwic 0:44a3005d4f20 67 int main()
mfwic 0:44a3005d4f20 68 {
mfwic 7:860b3a8275cb 69 myled = 0;
mfwic 0:44a3005d4f20 70 extchlat = OFF;
mfwic 21:fe0ea1860c9f 71 wr_out_code = setBoardEnables(ALLON);
mfwic 21:fe0ea1860c9f 72 en_out_code = setBoardWeights(32);
mfwic 7:860b3a8275cb 73 running = FALSE;
mfwic 11:01dcfb29fbc4 74
mfwic 7:860b3a8275cb 75 initSerial();
mfwic 3:d8948c5b2951 76
mfwic 7:860b3a8275cb 77 initDRT(); // Display Refresh Timer
mfwic 7:860b3a8275cb 78
mfwic 0:44a3005d4f20 79 initADC();
mfwic 11:01dcfb29fbc4 80
mfwic 15:aed8f326c949 81 struct adcValues adcVals = getADCresults();
mfwic 22:2c37ac12746e 82 struct displayValues dispVals = calcDisplayValues(adcVals);
mfwic 15:aed8f326c949 83 struct statusValues statVals = checkLevels(adcVals);
mfwic 7:860b3a8275cb 84
mfwic 22:2c37ac12746e 85 row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR);
mfwic 22:2c37ac12746e 86 unsigned int old_row = row;
mfwic 22:2c37ac12746e 87
mfwic 16:5791665200cb 88 menu_banner();
mfwic 8:d3d7dca419b3 89 sprintf(strbuf, "\r\nPress Enter to continue");
mfwic 8:d3d7dca419b3 90 sendSerial(strbuf);
mfwic 11:01dcfb29fbc4 91 while(waitCommand()){ // Wait for user to press Enter
mfwic 8:d3d7dca419b3 92 }
mfwic 8:d3d7dca419b3 93
mfwic 8:d3d7dca419b3 94 menuRedraw(WITH_PROMPT);
mfwic 21:fe0ea1860c9f 95
mfwic 21:fe0ea1860c9f 96 initBoards(adcVals);
mfwic 11:01dcfb29fbc4 97
mfwic 0:44a3005d4f20 98 while (1)
mfwic 0:44a3005d4f20 99 {
mfwic 15:aed8f326c949 100 adcVals = getADCresults();
mfwic 15:aed8f326c949 101
mfwic 22:2c37ac12746e 102 dispVals = calcDisplayValues(adcVals);
mfwic 22:2c37ac12746e 103
mfwic 15:aed8f326c949 104 statVals = checkLevels(adcVals);
mfwic 14:e55ae9bb2a81 105
mfwic 0:44a3005d4f20 106 processCommand();
mfwic 11:01dcfb29fbc4 107
mfwic 14:e55ae9bb2a81 108 // Select RUN from menu to activate running mode.
mfwic 14:e55ae9bb2a81 109 // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode.
mfwic 14:e55ae9bb2a81 110 // CAL and UNCAL do not change state of running or testing.
mfwic 22:2c37ac12746e 111 if(adcVals.i12 < CURRENT_12_OFFSET){
mfwic 22:2c37ac12746e 112 row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR);
mfwic 22:2c37ac12746e 113 buck = TRUE;
mfwic 22:2c37ac12746e 114 }else{
mfwic 22:2c37ac12746e 115 row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR));
mfwic 22:2c37ac12746e 116 buck = FALSE;
mfwic 22:2c37ac12746e 117 }
mfwic 22:2c37ac12746e 118 row_test = abs((int)(row-old_row));
mfwic 14:e55ae9bb2a81 119 if(running){
mfwic 14:e55ae9bb2a81 120 //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode.
mfwic 22:2c37ac12746e 121 if(row_test>ROW_HYSTERESIS){
mfwic 22:2c37ac12746e 122 old_row = row;
mfwic 22:2c37ac12746e 123 if(row<=1023){
mfwic 22:2c37ac12746e 124 updateControls(row);
mfwic 22:2c37ac12746e 125 }
mfwic 22:2c37ac12746e 126 row_print = row;
mfwic 22:2c37ac12746e 127 myled = !myled;
Slord2142 32:05a15c208bfb 128 }
mfwic 14:e55ae9bb2a81 129 }else if(!testing){
mfwic 26:55e8e1a9cc84 130 row_test = abs((int)(my12-old_row));
mfwic 26:55e8e1a9cc84 131 if(row_test>ROW_HYSTERESIS){
mfwic 26:55e8e1a9cc84 132 old_row = my12;
mfwic 26:55e8e1a9cc84 133 if(row<=1023){
mfwic 26:55e8e1a9cc84 134 updateControls(my12);
mfwic 26:55e8e1a9cc84 135 }
mfwic 26:55e8e1a9cc84 136 row_print = my12;
mfwic 26:55e8e1a9cc84 137 myled = !myled;
mfwic 26:55e8e1a9cc84 138 }
mfwic 14:e55ae9bb2a81 139 }
mfwic 6:39442d493098 140
mfwic 6:39442d493098 141 if(updateReady){
mfwic 6:39442d493098 142 updateReady = FALSE;
mfwic 15:aed8f326c949 143 updateTerminal(adcVals, statVals); // May want to gate this call when we run a headless system.
mfwic 25:8bcc8bea0e31 144
mfwic 6:39442d493098 145 }
mfwic 11:01dcfb29fbc4 146 }//end while(1)
mfwic 11:01dcfb29fbc4 147 }//end void main(void)
Slord2142 32:05a15c208bfb 148