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

Thread: pinMode (PIN, OUTPUT_OPENDRAIN)

  1. #1
    Junior Member
    Join Date
    Oct 2016
    Posts
    11

    pinMode (PIN, OUTPUT_OPENDRAIN)

    I have to drive with a Teensy 3.2 six dc-motors. The motor controllers need 5V TTL signals. To avoid additional level shifters, I would simply use PullUp resistors, connected to 5V.
    Question 1: for which pins does "pinMode (PINNUMBER, OUTPUT_OPENDRAIN)" work?
    Question 2: does OUTPUT_OPENDRAIN work together with PWM ( "analogWrite (PWM_Pin, pwm)")?

    Greetings from Austria

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,485
    Quote Originally Posted by josto View Post
    Question 1: for which pins does "pinMode (PINNUMBER, OUTPUT_OPENDRAIN)" work?
    All the digital pins support OUTPUT_OPENDRAIN mode.

    However, this mode has a small quirk (which really isn't documented anywhere.....) Teensy 3.2 is NOT 5 volt tolerant in this mode. The chip activates a clamping diode to 3.3V when you put it into this mode. Normally this isn't an issue, because a physical pullup resistor to 5V will just inject a (hopefully safe) current into the pin that flows through the diode to 3.3V power.

    But it does mean you can't use OUTPUT_OPENDRAIN to get a 5V signal. You'll get approx 3.9 volts for logic high. Of course, there's also the slow rise time caveat that always applies for open drain/collector circuits.

    If you want 5V output, you CAN get it by switching from output mode to input mode, or to disabled mode. As an input or disabled, the pin will allow an external pullup resistor to bring the voltage all the way up to 5V.

    Question 2: does OUTPUT_OPENDRAIN work together with PWM ( "analogWrite (PWM_Pin, pwm)")?
    No. The pin becomes fully controlled by the timer in PWM mode. The GPIO registers have no effect on the pin when it's controlled by non-GPIO peripherals.

  3. #3
    Junior Member
    Join Date
    Oct 2016
    Posts
    11
    Thanks for the explanations!

Posting Permissions

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