Skip to content
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

ADC Bias with SDIO on Teensy 3.6 #3

Open
kcareyMT opened this issue Apr 30, 2018 · 2 comments
Open

ADC Bias with SDIO on Teensy 3.6 #3

kcareyMT opened this issue Apr 30, 2018 · 2 comments

Comments

@kcareyMT
Copy link

I have been observing a seemingly random bias in the ADC readings on a Teensy 3.6 when using the SDIO interface. Switching to the SPI interface solves the issue.

Setup:

  • Pin A16 connected to Analog ground
  • uSD card inserted

Code:
Attached, but the overview is that ADC readings are taken on an InterruptTimer and the raw value is printed out over Serial (for validation purposes). Depending on the configuration, a write to the SD card takes place once before the IntervalTimer is started and appears to instigate the issue. Pressing "s" starts logging with SD writing enabled, while pressing "n" starts logging with SD writing not enabled. Pressing any button while logging will stop logging.

Issue:
When logging is configured to write to the SD card with SDIO, the ADC results may consistently be biased by ~110 or ~230 ADC counts. The expected value is 0 since the pin is connected to AGND. Different logging sessions (stop/start logging) result in different bias values (including 0 bias), and the bias remains until logging is stopped. The code is set up to work with any pin connected to ADC1, but I have seen the same issue with ADC0.

Environment:
PlatformIO, version 3.5.3b2
teensy platform, version 3.1.0
framework-arduinoteensy, version 1.141.0

Workaround:
Use SPI interface instead of SDIO, although SPI is less than half the speed of SDIO.

Sample output with SD card enabled:

  Press "s" to log with the SD card enabled or "n" to log with the SD card disabled
  Starting Logging
  Timers started
  108
  113
  115
  108
  111
  105
  108
  106
  112
  111
  102
  data logging stopped
  Press "s" to log with the SD card enabled or "n" to log with the SD card disabled
  Starting Logging
  Timers started
  113
  105
  105
  106
  109
  110
  110
  109
  108
  107
  110
  105
  data logging stopped
  Press "s" to log with the SD card enabled or "n" to log with the SD card disabled
  Starting Logging
  Timers started
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  data logging stopped

I have also noticed the issue on the FRDM-K66F board from NXP, which uses (almost) the same chip as the Teensy. This leads me to believe that the issue either stems from the chip (I have reached out to NXP to see if this is the case) or has something to do with the SdFs library (though I have scoured the code and haven't seen any indications that this is the case, but I could easily have missed something). I have modified both boards (FRDM-K66F and Teensy 3.6) with a precision reference voltage, and scope readings look clean.

adc_issue.zip

@greiman
Copy link
Owner

greiman commented May 1, 2018

I only access the SDHC controller for SDIO mode. That should not cause the problem you are seeing with the ADCs.

The only thing I can think of is that some of the SDHC pins can also be used for ADC1 but that would require a problem with the chip's pin multiplexing.

The chip has many errata for the SDHC. I had a real battle getting it work in some modes.

@kcareyMT
Copy link
Author

kcareyMT commented May 1, 2018

My hunch is that this is a chip issue since the problem appears on several pins across both ADC peripherals.

I have reached out to NXP about the issue and am still waiting for their response. I do appreciate the quickness of your reply and the time you have put into this library.

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

No branches or pull requests

2 participants