AP_AnalogSource_Arduino: fix to allow analog port to be read to be specified as a "channel" (i.e. A0)
Also fixed example range finder sketch to work with interrupt enabled AP_AnalogSource_Arduino class
This commit is contained in:
parent
1feaaa4655
commit
4dd4c95d5c
@ -27,8 +27,7 @@ static volatile struct {
|
|||||||
// each conversion takes about 125 microseconds
|
// each conversion takes about 125 microseconds
|
||||||
static void adc_timer(uint32_t t)
|
static void adc_timer(uint32_t t)
|
||||||
{
|
{
|
||||||
if (bit_is_set(ADCSRA, ADSC) ||
|
if (bit_is_set(ADCSRA, ADSC) || num_pins_watched == 0) {
|
||||||
num_pins_watched == 0) {
|
|
||||||
// conversion is still running. This should be
|
// conversion is still running. This should be
|
||||||
// very rare, as we are called at 1kHz
|
// very rare, as we are called at 1kHz
|
||||||
return;
|
return;
|
||||||
@ -142,6 +141,18 @@ void AP_AnalogSource_Arduino::assign_pin_index(uint8_t pin)
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allow pin to be a channel (i.e. "A0") or an actual pin
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
|
if (pin >= 54) pin -= 54;
|
||||||
|
#elif defined(__AVR_ATmega32U4__)
|
||||||
|
if (pin >= 18) pin -= 18;
|
||||||
|
#elif defined(__AVR_ATmega1284__)
|
||||||
|
if (pin >= 24) pin -= 24;
|
||||||
|
#else
|
||||||
|
if (pin >= 14) pin -= 14;
|
||||||
|
#endif
|
||||||
|
|
||||||
_pin_index = num_pins_watched;
|
_pin_index = num_pins_watched;
|
||||||
pins[_pin_index].pin = pin;
|
pins[_pin_index].pin = pin;
|
||||||
num_pins_watched++;
|
num_pins_watched++;
|
||||||
|
@ -33,8 +33,9 @@ FastSerialPort0(Serial); // FTDI/console
|
|||||||
// declare global instances
|
// declare global instances
|
||||||
Arduino_Mega_ISR_Registry isr_registry;
|
Arduino_Mega_ISR_Registry isr_registry;
|
||||||
ModeFilterInt16_Size5 mode_filter(2);
|
ModeFilterInt16_Size5 mode_filter(2);
|
||||||
|
AP_TimerProcess timer_scheduler;
|
||||||
|
|
||||||
#ifdef USE_ADC_ADS7844
|
#ifdef USE_ADC_ADS7844
|
||||||
AP_TimerProcess adc_scheduler;
|
|
||||||
AP_ADC_ADS7844 adc;
|
AP_ADC_ADS7844 adc;
|
||||||
AP_AnalogSource_ADC adc_source(&adc, AP_RANGEFINDER_PITOT_TYPE_ADC_CHANNEL, 0.25); // use Pitot tube
|
AP_AnalogSource_ADC adc_source(&adc, AP_RANGEFINDER_PITOT_TYPE_ADC_CHANNEL, 0.25); // use Pitot tube
|
||||||
#else
|
#else
|
||||||
@ -51,14 +52,18 @@ void setup()
|
|||||||
Serial.println("Range Finder Test v1.1");
|
Serial.println("Range Finder Test v1.1");
|
||||||
Serial.print("Sonar Type: ");
|
Serial.print("Sonar Type: ");
|
||||||
Serial.println(SONAR_TYPE);
|
Serial.println(SONAR_TYPE);
|
||||||
|
|
||||||
#ifdef USE_ADC_ADS7844
|
|
||||||
isr_registry.init();
|
isr_registry.init();
|
||||||
adc_scheduler.init(&isr_registry);
|
timer_scheduler.init(&isr_registry);
|
||||||
|
|
||||||
|
#ifdef USE_ADC_ADS7844
|
||||||
adc.filter_result = true;
|
adc.filter_result = true;
|
||||||
adc.Init(&adc_scheduler); // APM ADC initialization
|
adc.Init(&timer_scheduler); // APM ADC initialization
|
||||||
aRF.calculate_scaler(SONAR_TYPE,3.3); // setup scaling for sonar
|
aRF.calculate_scaler(SONAR_TYPE,3.3); // setup scaling for sonar
|
||||||
#else
|
#else
|
||||||
|
// initialise the analog port reader
|
||||||
|
AP_AnalogSource_Arduino::init_timer(&timer_scheduler);
|
||||||
|
|
||||||
aRF.calculate_scaler(SONAR_TYPE,5.0); // setup scaling for sonar
|
aRF.calculate_scaler(SONAR_TYPE,5.0); // setup scaling for sonar
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user