Skip to content

Re-initialize ADC before every AnalogIn read.#255

Merged
dhalbert merged 1 commit into
adafruit:masterfrom
dhalbert:issue_253_adc_reinit
Sep 16, 2017
Merged

Re-initialize ADC before every AnalogIn read.#255
dhalbert merged 1 commit into
adafruit:masterfrom
dhalbert:issue_253_adc_reinit

Conversation

@dhalbert
Copy link
Copy Markdown
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
Copy Markdown
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