Treehouse Mbed Team / Mbed 2 deprecated APS_1U5x

Dependencies:   mbed

Committer:
mfwic
Date:
Tue Dec 11 16:59:21 2018 +0000
Revision:
15:aed8f326c949
Parent:
14:e55ae9bb2a81
Child:
16:5791665200cb
Added voltage level checks.

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 6:39442d493098 52 Timer masterTimer;
mfwic 0:44a3005d4f20 53
mfwic 0:44a3005d4f20 54 int main()
mfwic 0:44a3005d4f20 55 {
mfwic 7:860b3a8275cb 56 myled = 0;
mfwic 0:44a3005d4f20 57 extchlat = OFF;
mfwic 6:39442d493098 58 wr_out_code = setBoardEnables(ALLOFF);
mfwic 11:01dcfb29fbc4 59 en_out_code = setBoardWeights(ALLOFF); // RK: Maybe? Use hex value for boardWeights to highlight that it's an encoded value.
mfwic 7:860b3a8275cb 60 running = FALSE;
mfwic 11:01dcfb29fbc4 61
mfwic 7:860b3a8275cb 62 initSerial();
mfwic 3:d8948c5b2951 63
mfwic 7:860b3a8275cb 64 initDRT(); // Display Refresh Timer
mfwic 7:860b3a8275cb 65
mfwic 0:44a3005d4f20 66 initADC();
mfwic 11:01dcfb29fbc4 67
mfwic 15:aed8f326c949 68 struct adcValues adcVals = getADCresults();
mfwic 15:aed8f326c949 69 struct statusValues statVals = checkLevels(adcVals);
mfwic 7:860b3a8275cb 70
mfwic 8:d3d7dca419b3 71 splash_screen();
mfwic 15:aed8f326c949 72 //initBoards(adcVals);
mfwic 8:d3d7dca419b3 73 sprintf(strbuf, "\r\nPress Enter to continue");
mfwic 8:d3d7dca419b3 74 sendSerial(strbuf);
mfwic 11:01dcfb29fbc4 75 while(waitCommand()){ // Wait for user to press Enter
mfwic 8:d3d7dca419b3 76 }
mfwic 8:d3d7dca419b3 77
mfwic 8:d3d7dca419b3 78 menuRedraw(WITH_PROMPT);
mfwic 11:01dcfb29fbc4 79
mfwic 0:44a3005d4f20 80 while (1)
mfwic 0:44a3005d4f20 81 {
mfwic 15:aed8f326c949 82 adcVals = getADCresults();
mfwic 15:aed8f326c949 83
mfwic 15:aed8f326c949 84 statVals = checkLevels(adcVals);
mfwic 14:e55ae9bb2a81 85
mfwic 0:44a3005d4f20 86 processCommand();
mfwic 11:01dcfb29fbc4 87
mfwic 14:e55ae9bb2a81 88 // Select RUN from menu to activate running mode.
mfwic 14:e55ae9bb2a81 89 // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode.
mfwic 14:e55ae9bb2a81 90 // CAL and UNCAL do not change state of running or testing.
mfwic 14:e55ae9bb2a81 91 if(running){
mfwic 14:e55ae9bb2a81 92 //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode.
mfwic 15:aed8f326c949 93 if(adcVals.i12 < CURRENT_12_OFFSET){
mfwic 15:aed8f326c949 94 updateControls(adcVals.i12);
mfwic 15:aed8f326c949 95 buck = TRUE;
mfwic 14:e55ae9bb2a81 96 }else{
mfwic 15:aed8f326c949 97 updateControls(adcVals.i12-CURRENT_12_OFFSET);
mfwic 15:aed8f326c949 98 buck = FALSE;
mfwic 14:e55ae9bb2a81 99 }
mfwic 14:e55ae9bb2a81 100 //count++;
mfwic 14:e55ae9bb2a81 101 }else if(!testing){
mfwic 14:e55ae9bb2a81 102 updateControls(my12);
mfwic 14:e55ae9bb2a81 103 }
mfwic 6:39442d493098 104
mfwic 6:39442d493098 105 if(updateReady){
mfwic 6:39442d493098 106 updateReady = FALSE;
mfwic 15:aed8f326c949 107 updateTerminal(adcVals, statVals); // May want to gate this call when we run a headless system.
mfwic 7:860b3a8275cb 108 //loopTime = masterTimer.read_ms();// - loopTime;
mfwic 7:860b3a8275cb 109 myled = !myled;
mfwic 9:816b9a4e4f21 110 //sprintf(strbuf, "\r\nupdateControls ran %d times.\r\n", count);
mfwic 9:816b9a4e4f21 111 //sendSerial(strbuf);
mfwic 9:816b9a4e4f21 112 //count=0;
mfwic 6:39442d493098 113 }
mfwic 11:01dcfb29fbc4 114 }//end while(1)
mfwic 11:01dcfb29fbc4 115 }//end void main(void)
mfwic 0:44a3005d4f20 116