1
\$\begingroup\$

Here is an object push button that needs to be hacked:

schematic

simulate this circuit – Schematic created using CircuitLab

Hacked object circuit is not accessible.

From multimeter :

  • button is pulled up with a 10k resistor (measured resistance between 5V power and button input)

I want to hack it with an external 3.3V MCU, tolerant to 5V on its inputs. My goal is to keep actual behavior and :

  • read current button status
  • control button from external CPU

schematic

simulate this circuit

Max sink/source current on D0 is 12mA.

  • on D0 - GPIO as input - button state is read
  • on D0 - button control done by configuring it as output with a low logic level.

Here are sink/source current :

----------------------------------------------------------------
|                         |        PB1 state
----------------------------------------------------------------
|DO Configuration  |Level |   OPEN           |   CLOSED
----------------------------------------------------------------
|     OUTPUT -     |HIGH  |   170µA          |   short circuit! 
|     OUTPUT -     |LOW   |   500µA          |   0
|INPUT PULLUP-     |HIGH  | 1,7/(10k+RPullUp)|   NA                 
|INPUT PULLUP-     |LOW   |   NA             |   3.3/RPullUp
----------------------------------------------------------------

To prevent shortcircuit adding a resistor before D0 would be safe, but with such a resistor, on hacked object circuit input there is now a voltage divider when D0 driven low (and PB1 open). Adding a 680ohm resistor keeps D0 far from current limitation and now when D0 driven low and PB1 is opened, hacked object circuit has a 0.31 level. When D0 is configured as input I must be sure D0 pullup resisor >> 680ohm

  • So is it safe to connect this circuit with only a resistor?Above, I supposed hacked object circuit impedance was fixed (high impedance input with 10k resistor pullup)...
  • Can you provide and detail some examples of dangerous cases?

regards

\$\endgroup\$
0

2 Answers 2

1
\$\begingroup\$

Set D0 to '0' and never change it. Instead, change the output enable (e.g. PB1DIR or pinmode(D0, OUTPUT) when you want to close the switch.

You're limited on how much resistance you can put in series and still get a valid logic value. If you make sure it is unambiguously a '0' and use 0.8V as a threshold, then you need the resistor to be less than 1k. Based on your current limit of 12mA, maybe a 330 ohm resistor would be sufficient to offer some protection while still giving a reasonable output voltage.

I don't think the resistor is necessary for proper operation.

\$\endgroup\$
3
  • \$\begingroup\$ "Set PB1 to '0' and never change it. Instead, toggle the output enable bit (e.g. PB1DIR or TRISB1) when you want to close the switch." PB1 is a push button that can be pushed by user and must be hacked from an external CPU to simulate a push on hacked object circuit. \$\endgroup\$
    – rem
    May 24, 2016 at 16:45
  • \$\begingroup\$ @rem I thought that was the pin on the microcontroller you were using. In that case, the answer is to change PB1 to D0, or whatever the pin is called in your system. \$\endgroup\$
    – W5VO
    May 24, 2016 at 16:47
  • \$\begingroup\$ @W5V0 ok, for D0 configuration. \$\endgroup\$
    – rem
    May 24, 2016 at 16:55
0
\$\begingroup\$

For a less complicated setup, use two pins and a npn transistor or optocoupler.

D0 as high-Z input. You could add a series current limiting resistor if you want t, but unneeded. No Pull-up needed as the target already pulls it up.

D1 with a 1k - 10k resistor to the NPN base. The collector to the button input, and emitter to ground. So across the button, in parallel.

Read state from D0. Change state from D1. No issue with sinking an unknown current, no voltage divider problem.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.