Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 14 of 14

Thread: Teensy 4.0 ADC keeper issue

  1. #1
    Senior Member
    Join Date
    Feb 2019
    Posts
    107

    Teensy 4.0 ADC keeper issue

    I used the program given below to read an analog voltage on pin 14/A0. I observed strange values and it took me some hours to learn that the keeper on this pin is enabled and leads to a current into/out of this pin changing the voltage on the pin. There was a keeper issue in the beta-thread but it it is unclear for me how this is handeled. I think activating the keeper is not a good idea since it makes the ADC-input "low ohmic" and may lead to strange results if the source has not a low inner resistance. Is there a specific reason to have the keeper enabled?
    Code:
    void setup() {
      Serial.begin(115200);  
      while(!Serial) ;
      Serial.println("start teensy40doADCtest1...") ;
      Serial.println("end setup...") ;  
      }
    
    volatile int val ;
    
    void loop() {
      val = analogRead(0) ;
      Serial.printf("ADC= %6d \n",val) ;
      delay(500) ;
      }

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546
    You're right, it should be disabled for pins which are used for analog (But should be enabled for the digital case(?) ) . Its clearly stated in the documentation, and we found this ssue during the beta-phase. Don't know why this got not fixed. I assumed, it was.
    Can you fix that and do a pull request?
    Last edited by Frank B; 03-12-2020 at 03:40 PM.

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546
    I'm not at my PC at the moment: Does pinMode(x, INPUT_DISABLE) disable the keeper?
    Last edited by Frank B; 03-12-2020 at 02:10 PM.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546
    Quote Originally Posted by Frank B View Post
    I'm not at my PC at the moment: Does pinMode(x, INPUT_DISABLE) disable the keeper?
    As I understand it, it should be enabled if the pin is an output and gets disabled, and be disabled otherwise.
    See AN 5078.

    Is this is correct?
    I think it may be better to disable it completely for all pins. Wouldn't that be more compatible to T3.x?

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546

  6. #6
    Senior Member
    Join Date
    Feb 2019
    Posts
    107
    In my case I should have used:
    pinMode(PIN_A0, INPUT);
    This disables the keeper. Nevertheless I think it would be good to disable keepers at startup.

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,341
    It is sort of an interesting question.

    Should the startup code run through all of the GPIO pins/pads and set them to a similar state as maybe T3.x? or should they be left at the Reset state?
    In the case of: IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02

    The defaults include: PKE=1 PUE=0... So Keeper is on...

    Again I wonder what is the right answer. That is analogRead could logically set to INPUT_DISABLE, but I maybe previously did something like INPUT_PULLUP or INPUT_PULLDOWN...
    Which maybe works?

  8. #8
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546
    As I understand it from the AppNote, the Keeper still works with a disabled Pin. So a simple DISABLE does not help.

    I think we can measure that.
    Will do.

  9. #9
    Senior Member
    Join Date
    Feb 2019
    Posts
    107
    With the line:
    Code:
    IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02 &= ~ (1<<12) ; // disable keeper
    I could switch off the keeper at a0. The input current was so small that I couldn't measure it in this situation.

  10. #10
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546
    Confusion you're right - I was speaking of pin disable.

  11. #11
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546
    Quote Originally Posted by Frank B View Post
    Confusion you're right - I was speaking of pin disable.
    oops, I've looked now at the code. ok INPUT_DISABLE disables the keeper.

    I've added a 470k Voltage divider to a pin.

    1) The pin has 0.6V default after power up - when we do nothing - which is questionable
    2) It has 1.6V after pinMode(x, INPUT_DISABLE) - which is correct

    The only way to fix this, is indeed a loop over alls pins which disables the keeper.
    The Teensy 3. does not do that, so the T4 is not compatible in this regard, and it should be fixed.

  12. #12
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546
    My PR is here:
    https://github.com/PaulStoffregen/cores/pull/451

    So, for me it's solved. If you know a better solution please add a comment

  13. #13
    I am working on a project for school. We plan to use the ADC to read analog audio signals (3 of them). How do I disable the keeper on these pins? I have searched the net and can't really find anything. Also, what is a keeper?

  14. #14
    Senior Member
    Join Date
    Feb 2019
    Posts
    107
    A keeper can be used to preserve the pin output-state when the pin driver is switched off. Further info can be obtained by the app-note:

    https://www.google.com/url?sa=t&sour...x-7bziVYCwG_ke

    In order to disable the keeper you have to clear the pke bit of the corresponding pin. For the Teensy 4.0 pin 14=A0 it is
    IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02 &= ~ (1<<12) ; // disable keeper
    AD_B1_02 is the internal name of the pin14=A0, bit 12 is the pke bit in the IOMUXC_SW_PAD_CTL_PAD_GPIO register (see datasheet).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •