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

Thread: Are Teensy3.2 Pins High Low and Tri State

  1. #1
    Senior Member
    Join Date
    Apr 2014
    Posts
    318

    Are Teensy3.2 Pins High Low and Tri State

    I want to connect a 100k resistor to a device but I want to use Teensy3.2 to switch the other end of it from GND, to open circuit, to 5 volt.
    I was thinking to simply connect it to a pin and control as below.........wondering if that would work or be reliable.????

    pinMode( pinNumber, OUTPUT ); // set as output
    digitalWrite( pinNumber, LOW ); // set pin low

    // code here to do something when pin is low

    pinMode( pinNumber, INPUT ); // now set tri-stated.?.....Is this same as opencircuit or at least very high impedance well in access of 100k..??

    //code here to do something when pin is open circuit

    pinMode( pinNumber, OUTPUT ); // and set back to output
    digitalWrite( pinNumber, HIGH ); // set pin high

    //code here to do something when pin is high

    .................................................. .............................................

    Got this below from a search on the forum..................

    That's why newer chips like the ARM chips from Freescale have a special disable mode, which is the default.

    On AVR, the pins with ADC inputs also have a special disable mode. However, it's not the default. When you use analogRead(), the pin you're reading is placed in that mode (this is a Teensyduino feature - Arduino's version of analogRead does not do this) to prevent that pin you're using for analog voltages from consuming extra power. On Teensy 2.0, only the pins with analog input have this digital input disable feature
    .................................................. ...............................................

    ....................What command is used to set to disable mode ??...

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    PS I should have said I will not be doing anything else with this pin, just holding it either High, Low or Tri-state for a period of time while the code in between runs to do other functions

  3. #3
    Senior Member Ben's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    401
    In the datasheet in section 5.2.3 (Page 13) the maximum leakage current is 1ľA over the full temperature range and 0.025ľA at room temp. Both measured at Vdd=3.6V.

    Ohms law yields R = V/I = 3.6/(1E-6) = 3.6 Megaohms for 1ľA and a whopping 3.6/25E-9 = 144 MOhms for 0.025ľA.

    AFAIK using pinMode( pinNumber, INPUT ); will be sufficient for tri-stating the pin to HiZ.

    Remember that immediately after putting the pin to HiZ mode the pin capacitance will charge through your attached 100k resistor, so the system will need a certain settling time. Pin capacitance is 5pF typical plus line capacitance on the PCB plus whatever wires you attach.

    -Ben

  4. #4
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    Most often, unused pins are programmed early in startup as GPIO Input, no pull-up. But some vendors recommend "analog" input. The internal pull-ups, if enabled, are on the order or 40K.

  5. #5
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    Thanks for replies. I have tried it out as per my example code outlined and it seems to work OK. the state of my other device changes to correspond with the pinmode settings

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,591
    Quote Originally Posted by Teenfor3 View Post
    What command is used to set to disable mode ??...
    You currently can not access pin disable from pinMode() or any other Arduino function. To do this, you have to write directly to the pin's config register.

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Quote Originally Posted by Teenfor3 View Post
    What command is used to set to disable mode ??...

    Try this:

    Code:
    void pinDisable(const uint8_t pin) {
      volatile uint32_t *config;  
      if (pin >= CORE_NUM_TOTAL_PINS) return;
      config = portConfigRegister(pin);
      *config = 0;
    }
    Last edited by Frank B; 06-12-2016 at 01:31 PM.

Posting Permissions

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