Skip to content

Commit

Permalink
drivers/ads1115: Fix consecutive warning "ADS1115 not ready!"
Browse files Browse the repository at this point in the history
ADS1115 is first commanded to start sampling and after 1/4 of the sample
period the single channel sample is read out.

However, when using ScheduleOnInterval this fails if the sample reading
is blocked for long enough.

The resulting _average_ sample rate is still correct (80Hz) but the time
between triggering the new sample on the ADC and reading it out can be
anything. If the call to ADS1115::RunImpl() happens too soon after starting
the new sample, reading it will obviously fail.

Fix this by scheduling the sample reading _after_ the sampling has been
triggered on the ADC. This ensures the sample is ready the next time when
ADS1115::RunImpl() is executed.
  • Loading branch information
pussuw committed Aug 17, 2023
1 parent 2b72281 commit 30e4475
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/drivers/adc/ads1115/ADS1115.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int ADS1115::init()

setChannel(ADS1115::A0); // prepare for the first measure.

ScheduleOnInterval(SAMPLE_INTERVAL / 4, SAMPLE_INTERVAL / 4);
ScheduleDelayed(SAMPLE_INTERVAL / 4);

return PX4_OK;
}
Expand Down
3 changes: 3 additions & 0 deletions src/drivers/adc/ads1115/ads1115_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void ADS1115::RunImpl()
PX4_WARN("ADS1115 not ready!");
}

// Schedule the next sample reading (regardless of isSampleReady())
ScheduleDelayed(SAMPLE_INTERVAL / 4);

perf_end(_cycle_perf);
}

Expand Down

0 comments on commit 30e4475

Please sign in to comment.