Skip to content

Re-initialize ADC before every AnalogIn read. #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2017

Conversation

dhalbert
Copy link
Collaborator

microcontroller.cpu.temperature uses different ADC settings, and caused
AnalogIn to give wrong answers. AnalogIn can no longer assume it's the
only user of the ADC.

This fixes #253, at the expense of re-initing the ADC on every read, and also doing double reads to ensure accuracy of the result.

A more sophisticated implementation would remember the last ADC settings and not re-init if they were the same. If we're not going to do that, the AnalogIn code could be simplified to not save the ADC structs on the heap, but simply re-create them each time.

@tannewt -- do you have an opinion? Maybe it's not worth cleaning up because it will all change with ASF4.

`microcontroller.cpu.temperature` uses different ADC settings, and caused
AnalogIn to give wrong answers. AnalogIn can no longer assume it's the
only user of the ADC.
@dhalbert dhalbert requested a review from tannewt September 16, 2017 03:11
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me! Please merge it into the 2.x branch too. We'll need to redo it for ASF4 so lets not put a bunch of time into it.

@dhalbert dhalbert merged commit 75c3be3 into adafruit:master Sep 16, 2017
@dhalbert dhalbert deleted the issue_253_adc_reinit branch September 16, 2017 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2.0.0 - do we undo the mcu temperature ADC changeover?
2 participants