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@26:55e8e1a9cc84, 2019-01-22 (annotated)
- Committer:
- mfwic
- Date:
- Tue Jan 22 19:56:22 2019 +0000
- Revision:
- 26:55e8e1a9cc84
- Parent:
- 25:8bcc8bea0e31
Sent to customer for demo
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 | 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 | 25:8bcc8bea0e31 | 45 | unsigned int max_boards = 13; |
mfwic | 25:8bcc8bea0e31 | 46 | unsigned int max_rows = 2048; |
mfwic | 25:8bcc8bea0e31 | 47 | //unsigned int bCodeArray[2048][13]; |
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 | 15:aed8f326c949 | 90 | //initBoards(adcVals); |
mfwic | 8:d3d7dca419b3 | 91 | sprintf(strbuf, "\r\nPress Enter to continue"); |
mfwic | 8:d3d7dca419b3 | 92 | sendSerial(strbuf); |
mfwic | 11:01dcfb29fbc4 | 93 | while(waitCommand()){ // Wait for user to press Enter |
mfwic | 8:d3d7dca419b3 | 94 | } |
mfwic | 8:d3d7dca419b3 | 95 | |
mfwic | 8:d3d7dca419b3 | 96 | menuRedraw(WITH_PROMPT); |
mfwic | 21:fe0ea1860c9f | 97 | |
mfwic | 21:fe0ea1860c9f | 98 | initBoards(adcVals); |
mfwic | 11:01dcfb29fbc4 | 99 | |
mfwic | 0:44a3005d4f20 | 100 | while (1) |
mfwic | 0:44a3005d4f20 | 101 | { |
mfwic | 15:aed8f326c949 | 102 | adcVals = getADCresults(); |
mfwic | 15:aed8f326c949 | 103 | |
mfwic | 22:2c37ac12746e | 104 | dispVals = calcDisplayValues(adcVals); |
mfwic | 22:2c37ac12746e | 105 | |
mfwic | 15:aed8f326c949 | 106 | statVals = checkLevels(adcVals); |
mfwic | 14:e55ae9bb2a81 | 107 | |
mfwic | 0:44a3005d4f20 | 108 | processCommand(); |
mfwic | 11:01dcfb29fbc4 | 109 | |
mfwic | 14:e55ae9bb2a81 | 110 | // Select RUN from menu to activate running mode. |
mfwic | 14:e55ae9bb2a81 | 111 | // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode. |
mfwic | 14:e55ae9bb2a81 | 112 | // CAL and UNCAL do not change state of running or testing. |
mfwic | 22:2c37ac12746e | 113 | if(adcVals.i12 < CURRENT_12_OFFSET){ |
mfwic | 22:2c37ac12746e | 114 | row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR); |
mfwic | 22:2c37ac12746e | 115 | //updateControls(CURRENT_12_OFFSET-adcVals.i12); |
mfwic | 22:2c37ac12746e | 116 | buck = TRUE; |
mfwic | 22:2c37ac12746e | 117 | }else{ |
mfwic | 24:078f62c8d0ed | 118 | //row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR)); |
mfwic | 22:2c37ac12746e | 119 | row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR)); |
mfwic | 22:2c37ac12746e | 120 | //updateControls(adcVals.i12-CURRENT_12_OFFSET); |
mfwic | 22:2c37ac12746e | 121 | buck = FALSE; |
mfwic | 22:2c37ac12746e | 122 | } |
mfwic | 22:2c37ac12746e | 123 | row_test = abs((int)(row-old_row)); |
mfwic | 14:e55ae9bb2a81 | 124 | if(running){ |
mfwic | 14:e55ae9bb2a81 | 125 | //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode. |
mfwic | 22:2c37ac12746e | 126 | if(row_test>ROW_HYSTERESIS){ |
mfwic | 22:2c37ac12746e | 127 | old_row = row; |
mfwic | 22:2c37ac12746e | 128 | //updateControls(CURRENT_12_OFFSET-adcVals.i12); |
mfwic | 22:2c37ac12746e | 129 | if(row<=1023){ |
mfwic | 22:2c37ac12746e | 130 | updateControls(row); |
mfwic | 22:2c37ac12746e | 131 | } |
mfwic | 22:2c37ac12746e | 132 | row_print = row; |
mfwic | 22:2c37ac12746e | 133 | myled = !myled; |
mfwic | 22:2c37ac12746e | 134 | }//else if(row_test<=ROW_HYSTERESIS){ |
mfwic | 22:2c37ac12746e | 135 | // old_row = row; |
mfwic | 22:2c37ac12746e | 136 | // updateControls(row); |
mfwic | 22:2c37ac12746e | 137 | //} |
mfwic | 14:e55ae9bb2a81 | 138 | //count++; |
mfwic | 14:e55ae9bb2a81 | 139 | }else if(!testing){ |
mfwic | 26:55e8e1a9cc84 | 140 | row_test = abs((int)(my12-old_row)); |
mfwic | 26:55e8e1a9cc84 | 141 | if(row_test>ROW_HYSTERESIS){ |
mfwic | 26:55e8e1a9cc84 | 142 | old_row = my12; |
mfwic | 26:55e8e1a9cc84 | 143 | //updateControls(CURRENT_12_OFFSET-adcVals.i12); |
mfwic | 26:55e8e1a9cc84 | 144 | if(row<=1023){ |
mfwic | 26:55e8e1a9cc84 | 145 | //updateControls(row); |
mfwic | 26:55e8e1a9cc84 | 146 | updateControls(my12); |
mfwic | 26:55e8e1a9cc84 | 147 | } |
mfwic | 26:55e8e1a9cc84 | 148 | row_print = my12; |
mfwic | 26:55e8e1a9cc84 | 149 | myled = !myled; |
mfwic | 26:55e8e1a9cc84 | 150 | } |
mfwic | 14:e55ae9bb2a81 | 151 | } |
mfwic | 6:39442d493098 | 152 | |
mfwic | 6:39442d493098 | 153 | if(updateReady){ |
mfwic | 6:39442d493098 | 154 | updateReady = FALSE; |
mfwic | 15:aed8f326c949 | 155 | updateTerminal(adcVals, statVals); // May want to gate this call when we run a headless system. |
mfwic | 7:860b3a8275cb | 156 | //loopTime = masterTimer.read_ms();// - loopTime; |
mfwic | 22:2c37ac12746e | 157 | //myled = !myled; |
mfwic | 25:8bcc8bea0e31 | 158 | |
mfwic | 6:39442d493098 | 159 | } |
mfwic | 11:01dcfb29fbc4 | 160 | }//end while(1) |
mfwic | 11:01dcfb29fbc4 | 161 | }//end void main(void) |
mfwic | 0:44a3005d4f20 | 162 |