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
Diff: src/main.cpp
- Revision:
- 41:bd54c88e3334
- Parent:
- 32:05a15c208bfb
- Child:
- 42:3ae73b61f657
--- a/src/main.cpp Fri Mar 08 20:44:56 2019 +0000
+++ b/src/main.cpp Sat Mar 09 19:55:05 2019 +0000
@@ -3,7 +3,7 @@
// Treehouse Designs Inc.
// Colorado Springs, Colorado
//
-// Copyright (c) 2016 by Treehouse Designs Inc.
+// Copyright (c) 2018 by Treehouse Designs Inc.
// Copyright (c) 2018 by Agility Power Systems Inc.
//
// This code is the property of Treehouse Designs, Inc. (Treehouse) and
@@ -27,122 +27,164 @@
//-------------------------------------------------------------------------------
#include "mbed.h"
-#include "math.h"
-#include "globals.h"
-#include "parameters.h"
+#include "PortOut.h"
#include "all_io.h"
-#include "stdio.h"
-#include "stdlib.h"
-#include "serial.h"
-#include "adc.h"
-#include "adc_defs.h"
-#include "menu.h"
-#include "boards.h"
-#include "command.h"
+
+
+
+//DigitalOut myled(LED1);
+Ticker slowClk;
+Ticker fastClk;
+
+#define TRUE 1
+#define FALSE 0
-unsigned int en_out_code;
-unsigned int wr_out_code;
-unsigned int max_boards = 13;
-unsigned int max_rows = 2048;
-unsigned int bCodeRow[13];
+volatile bool dosFlip = FALSE;
+volatile bool dofFlip = FALSE;
+
+void slowFlip() {
+ dosFlip = TRUE;
+}
+
+void fastFlip() {
+ dofFlip = TRUE;
+}
-unsigned short my12=0;
-volatile bool updateReady = FALSE;
-unsigned int loopTime = 0;
-bool raw = FALSE;
-bool running = FALSE;
-bool testing = FALSE;
-bool buck = TRUE;
-
-double CURRENT_48_OFFSET = 33940;
-double CURRENT_24_OFFSET = 33580;
-double CURRENT_12_OFFSET = 33256;
-
-unsigned short row = 0;
-int row_test = 0;
-int row_print = 0;
-
-Timer masterTimer;
-
-int main()
-{
- myled = 0;
- extchlat = OFF;
- wr_out_code = setBoardEnables(ALLON);
- en_out_code = setBoardWeights(32);
- running = FALSE;
-
- initSerial();
-
- initDRT(); // Display Refresh Timer
-
- initADC();
+void initOut(void){
+ ec2 = 1;
+ ec15 = 1;
+ ec26 = 1;
+ ec6 = 1;
+ ec12 = 1;
+ ec25 = 1;
+ ec36 = 1;
+ ec31 = 1;
+ ec9 = 1;
+ ec5 = 1;
+ ec24 = 1;
+ ec11 = 1;
+ ec1 = 1;
+ ec10 = 1;
+ ec23 = 1;
+ ec7 = 1;
+ ec18 = 1;
+ ec14 = 1;
+ ec27 = 1;
+ ec19 = 1;
+ ec32 = 1;
+ ec35 = 1;
+ ec21 = 1;
+ ec30 = 1;
+ ec33 = 1;
+ ec20 = 1;
+ ec34 = 1;
+ ec29 = 1;
+ ec8 = 1;
+ ec4 = 1;
+ ec17 = 1;
+ ec13 = 1;
+ ec26 = 1;
+ ec22 = 1;
+}
- struct adcValues adcVals = getADCresults();
- struct displayValues dispVals = calcDisplayValues(adcVals);
- struct statusValues statVals = checkLevels(adcVals);
-
- row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR);
- unsigned int old_row = row;
-
- menu_banner();
- sprintf(strbuf, "\r\nPress Enter to continue");
- sendSerial(strbuf);
- while(waitCommand()){ // Wait for user to press Enter
- }
-
- menuRedraw(WITH_PROMPT);
-
- initBoards(adcVals);
-
- while (1)
- {
- adcVals = getADCresults();
-
- dispVals = calcDisplayValues(adcVals);
-
- statVals = checkLevels(adcVals);
-
- processCommand();
+void flipSlow(void){
+ dosFlip = FALSE;
+ if(!ILR_enable){
+ ec2 = !ec2;
+ ec15 = !ec15;
+ ec26 = !ec26;
+ ec6 = !ec6;
+ ec12 = !ec12;
+ ec25 = !ec25;
+ ec36 = !ec36;
+ ec31 = !ec31;
+ ec9 = !ec9;
+ ec5 = !ec5;
+ ec24 = !ec24;
+ ec11 = !ec11;
+ ec1 = !ec1;
+ ec10 = !ec10;
+ ec23 = !ec23;
+ ec7 = !ec7;
+ ec18 = !ec18;
+ ec14 = !ec14;
+ ec27 = !ec27;
+ ec19 = !ec19;
+ ec32 = !ec32;
+ ec35 = !ec35;
+ ec21 = !ec21;
+ ec30 = !ec30;
+ ec33 = !ec33;
+ ec20 = !ec20;
+ ec34 = !ec34;
+ ec29 = !ec29;
+ ec8 = !ec8;
+ ec4 = !ec4;
+ ec17 = !ec17;
+ ec13 = !ec13;
+ ec26 = !ec26;
+ ec22 = !ec22;
+ }
+}
- // Select RUN from menu to activate running mode.
- // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode.
- // CAL and UNCAL do not change state of running or testing.
- if(adcVals.i12 < CURRENT_12_OFFSET){
- row = (unsigned short)(dispVals.i12f*dispVals.v12f*ROW_CORRECTION_FACTOR);
- buck = TRUE;
- }else{
- row = (unsigned short)(dispVals.i12f*dispVals.v12f*(-ROW_CORRECTION_FACTOR));
- buck = FALSE;
- }
- row_test = abs((int)(row-old_row));
- if(running){
- //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode.
- if(row_test>ROW_HYSTERESIS){
- old_row = row;
- if(row<=1023){
- updateControls(row);
- }
- row_print = row;
- myled = !myled;
- }
- }else if(!testing){
- row_test = abs((int)(my12-old_row));
- if(row_test>ROW_HYSTERESIS){
- old_row = my12;
- if(row<=1023){
- updateControls(my12);
- }
- row_print = my12;
- myled = !myled;
- }
- }
-
- if(updateReady){
- updateReady = FALSE;
- updateTerminal(adcVals, statVals); // May want to gate this call when we run a headless system.
+void flipFast(void){
+ dofFlip = FALSE;
+ if(ILR_enable){
+ ec2 = !ec2;
+ ec15 = !ec15;
+ ec26 = !ec26;
+ ec6 = !ec6;
+ ec12 = !ec12;
+ ec25 = !ec25;
+ ec36 = !ec36;
+ ec31 = !ec31;
+ ec9 = !ec9;
+ ec5 = !ec5;
+ ec24 = !ec24;
+ ec11 = !ec11;
+ ec1 = !ec1;
+ ec10 = !ec10;
+ ec23 = !ec23;
+ ec7 = !ec7;
+ ec18 = !ec18;
+ ec14 = !ec14;
+ ec27 = !ec27;
+ ec19 = !ec19;
+ ec32 = !ec32;
+ ec35 = !ec35;
+ ec21 = !ec21;
+ ec30 = !ec30;
+ ec33 = !ec33;
+ ec20 = !ec20;
+ ec34 = !ec34;
+ ec29 = !ec29;
+ ec8 = !ec8;
+ ec4 = !ec4;
+ ec17 = !ec17;
+ ec13 = !ec13;
+ ec26 = !ec26;
+ ec22 = !ec22;
+ }
+}
- }
- }//end while(1)
-}//end void main(void)
+void checkFlip(void){
+ if(dosFlip){
+ flipSlow();
+ }
+ if(dofFlip){
+ flipFast();
+ }
+}
+int main() {
+
+ initOut();
+
+ slowClk.attach(&slowFlip, 0.0003);
+ fastClk.attach(&fastFlip, 0.00001);
+
+ while(1){
+ checkFlip();
+ }
+
+}
\ No newline at end of file