Treehouse Mbed Team / Mbed 2 deprecated APS_1U5x

Dependencies:   mbed

Committer:
mfwic
Date:
Thu Dec 13 21:58:28 2018 +0000
Revision:
17:454afe56eedb
Parent:
16:5791665200cb
Child:
18:78e982f31c6b
Removed voltage limit check to stop converter. Now just show voltage levels in status.; LUT v1p1.

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 0:44a3005d4f20 30 #include "globals.h"
mfwic 0:44a3005d4f20 31 #include "parameters.h"
mfwic 0:44a3005d4f20 32 #include "all_io.h"
mfwic 0:44a3005d4f20 33 #include "stdio.h"
mfwic 0:44a3005d4f20 34 #include "stdlib.h"
mfwic 0:44a3005d4f20 35 #include "serial.h"
mfwic 0:44a3005d4f20 36 #include "adc.h"
mfwic 14:e55ae9bb2a81 37 #include "adc_defs.h"
mfwic 2:46faae84b8b0 38 #include "menu.h"
mfwic 1:9f8583ba2431 39 #include "boards.h"
mfwic 8:d3d7dca419b3 40 #include "command.h"
mfwic 1:9f8583ba2431 41
mfwic 6:39442d493098 42 unsigned int en_out_code;
mfwic 6:39442d493098 43 unsigned int wr_out_code;
mfwic 6:39442d493098 44 unsigned short my12=0;
mfwic 6:39442d493098 45 volatile bool updateReady = FALSE;
mfwic 6:39442d493098 46 unsigned int loopTime = 0;
mfwic 8:d3d7dca419b3 47 bool raw = FALSE;
mfwic 11:01dcfb29fbc4 48 bool running = FALSE;
mfwic 12:fd1fd1857628 49 bool testing = FALSE;
mfwic 15:aed8f326c949 50 bool buck = TRUE;
mfwic 6:39442d493098 51
mfwic 17:454afe56eedb 52 double CURRENT_48_OFFSET = 33940;
mfwic 17:454afe56eedb 53 double CURRENT_24_OFFSET = 33580;
mfwic 17:454afe56eedb 54 double CURRENT_12_OFFSET = 33380;
mfwic 17:454afe56eedb 55
mfwic 6:39442d493098 56 Timer masterTimer;
mfwic 0:44a3005d4f20 57
mfwic 0:44a3005d4f20 58 int main()
mfwic 0:44a3005d4f20 59 {
mfwic 7:860b3a8275cb 60 myled = 0;
mfwic 0:44a3005d4f20 61 extchlat = OFF;
mfwic 6:39442d493098 62 wr_out_code = setBoardEnables(ALLOFF);
mfwic 11:01dcfb29fbc4 63 en_out_code = setBoardWeights(ALLOFF); // RK: Maybe? Use hex value for boardWeights to highlight that it's an encoded value.
mfwic 7:860b3a8275cb 64 running = FALSE;
mfwic 11:01dcfb29fbc4 65
mfwic 7:860b3a8275cb 66 initSerial();
mfwic 3:d8948c5b2951 67
mfwic 7:860b3a8275cb 68 initDRT(); // Display Refresh Timer
mfwic 7:860b3a8275cb 69
mfwic 0:44a3005d4f20 70 initADC();
mfwic 11:01dcfb29fbc4 71
mfwic 15:aed8f326c949 72 struct adcValues adcVals = getADCresults();
mfwic 15:aed8f326c949 73 struct statusValues statVals = checkLevels(adcVals);
mfwic 7:860b3a8275cb 74
mfwic 16:5791665200cb 75 menu_banner();
mfwic 15:aed8f326c949 76 //initBoards(adcVals);
mfwic 8:d3d7dca419b3 77 sprintf(strbuf, "\r\nPress Enter to continue");
mfwic 8:d3d7dca419b3 78 sendSerial(strbuf);
mfwic 11:01dcfb29fbc4 79 while(waitCommand()){ // Wait for user to press Enter
mfwic 8:d3d7dca419b3 80 }
mfwic 8:d3d7dca419b3 81
mfwic 8:d3d7dca419b3 82 menuRedraw(WITH_PROMPT);
mfwic 11:01dcfb29fbc4 83
mfwic 0:44a3005d4f20 84 while (1)
mfwic 0:44a3005d4f20 85 {
mfwic 15:aed8f326c949 86 adcVals = getADCresults();
mfwic 15:aed8f326c949 87
mfwic 15:aed8f326c949 88 statVals = checkLevels(adcVals);
mfwic 14:e55ae9bb2a81 89
mfwic 0:44a3005d4f20 90 processCommand();
mfwic 11:01dcfb29fbc4 91
mfwic 14:e55ae9bb2a81 92 // Select RUN from menu to activate running mode.
mfwic 14:e55ae9bb2a81 93 // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode.
mfwic 14:e55ae9bb2a81 94 // CAL and UNCAL do not change state of running or testing.
mfwic 14:e55ae9bb2a81 95 if(running){
mfwic 14:e55ae9bb2a81 96 //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode.
mfwic 15:aed8f326c949 97 if(adcVals.i12 < CURRENT_12_OFFSET){
mfwic 15:aed8f326c949 98 updateControls(adcVals.i12);
mfwic 15:aed8f326c949 99 buck = TRUE;
mfwic 14:e55ae9bb2a81 100 }else{
mfwic 15:aed8f326c949 101 updateControls(adcVals.i12-CURRENT_12_OFFSET);
mfwic 15:aed8f326c949 102 buck = FALSE;
mfwic 14:e55ae9bb2a81 103 }
mfwic 14:e55ae9bb2a81 104 //count++;
mfwic 14:e55ae9bb2a81 105 }else if(!testing){
mfwic 14:e55ae9bb2a81 106 updateControls(my12);
mfwic 14:e55ae9bb2a81 107 }
mfwic 6:39442d493098 108
mfwic 6:39442d493098 109 if(updateReady){
mfwic 6:39442d493098 110 updateReady = FALSE;
mfwic 15:aed8f326c949 111 updateTerminal(adcVals, statVals); // May want to gate this call when we run a headless system.
mfwic 7:860b3a8275cb 112 //loopTime = masterTimer.read_ms();// - loopTime;
mfwic 7:860b3a8275cb 113 myled = !myled;
mfwic 9:816b9a4e4f21 114 //sprintf(strbuf, "\r\nupdateControls ran %d times.\r\n", count);
mfwic 9:816b9a4e4f21 115 //sendSerial(strbuf);
mfwic 9:816b9a4e4f21 116 //count=0;
mfwic 6:39442d493098 117 }
mfwic 11:01dcfb29fbc4 118 }//end while(1)
mfwic 11:01dcfb29fbc4 119 }//end void main(void)
mfwic 0:44a3005d4f20 120