Treehouse Mbed Team / Mbed 2 deprecated APS_1U5x

Dependencies:   mbed

Committer:
mfwic
Date:
Fri Jan 18 20:17:55 2019 +0000
Revision:
24:078f62c8d0ed
Parent:
22:2c37ac12746e
Child:
25:8bcc8bea0e31
Changed LUT scale factor to target 3W per chip instead of 2.6W.

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