Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
Slord2142
Date:
Thu Aug 22 15:38:50 2019 +0000
Revision:
33:6c7364ea360f
Parent:
32:05a15c208bfb
Newest edition. Many changes since last time

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