most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown

Dependencies:   mbed MODSERIAL FATFileSystem

Revision:
51:c5c40272ecc3
Parent:
10:085ab7328054
Child:
63:6cb0405fc6e6
--- 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