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
LTC1298/ltc1298.cpp
- Committer:
- mkelly10
- Date:
- 2017-10-20
- Revision:
- 9:d5fcdcb3c89d
- Child:
- 10:085ab7328054
File content as of revision 9:d5fcdcb3c89d:
#include "ltc1298.hpp" SpiADC::SpiADC(): _spi(p5,p6,p7),adcLed(LED2),cs(p8) //maybe this should configurable on construction { } void SpiADC::initialize() { //set up the spi bus and frequency _spi.format(13,0); _spi.frequency(1000000); //chip select high puts ltc1298 in standby adcLed = 1; ch0_filt = 0; ch1_filt = 0; cs = 1; } //This starts 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 } //This stops it void SpiADC::stop() { interval.detach(); } void SpiADC::update() { //flash the LED adcLed = !adcLed; //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 | // if you want single ended on channel 0 MSB first then input 0xD // if you want single ended on channel 1 MSB first then input 0xF // get channel 0 unsigned int byte = _spi.write(0xD); //send a dummy byte to receive the data unsigned int byte1 = _spi.write(0x0); ch0_raw = byte1; ch0_filt += (ch0_raw - ch0_filt)/CH0OVERSAMPLE; cs = 1; cs = 0; byte = _spi.write(0xF); //send a dummy byte to receive the data byte1 = _spi.write(0x0); ch1_raw = byte1; ch1_filt += (ch1_raw - ch1_filt)/CH1OVERSAMPLE; //switch chip select back to high cs = 1; return ; } int SpiADC::readCh0() { return ch0_filt; } int SpiADC::readCh1() { return ch1_filt; }