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@10:085ab7328054, 2017-10-23 (annotated)
- Committer:
- danstrider
- Date:
- Mon Oct 23 12:50:53 2017 +0000
- Revision:
- 10:085ab7328054
- Parent:
- 9:d5fcdcb3c89d
- Child:
- 51:c5c40272ecc3
checked out on the hardware
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mkelly10 | 9:d5fcdcb3c89d | 1 | #include "ltc1298.hpp" |
mkelly10 | 9:d5fcdcb3c89d | 2 | |
danstrider | 10:085ab7328054 | 3 | SpiADC::SpiADC(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName led) : |
danstrider | 10:085ab7328054 | 4 | _spi(mosi, miso, sclk), // mosi, miso, sclk |
danstrider | 10:085ab7328054 | 5 | adcLed(led), // status led |
danstrider | 10:085ab7328054 | 6 | cs(csel) // chip select |
mkelly10 | 9:d5fcdcb3c89d | 7 | { |
mkelly10 | 9:d5fcdcb3c89d | 8 | } |
mkelly10 | 9:d5fcdcb3c89d | 9 | |
danstrider | 10:085ab7328054 | 10 | void SpiADC::initialize() { |
mkelly10 | 9:d5fcdcb3c89d | 11 | //set up the spi bus and frequency |
mkelly10 | 9:d5fcdcb3c89d | 12 | _spi.format(13,0); |
mkelly10 | 9:d5fcdcb3c89d | 13 | _spi.frequency(1000000); |
danstrider | 10:085ab7328054 | 14 | |
mkelly10 | 9:d5fcdcb3c89d | 15 | //chip select high puts ltc1298 in standby |
danstrider | 10:085ab7328054 | 16 | cs = 1; |
danstrider | 10:085ab7328054 | 17 | |
danstrider | 10:085ab7328054 | 18 | //zero the initial ch0 and ch1 oversampled readings |
mkelly10 | 9:d5fcdcb3c89d | 19 | ch0_filt = 0; |
mkelly10 | 9:d5fcdcb3c89d | 20 | ch1_filt = 0; |
mkelly10 | 9:d5fcdcb3c89d | 21 | |
danstrider | 10:085ab7328054 | 22 | //led on to say hello |
danstrider | 10:085ab7328054 | 23 | adcLed = 1; |
mkelly10 | 9:d5fcdcb3c89d | 24 | } |
mkelly10 | 9:d5fcdcb3c89d | 25 | |
danstrider | 10:085ab7328054 | 26 | // start an interupt driven trigger of the external ADC |
danstrider | 10:085ab7328054 | 27 | void SpiADC::start() { |
mkelly10 | 9:d5fcdcb3c89d | 28 | interval.attach_us(this, &SpiADC::update, 100); //this should be a 10 kHz sample rate |
mkelly10 | 9:d5fcdcb3c89d | 29 | } |
mkelly10 | 9:d5fcdcb3c89d | 30 | |
danstrider | 10:085ab7328054 | 31 | // stop the interupt driven trigger |
danstrider | 10:085ab7328054 | 32 | void SpiADC::stop() { |
mkelly10 | 9:d5fcdcb3c89d | 33 | interval.detach(); |
mkelly10 | 9:d5fcdcb3c89d | 34 | } |
mkelly10 | 9:d5fcdcb3c89d | 35 | |
danstrider | 10:085ab7328054 | 36 | void SpiADC::update() { |
mkelly10 | 9:d5fcdcb3c89d | 37 | //flash the LED |
mkelly10 | 9:d5fcdcb3c89d | 38 | adcLed = !adcLed; |
mkelly10 | 9:d5fcdcb3c89d | 39 | |
mkelly10 | 9:d5fcdcb3c89d | 40 | //chip select low starts data conversion |
mkelly10 | 9:d5fcdcb3c89d | 41 | cs = 0; |
danstrider | 10:085ab7328054 | 42 | |
mkelly10 | 9:d5fcdcb3c89d | 43 | //the next thing is the input data word |
mkelly10 | 9:d5fcdcb3c89d | 44 | //it is 4 bits and looks like this |
mkelly10 | 9:d5fcdcb3c89d | 45 | // | start | single/diff | odd/sign | MSB first/LSB first | |
mkelly10 | 9:d5fcdcb3c89d | 46 | // if you want single ended on channel 0 MSB first then input 0xD |
mkelly10 | 9:d5fcdcb3c89d | 47 | // if you want single ended on channel 1 MSB first then input 0xF |
mkelly10 | 9:d5fcdcb3c89d | 48 | |
mkelly10 | 9:d5fcdcb3c89d | 49 | // get channel 0 |
mkelly10 | 9:d5fcdcb3c89d | 50 | unsigned int byte = _spi.write(0xD); |
mkelly10 | 9:d5fcdcb3c89d | 51 | //send a dummy byte to receive the data |
mkelly10 | 9:d5fcdcb3c89d | 52 | unsigned int byte1 = _spi.write(0x0); |
mkelly10 | 9:d5fcdcb3c89d | 53 | ch0_raw = byte1; |
mkelly10 | 9:d5fcdcb3c89d | 54 | ch0_filt += (ch0_raw - ch0_filt)/CH0OVERSAMPLE; |
mkelly10 | 9:d5fcdcb3c89d | 55 | |
mkelly10 | 9:d5fcdcb3c89d | 56 | cs = 1; |
mkelly10 | 9:d5fcdcb3c89d | 57 | cs = 0; |
mkelly10 | 9:d5fcdcb3c89d | 58 | |
mkelly10 | 9:d5fcdcb3c89d | 59 | byte = _spi.write(0xF); |
mkelly10 | 9:d5fcdcb3c89d | 60 | //send a dummy byte to receive the data |
mkelly10 | 9:d5fcdcb3c89d | 61 | byte1 = _spi.write(0x0); |
mkelly10 | 9:d5fcdcb3c89d | 62 | ch1_raw = byte1; |
mkelly10 | 9:d5fcdcb3c89d | 63 | ch1_filt += (ch1_raw - ch1_filt)/CH1OVERSAMPLE; |
mkelly10 | 9:d5fcdcb3c89d | 64 | |
mkelly10 | 9:d5fcdcb3c89d | 65 | //switch chip select back to high |
mkelly10 | 9:d5fcdcb3c89d | 66 | cs = 1; |
mkelly10 | 9:d5fcdcb3c89d | 67 | return ; |
mkelly10 | 9:d5fcdcb3c89d | 68 | } |
mkelly10 | 9:d5fcdcb3c89d | 69 | |
danstrider | 10:085ab7328054 | 70 | int SpiADC::readCh0() { |
mkelly10 | 9:d5fcdcb3c89d | 71 | return ch0_filt; |
mkelly10 | 9:d5fcdcb3c89d | 72 | } |
mkelly10 | 9:d5fcdcb3c89d | 73 | |
danstrider | 10:085ab7328054 | 74 | int SpiADC::readCh1() { |
mkelly10 | 9:d5fcdcb3c89d | 75 | return ch1_filt; |
mkelly10 | 9:d5fcdcb3c89d | 76 | } |