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

Thread: How to pull down an input pin on the Teensy 4.0

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    10

    How to pull down an input pin on the Teensy 4.0

    Is there any way to pull down an input pin on the Teensy 4.0 other that manually connecting it to GND via a resistor?

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,443
    input or output?

  3. #3
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    329
    Haven't tested it, but supposedly:

    pinMode(pin, INPUT_PULLDOWN);

  4. #4
    Junior Member
    Join Date
    Oct 2019
    Posts
    10
    It seems that the Pins are connected to GND via a 100 kOhm resistor by default. It is possible to disconnect them though using

    Code:
    pinMode(pin, INPUT_PULLUP);
    See also https://www.pjrc.com/teensy/td_digital.html.

    If a pin was set as an output and you want to change it to an input, it will automatically be pulled down via a 100 kOhm resistor. The two commands

    Code:
    pinMode(pin, INPUT);
    and

    Code:
    pinMode(pin, INPUT_PULLDOWN);
    have the same effect.

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,938
    Note: the web page : https://www.pjrc.com/teensy/td_digital.html as well as several others is more specific to the Teensy 1 and 2 (AVR) based setup.

    For information on some of this stuff you should look at the actual processor reference pdfs which you can download from the PJRC site.

    Example look at section 11.4.2.2 for T4...

    Note input pinMode(pin, INPUT) is NOT the same as pinMode(pin, INPUT_PULLDOWN);
    You can confirm this by looking at the sources (digital.c) under teensy4...

    Code:
    void pinMode(uint8_t pin, uint8_t mode)
    {
    	const struct digital_pin_bitband_and_config_table_struct *p;
    
    	if (pin >= CORE_NUM_DIGITAL) return;
    	p = digital_pin_to_info_PGM + pin;
    	if (mode == OUTPUT || mode == OUTPUT_OPENDRAIN) {
    		*(p->reg + 1) |= p->mask; // TODO: atomic
    		if (mode == OUTPUT) {
    			*(p->pad) = IOMUXC_PAD_DSE(7);
    		} else { // OUTPUT_OPENDRAIN
    			*(p->pad) = IOMUXC_PAD_DSE(7) | IOMUXC_PAD_ODE;
    		}
    	} else {
    		*(p->reg + 1) &= ~(p->mask); // TODO: atomic
    		if (mode == INPUT) {
    			*(p->pad) = IOMUXC_PAD_DSE(7);
    		} else if (mode == INPUT_PULLUP) {
    			*(p->pad) = IOMUXC_PAD_DSE(7) | IOMUXC_PAD_PKE | IOMUXC_PAD_PUE | IOMUXC_PAD_PUS(3) | IOMUXC_PAD_HYS;
    		} else if (mode == INPUT_PULLDOWN) {
    			*(p->pad) = IOMUXC_PAD_DSE(7) | IOMUXC_PAD_PKE | IOMUXC_PAD_PUE | IOMUXC_PAD_PUS(0) | IOMUXC_PAD_HYS;
    		} else { // INPUT_DISABLE
    			*(p->pad) = IOMUXC_PAD_DSE(7) | IOMUXC_PAD_HYS;
    		}
    	}
    	*(p->mux) = 5 | 0x10;
    }
    Note the Input and output, set PKE and PUE and PUS (Pull up/down enabled and PUS(0) says 100K Ohm Pull Down and: PUS(3) says 22K Ohm Pull Up

    And notice that INPUT does not set these, so no PULL up or PULL down enabled. i.e. the pin is floating. Now if you have that pin hooked up to something else like an another IO pin of the processor or other processor it will be the value of that other pin...

Posting Permissions

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