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

Thread: output open drain

  1. #1

    output open drain


    i am reworking code that i wrote for the maple mini (also arm) to work with the teensy.
    what's the equivalent of pinMode(ledPin,OUTPUT_OPEN_DRAIN); in the teensy world?

    my led driver needs to receive a pwm in open drain mode.


  2. #2
    Junior Member
    Join Date
    Nov 2013
    Clear the port's bit in its PORT register, then output the inverted level to the pin's bit in the DDR register. This way when you write a 0 to the DDR register, the pin becomes an input, and thus high-impedance. When you write a 1 to the DDR register, it becomes an output of a low level.

    Example: PB2
    PORTB &= ~(1<<2); // only needs to be done once
    DDRB  |=   1<<2; // pull line low
    DDRB  &= ~(1<<2); // let line float
    There's probably some Arduino equivalent to this. Maybe just using the normal "output a 0 on this pin", then "make this pin an input" and "make this pin an output" functions.

    If you're using hardware-based PWM, then I don't think the above can work, though I've never used PWM on an AVR before. All I'd know to do in that case is put a diode between the pin and the line, with its cathode towards the AVR. This way it lets a low level pull the line low, but blocks a high level from the AVR.

    EDIT: if you're adding an external component, I guess you might as well just use a mosfet instead of a diode, to do it by the book.
    Last edited by blargg; 12-09-2013 at 11:21 PM.

  3. #3
    ok. thanks for the info.
    still trying to find the "arduino" way of doing it.

Tags for this Thread

Posting Permissions

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