Skip to content

Commit

Permalink
analogRead() disable pin input keeper on Teensy 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen committed Jan 16, 2024
1 parent f9b1612 commit c5e7163
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions teensy4/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ int analogRead(uint8_t pin)
if (calibrating) wait_for_cal();
uint8_t ch = pin_to_channel[pin];
if (ch == 255) return 0;
// check if pin has input "keeper"
volatile uint32_t *pad = portControlRegister(pin);
uint32_t padval = *pad;
if ((padval & (IOMUXC_PAD_PUE | IOMUXC_PAD_PKE)) == IOMUXC_PAD_PKE) {
// disable keeper, as it messes up analog with higher source impedance
// but don't touch user's setting if ordinary pullup, which some
// people use together with capacitors or other circuitry
*pad = padval & ~IOMUXC_PAD_PKE;
}
// printf("%d\n", ch);
// if (ch > 15) return 0;
if(!(ch & 0x80)) {
Expand Down

0 comments on commit c5e7163

Please sign in to comment.