Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
src/main.cpp@14:e55ae9bb2a81, 2018-12-08 (annotated)
- Committer:
- mfwic
- Date:
- Sat Dec 08 16:57:27 2018 +0000
- Revision:
- 14:e55ae9bb2a81
- Parent:
- 12:fd1fd1857628
- Child:
- 15:aed8f326c949
Deleted BUCK and BOOST commands.; Added auto-detect of buck/boost modes by testing the "polarity" of the current signals.
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:39442d493098 | 50 | |
mfwic | 6:39442d493098 | 51 | Timer masterTimer; |
mfwic | 0:44a3005d4f20 | 52 | |
mfwic | 0:44a3005d4f20 | 53 | int main() |
mfwic | 0:44a3005d4f20 | 54 | { |
mfwic | 7:860b3a8275cb | 55 | myled = 0; |
mfwic | 0:44a3005d4f20 | 56 | extchlat = OFF; |
mfwic | 6:39442d493098 | 57 | wr_out_code = setBoardEnables(ALLOFF); |
mfwic | 11:01dcfb29fbc4 | 58 | en_out_code = setBoardWeights(ALLOFF); // RK: Maybe? Use hex value for boardWeights to highlight that it's an encoded value. |
mfwic | 7:860b3a8275cb | 59 | running = FALSE; |
mfwic | 11:01dcfb29fbc4 | 60 | |
mfwic | 7:860b3a8275cb | 61 | initSerial(); |
mfwic | 3:d8948c5b2951 | 62 | |
mfwic | 7:860b3a8275cb | 63 | initDRT(); // Display Refresh Timer |
mfwic | 7:860b3a8275cb | 64 | |
mfwic | 0:44a3005d4f20 | 65 | initADC(); |
mfwic | 11:01dcfb29fbc4 | 66 | |
mfwic | 11:01dcfb29fbc4 | 67 | struct adcValues avals = getADCresults(); |
mfwic | 7:860b3a8275cb | 68 | |
mfwic | 8:d3d7dca419b3 | 69 | splash_screen(); |
mfwic | 8:d3d7dca419b3 | 70 | sprintf(strbuf, "\r\nPress Enter to continue"); |
mfwic | 8:d3d7dca419b3 | 71 | sendSerial(strbuf); |
mfwic | 11:01dcfb29fbc4 | 72 | while(waitCommand()){ // Wait for user to press Enter |
mfwic | 8:d3d7dca419b3 | 73 | } |
mfwic | 8:d3d7dca419b3 | 74 | |
mfwic | 8:d3d7dca419b3 | 75 | menuRedraw(WITH_PROMPT); |
mfwic | 11:01dcfb29fbc4 | 76 | |
mfwic | 0:44a3005d4f20 | 77 | while (1) |
mfwic | 0:44a3005d4f20 | 78 | { |
mfwic | 14:e55ae9bb2a81 | 79 | avals = getADCresults(); |
mfwic | 14:e55ae9bb2a81 | 80 | |
mfwic | 0:44a3005d4f20 | 81 | processCommand(); |
mfwic | 11:01dcfb29fbc4 | 82 | |
mfwic | 14:e55ae9bb2a81 | 83 | // Select RUN from menu to activate running mode. |
mfwic | 14:e55ae9bb2a81 | 84 | // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode. |
mfwic | 14:e55ae9bb2a81 | 85 | // CAL and UNCAL do not change state of running or testing. |
mfwic | 14:e55ae9bb2a81 | 86 | if(running){ |
mfwic | 14:e55ae9bb2a81 | 87 | //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode. |
mfwic | 14:e55ae9bb2a81 | 88 | if((avals.i12 < CURRENT_12_OFFSET) & (avals.i48 < CURRENT_48_OFFSET)){ |
mfwic | 14:e55ae9bb2a81 | 89 | updateControls(avals.i12); |
mfwic | 14:e55ae9bb2a81 | 90 | }else{ |
mfwic | 14:e55ae9bb2a81 | 91 | updateControls(-(avals.i48)); |
mfwic | 14:e55ae9bb2a81 | 92 | } |
mfwic | 14:e55ae9bb2a81 | 93 | //count++; |
mfwic | 14:e55ae9bb2a81 | 94 | }else if(!testing){ |
mfwic | 14:e55ae9bb2a81 | 95 | updateControls(my12); |
mfwic | 14:e55ae9bb2a81 | 96 | } |
mfwic | 6:39442d493098 | 97 | |
mfwic | 6:39442d493098 | 98 | if(updateReady){ |
mfwic | 6:39442d493098 | 99 | updateReady = FALSE; |
mfwic | 11:01dcfb29fbc4 | 100 | updateTerminal(avals); // May want to gate this call when we run a headless system. |
mfwic | 7:860b3a8275cb | 101 | //loopTime = masterTimer.read_ms();// - loopTime; |
mfwic | 7:860b3a8275cb | 102 | myled = !myled; |
mfwic | 9:816b9a4e4f21 | 103 | //sprintf(strbuf, "\r\nupdateControls ran %d times.\r\n", count); |
mfwic | 9:816b9a4e4f21 | 104 | //sendSerial(strbuf); |
mfwic | 9:816b9a4e4f21 | 105 | //count=0; |
mfwic | 6:39442d493098 | 106 | } |
mfwic | 11:01dcfb29fbc4 | 107 | }//end while(1) |
mfwic | 11:01dcfb29fbc4 | 108 | }//end void main(void) |
mfwic | 0:44a3005d4f20 | 109 |