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@43:291bbdba48f3, 2019-03-09 (annotated)
- Committer:
- mfwic
- Date:
- Sat Mar 09 21:16:38 2019 +0000
- Revision:
- 43:291bbdba48f3
- Parent:
- 42:3ae73b61f657
- Child:
- 44:741ee27c8a34
Added boards, lut, and command.
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 | // |
Slord2142 | 41:bd54c88e3334 | 6 | // Copyright (c) 2018 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 | 42:3ae73b61f657 | 30 | #include "math.h" |
mfwic | 42:3ae73b61f657 | 31 | #include "globals.h" |
mfwic | 42:3ae73b61f657 | 32 | #include "parameters.h" |
mfwic | 0:44a3005d4f20 | 33 | #include "all_io.h" |
mfwic | 42:3ae73b61f657 | 34 | #include "stdio.h" |
mfwic | 42:3ae73b61f657 | 35 | #include "stdlib.h" |
mfwic | 42:3ae73b61f657 | 36 | #include "serial.h" |
mfwic | 42:3ae73b61f657 | 37 | #include "adc.h" |
mfwic | 42:3ae73b61f657 | 38 | #include "adc_defs.h" |
mfwic | 42:3ae73b61f657 | 39 | #include "menu.h" |
mfwic | 42:3ae73b61f657 | 40 | #include "boards.h" |
mfwic | 42:3ae73b61f657 | 41 | #include "command.h" |
mfwic | 42:3ae73b61f657 | 42 | #include "clocks.h" |
Slord2142 | 41:bd54c88e3334 | 43 | |
Slord2142 | 41:bd54c88e3334 | 44 | |
Slord2142 | 41:bd54c88e3334 | 45 | //DigitalOut myled(LED1); |
Slord2142 | 41:bd54c88e3334 | 46 | Ticker slowClk; |
Slord2142 | 41:bd54c88e3334 | 47 | Ticker fastClk; |
Slord2142 | 41:bd54c88e3334 | 48 | |
mfwic | 42:3ae73b61f657 | 49 | unsigned short my12=0; |
mfwic | 42:3ae73b61f657 | 50 | volatile bool updateReady = FALSE; |
mfwic | 42:3ae73b61f657 | 51 | unsigned int loopTime = 0; |
mfwic | 42:3ae73b61f657 | 52 | bool raw = FALSE; |
mfwic | 42:3ae73b61f657 | 53 | bool running = FALSE; |
mfwic | 42:3ae73b61f657 | 54 | bool testing = FALSE; |
mfwic | 42:3ae73b61f657 | 55 | bool buck = TRUE; |
mfwic | 43:291bbdba48f3 | 56 | bool pcConnected = FALSE; |
mfwic | 43:291bbdba48f3 | 57 | unsigned int max_rows = 2048; |
mfwic | 43:291bbdba48f3 | 58 | unsigned int bCodeRow[13]; |
mfwic | 43:291bbdba48f3 | 59 | unsigned int max_boards = 3; |
mfwic | 43:291bbdba48f3 | 60 | unsigned short row = 0; |
mfwic | 43:291bbdba48f3 | 61 | int row_test = 0; |
mfwic | 42:3ae73b61f657 | 62 | |
mfwic | 42:3ae73b61f657 | 63 | double CURRENT_48_OFFSET = 33940; |
mfwic | 42:3ae73b61f657 | 64 | double CURRENT_24_OFFSET = 33580; |
mfwic | 42:3ae73b61f657 | 65 | double CURRENT_12_OFFSET = 33256; |
mfwic | 1:9f8583ba2431 | 66 | |
Slord2142 | 41:bd54c88e3334 | 67 | volatile bool dosFlip = FALSE; |
Slord2142 | 41:bd54c88e3334 | 68 | volatile bool dofFlip = FALSE; |
Slord2142 | 41:bd54c88e3334 | 69 | |
Slord2142 | 41:bd54c88e3334 | 70 | void slowFlip() { |
Slord2142 | 41:bd54c88e3334 | 71 | dosFlip = TRUE; |
Slord2142 | 41:bd54c88e3334 | 72 | } |
Slord2142 | 41:bd54c88e3334 | 73 | |
Slord2142 | 41:bd54c88e3334 | 74 | void fastFlip() { |
Slord2142 | 41:bd54c88e3334 | 75 | dofFlip = TRUE; |
Slord2142 | 41:bd54c88e3334 | 76 | } |
mfwic | 25:8bcc8bea0e31 | 77 | |
Slord2142 | 41:bd54c88e3334 | 78 | int main() { |
Slord2142 | 41:bd54c88e3334 | 79 | |
Slord2142 | 41:bd54c88e3334 | 80 | initOut(); |
Slord2142 | 41:bd54c88e3334 | 81 | |
Slord2142 | 41:bd54c88e3334 | 82 | slowClk.attach(&slowFlip, 0.0003); |
Slord2142 | 41:bd54c88e3334 | 83 | fastClk.attach(&fastFlip, 0.00001); |
mfwic | 43:291bbdba48f3 | 84 | |
mfwic | 43:291bbdba48f3 | 85 | running = FALSE; |
mfwic | 43:291bbdba48f3 | 86 | |
mfwic | 43:291bbdba48f3 | 87 | initSerial(); |
Slord2142 | 41:bd54c88e3334 | 88 | |
mfwic | 43:291bbdba48f3 | 89 | initDRT(); // Display Refresh Timer |
mfwic | 43:291bbdba48f3 | 90 | |
mfwic | 43:291bbdba48f3 | 91 | initADC(); |
mfwic | 43:291bbdba48f3 | 92 | |
mfwic | 43:291bbdba48f3 | 93 | struct adcValues adcVals = getADCresults(); |
mfwic | 43:291bbdba48f3 | 94 | struct displayValues dispVals = calcDisplayValues(adcVals); |
mfwic | 43:291bbdba48f3 | 95 | struct statusValues statVals = checkLevels(adcVals); |
mfwic | 43:291bbdba48f3 | 96 | |
mfwic | 43:291bbdba48f3 | 97 | row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR); |
mfwic | 43:291bbdba48f3 | 98 | unsigned int old_row = row; |
mfwic | 43:291bbdba48f3 | 99 | |
mfwic | 43:291bbdba48f3 | 100 | menu_banner(); |
mfwic | 43:291bbdba48f3 | 101 | sprintf(strbuf, "\r\nPress Enter to continue"); |
mfwic | 43:291bbdba48f3 | 102 | sendSerial(strbuf); |
mfwic | 43:291bbdba48f3 | 103 | //while(waitCommand()){ // Wait for user to press Enter |
mfwic | 43:291bbdba48f3 | 104 | //} |
mfwic | 43:291bbdba48f3 | 105 | |
mfwic | 43:291bbdba48f3 | 106 | menuRedraw(WITH_PROMPT); |
mfwic | 43:291bbdba48f3 | 107 | |
mfwic | 43:291bbdba48f3 | 108 | initBoards(adcVals); |
mfwic | 43:291bbdba48f3 | 109 | |
mfwic | 43:291bbdba48f3 | 110 | while (1) |
mfwic | 43:291bbdba48f3 | 111 | { |
mfwic | 43:291bbdba48f3 | 112 | adcVals = getADCresults(); |
mfwic | 43:291bbdba48f3 | 113 | |
mfwic | 43:291bbdba48f3 | 114 | dispVals = calcDisplayValues(adcVals); |
mfwic | 43:291bbdba48f3 | 115 | |
mfwic | 43:291bbdba48f3 | 116 | statVals = checkLevels(adcVals); |
mfwic | 43:291bbdba48f3 | 117 | |
mfwic | 43:291bbdba48f3 | 118 | processCommand(); |
mfwic | 43:291bbdba48f3 | 119 | |
mfwic | 43:291bbdba48f3 | 120 | checkFlip(); |
mfwic | 43:291bbdba48f3 | 121 | |
mfwic | 43:291bbdba48f3 | 122 | // Select RUN from menu to activate running mode. |
mfwic | 43:291bbdba48f3 | 123 | // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode. |
mfwic | 43:291bbdba48f3 | 124 | // CAL and UNCAL do not change state of running or testing. |
mfwic | 43:291bbdba48f3 | 125 | if(adcVals.i12 < CURRENT_12_OFFSET){ |
mfwic | 43:291bbdba48f3 | 126 | row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR); |
mfwic | 43:291bbdba48f3 | 127 | buck = TRUE; |
mfwic | 43:291bbdba48f3 | 128 | }else{ |
mfwic | 43:291bbdba48f3 | 129 | row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR)); |
mfwic | 43:291bbdba48f3 | 130 | buck = FALSE; |
mfwic | 43:291bbdba48f3 | 131 | } |
mfwic | 43:291bbdba48f3 | 132 | row_test = abs((int)(row-old_row)); |
mfwic | 43:291bbdba48f3 | 133 | if(running){ |
mfwic | 43:291bbdba48f3 | 134 | //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode. |
mfwic | 43:291bbdba48f3 | 135 | if(row_test>ROW_HYSTERESIS){ |
mfwic | 43:291bbdba48f3 | 136 | old_row = row; |
mfwic | 43:291bbdba48f3 | 137 | if(row<=1023){ |
mfwic | 43:291bbdba48f3 | 138 | updateControls(row); |
mfwic | 43:291bbdba48f3 | 139 | } |
mfwic | 43:291bbdba48f3 | 140 | } |
mfwic | 43:291bbdba48f3 | 141 | }else if(!testing){ |
mfwic | 43:291bbdba48f3 | 142 | row_test = abs((int)(my12-old_row)); |
mfwic | 43:291bbdba48f3 | 143 | if(row_test>ROW_HYSTERESIS){ |
mfwic | 43:291bbdba48f3 | 144 | old_row = my12; |
mfwic | 43:291bbdba48f3 | 145 | if(row<=1023){ |
mfwic | 43:291bbdba48f3 | 146 | updateControls(my12); |
mfwic | 43:291bbdba48f3 | 147 | } |
mfwic | 43:291bbdba48f3 | 148 | } |
mfwic | 43:291bbdba48f3 | 149 | } |
mfwic | 43:291bbdba48f3 | 150 | |
mfwic | 43:291bbdba48f3 | 151 | if(updateReady && pcConnected){ |
mfwic | 43:291bbdba48f3 | 152 | updateReady = FALSE; |
mfwic | 43:291bbdba48f3 | 153 | updateTerminal(adcVals, statVals); // May want to gate this call when we run a headless system. |
mfwic | 43:291bbdba48f3 | 154 | |
mfwic | 43:291bbdba48f3 | 155 | } |
mfwic | 43:291bbdba48f3 | 156 | }//end while(1) |
mfwic | 43:291bbdba48f3 | 157 | }//end void main(void) |