pinMode (PIN, OUTPUT_OPENDRAIN)

Status
Not open for further replies.

josto

Member
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
 
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.
 
Status
Not open for further replies.
Back
Top