-
-
Notifications
You must be signed in to change notification settings - Fork 7k
High Impedance analogRead #5646
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
Comments
If you're measuring weak signals the hardware solution is to put an OPAMP between the source and the analog input.
A simpler software trick is to do a fake analogRead to switch channel and put a delay before the real analogRead:
This way you don't need to change the core but you can keep all the changes into the sketch. |
Thanks @cmagile. I'll keep that in mind the next time I come across this problem. Unfortunately, that would double my read time and I don't have that much to spare for this project. Y'all can feel free to close. I mostly wanted to doc my work around for the community. Thanks for chiming in with other options. |
Ok, thanks for your insights |
I'm not sure that this is a bug. It's likely by design, but I ran into an issue with
analogRead()
and high impedance input. This affects the Atmel 32U4, but may also affect other Atmel chips, I'm not sure. I mostly want to document the issue & work around here where people may find it.It's known and documented that Atmel recommends an impedance of <10 kOhm input on the ADC circuit.
ATmega16U4/ATmega32U4 datasheet Section 24.7.1.
The issue behaves much like cross talk and manifests itself when rapidly switching between and reading different input channels. The common recommendation is to place a capacitor between the high impedance sensor and the analog input, but this isn't sensible for some applications.
This issue can be solved in software by using a small delay in between switching channels on the ADCMUX and starting the conversion. In fact, it seems that @damellis ran into this way back in 2009. There remains a commented out delay in the wiring_analog.c module.
reference
I imagine the delay was removed for performance reasons, similar to #3064, and should probably remain commented out. Although, some option/hook to allow for a configurable delay between changing channels and reading would be very nice to have, as the amount of delay you need to charge the ADC circuit's capacitor is dependent on the input impedance.
The 32u4 datasheet (Section 24.7.1) also seems to imply that using differential input (#1256) could solve the apparent "crosstalk", but its unclear on how.
Workaround:
It's possible to override the core library's implementation for a specific project by copying the
wiring_analog.c
file from the Arduino installation directory (C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring_analog.c
) into your project and uncommenting the delay. The linker will pick up the modified file from the project. This allows you to change the behavior ofanalogRead()
locally.The text was updated successfully, but these errors were encountered: