diff --git a/libraries/AP_ADC/AP_ADC.h b/libraries/AP_ADC/AP_ADC.h index 8bebead3fc..fd98ed30a5 100644 --- a/libraries/AP_ADC/AP_ADC.h +++ b/libraries/AP_ADC/AP_ADC.h @@ -37,9 +37,14 @@ class AP_ADC The function returns the amount of time (in microseconds) since the last call to Ch6(). + + NOTE: You must enable the channels using enable_channel() + before use */ virtual uint32_t Ch6(const uint8_t *channel_numbers, uint16_t *result) = 0; + virtual void enable_channel(const uint8_t ch) = 0; + private: }; diff --git a/libraries/AP_ADC/AP_ADC_ADS7844.cpp b/libraries/AP_ADC/AP_ADC_ADS7844.cpp index 5dcce0303b..b43aac59b9 100644 --- a/libraries/AP_ADC/AP_ADC_ADS7844.cpp +++ b/libraries/AP_ADC/AP_ADC_ADS7844.cpp @@ -100,6 +100,7 @@ void AP_ADC_ADS7844::read(void) return; } + // build a sequence of commands to use to fetch the channels for (ch = 0; ch < 8; ch++) { if (enable_mask & (1< #include #include -#include // ArduPilot Mega ADC Library - +#include // ArduPilot Mega ADC Library + FastSerialPort0(Serial); // FTDI/console Arduino_Mega_ISR_Registry isr_registry; AP_TimerAperiodicProcess adc_scheduler; - + unsigned long timer; -AP_ADC_ADS7844 adc; - -void setup() +AP_ADC_ADS7844 adc; + +static const uint8_t channel_map[6] = { 1, 2, 0, 4, 5, 6}; + +void setup() { Serial.begin(115200, 128, 128); Serial.println("ArduPilot Mega ADC library test"); @@ -30,9 +32,12 @@ void setup() adc.Init(&adc_scheduler); // APM ADC initialization delay(1000); timer = millis(); + + for (uint8_t ch=0; ch<6; ch++) { + adc.enable_channel(channel_map[ch]); + } } -static const uint8_t channel_map[6] = { 1, 2, 0, 4, 5, 6}; float v; uint32_t last_usec = 0; diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_Oilpan.cpp b/libraries/AP_InertialSensor/AP_InertialSensor_Oilpan.cpp index 28f956b08a..3b6d7bfd0c 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_Oilpan.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor_Oilpan.cpp @@ -50,6 +50,11 @@ AP_InertialSensor_Oilpan::AP_InertialSensor_Oilpan( AP_ADC * adc ) : void AP_InertialSensor_Oilpan::init( AP_PeriodicProcess * scheduler) { _adc->Init(scheduler); + + // tell the ADC driver that we will be needed some channels + for (uint8_t ch=0; ch<6; ch++) { + _adc->enable_channel(_sensors[ch]); + } } bool AP_InertialSensor_Oilpan::update()