Flying Sea Glider / Mbed 2 deprecated 2019_13sep_jcw_nosd

Dependencies:   mbed MODSERIAL FATFileSystem

Files at this revision

API Documentation at this revision

Comitter:
mkelly10
Date:
Mon Jun 04 15:20:21 2018 +0000
Parent:
50:1d59ea7c7a1c
Child:
52:f207567d3ea4
Commit message:
FSG_PCB_V1

Changed in this revision

LTC1298/ltc1298.cpp Show annotated file Show diff for this revision Revisions of this file
LTC1298/ltc1298.hpp Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show diff for this revision Revisions of this file
StateMachine/StateMachine.cpp Show annotated file Show diff for this revision Revisions of this file
System/StaticDefs.cpp Show annotated file Show diff for this revision Revisions of this file
System/StaticDefs.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/LTC1298/ltc1298.cpp	Thu Feb 15 23:08:38 2018 +0000
+++ b/LTC1298/ltc1298.cpp	Mon Jun 04 15:20:21 2018 +0000
@@ -9,15 +9,21 @@
 
 void SpiADC::initialize() {
     //set up the spi bus and frequency
-    _spi.format(13,0);
+    _spi.format(12,0);
     _spi.frequency(1000000);
-    
+ 
     //chip select high puts ltc1298 in standby
     cs = 1;
     
     //zero the initial ch0 and ch1 oversampled readings    
     ch0_filt = 0;
     ch1_filt = 0;
+    ch2_filt = 0;
+    ch3_filt = 0;
+    ch4_filt = 0;
+    ch5_filt = 0;
+    ch6_filt = 0;
+    ch7_filt = 0;
 
     //led on to say hello
     adcLed = 1;
@@ -25,7 +31,7 @@
 
 // start an interupt driven trigger of the external ADC
 void SpiADC::start() {
-    interval.attach_us(this, &SpiADC::update, 100);  //this should be a 10 kHz sample rate
+    interval.attach_us(this, &SpiADC::update, 10000);  //this should be a 100 Hz sample rate
 }
 
 // stop the interupt driven trigger
@@ -39,7 +45,7 @@
 
     //chip select low starts data conversion
     cs = 0;
-    
+       
     //the next thing is the input data word
     //it is 4 bits and looks like this
     // | start | single/diff | odd/sign | MSB first/LSB first |
@@ -47,7 +53,7 @@
     // if you want single ended on channel 1 MSB first then input 0xF
 
     // get channel 0
-    unsigned int byte = _spi.write(0xD);
+    unsigned int byte = _spi.write((0x18)<<2);
     //send a dummy byte to receive the data
     unsigned int byte1 = _spi.write(0x0);
     ch0_raw = byte1;
@@ -56,7 +62,7 @@
     cs = 1;
     cs = 0;
 
-    byte = _spi.write(0xF);
+    byte = _spi.write((0x19)<<2);
     //send a dummy byte to receive the data
     byte1 = _spi.write(0x0);
     ch1_raw = byte1;
@@ -64,6 +70,71 @@
 
     //switch chip select back to high
     cs = 1;
+    cs = 0;
+
+    byte = _spi.write((0x1A)<<2);
+    //send a dummy byte to receive the data
+    byte1 = _spi.write(0x0);
+    ch2_raw = byte1;
+    ch2_filt += (ch2_raw - ch2_filt)/CH2OVERSAMPLE;
+
+    //switch chip select back to high
+    cs = 1;
+    cs = 0;
+
+    byte = _spi.write((0x1B)<<2);
+    //send a dummy byte to receive the data
+    byte1 = _spi.write(0x0);
+    ch3_raw = byte1;
+    ch3_filt += (ch3_raw - ch3_filt)/CH3OVERSAMPLE;
+
+    //switch chip select back to high
+    cs = 1;
+
+    cs = 0;
+
+    byte = _spi.write((0x1C)<<2);
+    //send a dummy byte to receive the data
+    byte1 = _spi.write(0x0);
+    ch4_raw = byte1;
+    ch4_filt += (ch4_raw - ch4_filt)/CH4OVERSAMPLE;
+
+    //switch chip select back to high
+    cs = 1;
+
+    cs = 0;
+
+    byte = _spi.write((0x1D)<<2);
+    //send a dummy byte to receive the data
+    byte1 = _spi.write(0x0);
+    ch5_raw = byte1;
+    ch5_filt += (ch5_raw - ch5_filt)/CH5OVERSAMPLE;
+
+    //switch chip select back to high
+    cs = 1;
+    
+    cs = 0;
+
+    byte = _spi.write((0x1E)<<2);
+    //send a dummy byte to receive the data
+    byte1 = _spi.write(0x0);
+    ch6_raw = byte1;
+    ch6_filt += (ch6_raw - ch6_filt)/CH6OVERSAMPLE;
+
+    //switch chip select back to high
+    cs = 1;
+    
+    cs = 0;
+
+    byte = _spi.write((0x1F)<<2);
+    //send a dummy byte to receive the data
+    byte1 = _spi.write(0x0);
+    ch7_raw = byte1;
+    ch7_filt += (ch7_raw - ch7_filt)/CH7OVERSAMPLE;
+
+    //switch chip select back to high
+    cs = 1;
+
     return ;
 }
 
@@ -73,4 +144,28 @@
 
 int SpiADC::readCh1() {
     return ch1_filt;
+}
+
+int SpiADC::readCh2() {
+    return ch2_filt;
+}
+
+int SpiADC::readCh3() {
+    return ch3_filt;
+}
+
+int SpiADC::readCh4() {
+    return ch4_filt;
+}
+
+int SpiADC::readCh5() {
+    return ch5_filt;
+}
+
+int SpiADC::readCh6() {
+    return ch6_filt;
+}
+
+int SpiADC::readCh7() {
+    return ch7_filt;
 }
\ No newline at end of file
--- a/LTC1298/ltc1298.hpp	Thu Feb 15 23:08:38 2018 +0000
+++ b/LTC1298/ltc1298.hpp	Mon Jun 04 15:20:21 2018 +0000
@@ -2,8 +2,14 @@
 #define MBED_LTC1298_H
 #include "mbed.h"
 
-#define CH0OVERSAMPLE 8
-#define CH1OVERSAMPLE 8
+#define CH0OVERSAMPLE 10
+#define CH1OVERSAMPLE 10
+#define CH2OVERSAMPLE 10
+#define CH3OVERSAMPLE 10
+#define CH4OVERSAMPLE 10
+#define CH5OVERSAMPLE 10
+#define CH6OVERSAMPLE 10
+#define CH7OVERSAMPLE 10
 
 class SpiADC{
 public:
@@ -15,6 +21,12 @@
     
     int readCh0();
     int readCh1();
+    int readCh2();
+    int readCh3();
+    int readCh4();
+    int readCh5();
+    int readCh6();
+    int readCh7();
     
 protected:
     SPI _spi;
@@ -24,9 +36,21 @@
 
     int ch0_raw;
     int ch1_raw;
+    int ch2_raw;
+    int ch3_raw;
+    int ch4_raw;
+    int ch5_raw;
+    int ch6_raw;
+    int ch7_raw;
     
     int ch0_filt;
     int ch1_filt;
+    int ch2_filt;
+    int ch3_filt;
+    int ch4_filt;
+    int ch5_filt;
+    int ch6_filt;
+    int ch7_filt;
 };
 
 
--- a/SDFileSystem.lib	Thu Feb 15 23:08:38 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/tnhnrl/code/SDFileSystem/#9e2a6ea13645
--- a/StateMachine/StateMachine.cpp	Thu Feb 15 23:08:38 2018 +0000
+++ b/StateMachine/StateMachine.cpp	Mon Jun 04 15:20:21 2018 +0000
@@ -1142,6 +1142,25 @@
         else if (userInput == 'C' or userInput == 'c') {
             
             pc().printf("\n\n\rCURRENT STATUS AND PARAMETERS:\n\r");
+            
+            // Testing out ADC
+            float vref = 5.6;
+            float vmeasured = 0;
+            unsigned int raw = adc().readCh5();
+            vmeasured = ((float)raw)/4095.0*vref;
+            pc().printf("raw BCE pos: %d \r\n",adc().readCh0());
+            pc().printf("raw BMM pos: %d \r\n",adc().readCh1());
+            pc().printf("raw BCE current sense: %d \r\n",adc().readCh2());
+            pc().printf("raw BMM current sense: %d \r\n",adc().readCh3());
+            pc().printf("raw depth pressure: %d \r\n",adc().readCh4());
+            pc().printf("raw vessel pressure: %d \r\n",adc().readCh5());
+            pc().printf("raw battery voltage: %d \r\n",adc().readCh6());
+            pc().printf("raw board current: %d \r\n",adc().readCh7());
+            pc().printf("raw BCE limit switch: %d \r\n",bce().getSwitch());
+            pc().printf("raw BMM limit switch: %d \r\n",batt().getSwitch());
+            pc().printf("raw vessel pressure: %f %d \r\n",vmeasured,raw);
+            // End of ADC Test
+            
             pc().printf("depth: %3.1f ft\r\n",depthLoop().getPosition());
             pc().printf("pitch: %3.1f deg\r\n",imu().getPitch());
             pc().printf("bce().getPosition_mm(): %3.1f\r\n",bce().getPosition_mm());
--- a/System/StaticDefs.cpp	Thu Feb 15 23:08:38 2018 +0000
+++ b/System/StaticDefs.cpp	Mon Jun 04 15:20:21 2018 +0000
@@ -14,8 +14,8 @@
 }
     
 MODSERIAL & pc() {
-    //static MODSERIAL pc(USBTX, USBRX);
-    static MODSERIAL pc(p9, p10);        //XBee tx, rx pins
+    static MODSERIAL pc(USBTX, USBRX);
+    //static MODSERIAL pc(p9, p10);        //XBee tx, rx pins
     return pc;
 }
 
@@ -26,21 +26,24 @@
 
 
 //FIX THIS TO USE SPI data logger...
-
+/*
 MODSERIAL & datalogger() {
     static MODSERIAL datalogger(p28, p27);  //Data Logger tx, rx pins
     return datalogger;
 }
+*/
 
 LocalFileSystem & local() {
     static LocalFileSystem local("local");
     return local;    
 } 
 
+/*************************************************************** Conflict with IMU
 SDFileSystem & sd_card() {
     static SDFileSystem sd_card(p11, p12, p13, p14, "sd");     //SDFileSystem sd_card(MOSI, MISO, SCK, CS, "sd");
     return sd_card;
 }
+*/
 
 SpiADC & adc() {
     static SpiADC adc(p5,p6,p7,p8,LED2);
@@ -48,12 +51,12 @@
 }
 
 LinearActuator & bce() {
-    static LinearActuator bce(0.01, p25, p29, p30, p18, 0); //interval , pwm, dir, reset, limit switch, adc channel
+    static LinearActuator bce(0.01, p22, p15, p16, p17, 0); //interval , pwm, dir, reset, limit switch, adc channel
     return bce;
 }
 
 LinearActuator & batt() {
-    static LinearActuator batt(0.01, p23, p21, p22, p17, 1); //interval , pwm, dir, reset, limit switchm, adc channel
+    static LinearActuator batt(0.01, p21, P0_29, P0_30, p18, 1); //interval , pwm, dir, reset, limit switchm, adc channel
     return batt;       
 }
 
@@ -62,14 +65,14 @@
     return servo;
 }
     
-
+//*************Need to adjust class**************
 omegaPX209 & depth() {
     static omegaPX209 depth(p19);   // pin
     return depth;
 }
 
 IMU & imu() {
-    static IMU imu(p28, p27);       // tx, rx pin
+    static IMU imu(p13, p14);       // tx, rx pin
     return imu;    
 }
 
--- a/System/StaticDefs.hpp	Thu Feb 15 23:08:38 2018 +0000
+++ b/System/StaticDefs.hpp	Mon Jun 04 15:20:21 2018 +0000
@@ -14,7 +14,7 @@
 #include "ConfigFileIO.hpp"
 #include "SequenceController.hpp"
 #include "MbedLogger.hpp"
-#include "SDFileSystem.h"
+// #include "SDFileSystem.h"
 #include "ServoDriver.hpp"
 
 //Declare static global variables using 'construct on use' idiom to ensure they are always constructed correctly
@@ -43,7 +43,7 @@
 
 MbedLogger                  &   mbedLogger();       //internal memory log files
 
-SDFileSystem                &   sd_card();          //SD card file system
+// SDFileSystem                &   sd_card();          //SD card file system
 MbedLogger                  &   sdLogger();         //sd log files
 
 ConfigFileIO                &   configFileIO();
--- a/main.cpp	Thu Feb 15 23:08:38 2018 +0000
+++ b/main.cpp	Mon Jun 04 15:20:21 2018 +0000
@@ -49,16 +49,17 @@
 void setup() {
     pc().baud(57600);
     pc().printf("\n\n\rFSG POOL TEST 2017-02-15 revB\n\n\r");
-    
-    //setup data logger baud rate and write the start of the program (every time you reset)
+
+/*    //setup data logger baud rate and write the start of the program (every time you reset)
     datalogger().baud(57600);
     datalogger().printf("SYSTEM, RESET\n");
- 
+*/
+      
     // start up the system timer
     systemTime().start();
  
     // set up and start the adc. This runs on a fixed interval and is interrupt driven
-    adc().initialize();
+    adc().initialize();  
     adc().start();
     
     // set up and start the imu. This polls in the background
@@ -73,7 +74,7 @@
     local();
     
     // construct the SD card file system
-    sd_card();
+//    sd_card();
  
     // load config data from files
     configFileIO().load_BCE_config();      // load the buoyancy engine parameters from the file "bce.txt"
@@ -115,19 +116,20 @@
     
     // setup the data logger rate
     log_loop_rate_ticker.attach(&log_loop_trigger, 1.0); // fires the ticker at 1 Hz rate (every second)
-    
+ 
     //set time of logger (to current or close-to-current time)
-    mbedLogger().setLogTime();
-    sdLogger().setLogTime();
+    mbedLogger().setLogTime();   
+//    sdLogger().setLogTime();
     
     //create log files if not present on file system
     mbedLogger().initializeLogFile();
-    sdLogger().initializeLogFile();
+//    sdLogger().initializeLogFile();
+
 } 
  
 int main() {
     setup();
-    
+
     while(1) {
         static int current_state = 0;
         
@@ -181,4 +183,5 @@
             log_loop = false;   // wait until the loop rate timer fires again
         }   //END OF LOG LOOP
     }
+
 }
\ No newline at end of file