designing a circuit with a programmable input output pin

Thread Starter

rustynex

Joined Jul 26, 2019
7
Hi everyone,

i am designing a circuit and i want to future proof it by having some programmable GPIO pins that can be assigned programmatically later on.

the pins need to be able to output 12v at 5 amps, or become an input, preferably an analog one so that i can decide to use it as a sensor input or a digital input.

all microprocessors have programmable IOs, and i was wondering how it was done so i can design my own. i want to use minimal MCU pins for these GPIOs

most importantly i would like to try and make the pin protected from incorrect use. so if the pin is connected to ground as an input pin then there should be no way that the 12v output can be activated, or if the pin receives 12v in then the microprocessor is protected against that as well.

any help would be great thanks!
 

Sensacell

Joined Jun 19, 2012
3,447
The two ideas can co-exist simultaneously, on the same pin.

1) Use a resistor voltage divider to divide the input voltage on the IO pin down to the correct range for the ADC.
(1 analog input pin)

2) Use a PFET high-side-switch to control the 12V output.
(1 digital output pin)

As long as the high-side-switch is off, you can simply read whatever voltage is on the pin- input mode.
Turning on the switch forces the output to +12 at a low impedance level- power out mode.
(reading it just shows the 12V signal)

You just have to consider the leakage current of the PFET when it's OFF- make sure your resistor voltage divider values are low enough to swamp the leakage.

No need to protect the analog input- besides ESD.
Shorts to ground might need a fuse or active current limit for output mode.
Not simple to "detect" a short to ground before turning the output on, lots of design issues there- your load looks like a short to ground.
 

Thread Starter

rustynex

Joined Jul 26, 2019
7
The two ideas can co-exist simultaneously, on the same pin.

1) Use a resistor voltage divider to divide the input voltage on the IO pin down to the correct range for the ADC.
(1 analog input pin)

2) Use a PFET high-side-switch to control the 12V output.
(1 digital output pin)

As long as the high-side-switch is off, you can simply read whatever voltage is on the pin- input mode.
Turning on the switch forces the output to +12 at a low impedance level- power out mode.
(reading it just shows the 12V signal)

You just have to consider the leakage current of the PFET when it's OFF- make sure your resistor voltage divider values are low enough to swamp the leakage.

No need to protect the analog input- besides ESD.
Shorts to ground might need a fuse or active current limit for output mode.
Not simple to "detect" a short to ground before turning the output on, lots of design issues there- your load looks like a short to ground.

thanks for the reply,

the bit i am confused about is how the two systems link together to have one pin. the input of the voltage divider would have to be attached to the output of the PFET, and the output of the voltage divider would have to be attached to the input of the PFET, meaning that a supply voltage that is supposed to be read on the analog pin would pass into the PFET and turn it on. how can the two systems be linked yet isolated from each other?
 

Sensacell

Joined Jun 19, 2012
3,447
thanks for the reply,

the bit i am confused about is how the two systems link together to have one pin. the input of the voltage divider would have to be attached to the output of the PFET, and the output of the voltage divider would have to be attached to the input of the PFET, meaning that a supply voltage that is supposed to be read on the analog pin would pass into the PFET and turn it on. how can the two systems be linked yet isolated from each other?
By using two separate IO pins.
One to read the voltage (analog ADC input)
Another to control the PFET. (digital OUT)

The two circuits connect to a single IO circuit - from your module
 

Thread Starter

rustynex

Joined Jul 26, 2019
7
By using two separate IO pins.
One to read the voltage (analog ADC input)
Another to control the PFET. (digital OUT)

The two circuits connect to a single IO circuit - from your module
but how does this system work inside a micro processor? i have a limited amount of pins on the connector for the board, so i want to have the last few pins left on the connector to be GPIOs, but i am struggling to work out how a single pin can be programmatically configured to be either a supply output or a digital input whilst keeping everything isolated
 

Alec_t

Joined Sep 17, 2013
14,313
but how does this system work inside a micro processor?
Inside a CMOS micro there would likely be two control signals: one for the gate of a high-side FET and one for the gate of a low-side FET. This would enable either FET to be switched on to drive a pin high or low in output mode, or both FETs to be kept switched off for using the pin in input mode.
 

BillB3857

Joined Feb 28, 2009
2,570
You could use a 74LD245 bi-directional bus driver with the proper support circuits, i.e. voltage divider inputs for high voltage digital input and FET circuits for the high voltage/current outputs. One data line would control the direction of the 8 signals.
 

Thread Starter

rustynex

Joined Jul 26, 2019
7
Inside a CMOS micro there would likely be two control signals: one for the gate of a high-side FET and one for the gate of a low-side FET. This would enable either FET to be switched on to drive a pin high or low in output mode, or both FETs to be kept switched off for using the pin in input mode.
but wouldn't that require a third pin for the actual input monitoring? or can the input be done behind the FET?

You could use a 74LD245 bi-directional bus driver with the proper support circuits, i.e. voltage divider inputs for high voltage digital input and FET circuits for the high voltage/current outputs. One data line would control the direction of the 8 signals.
thats a really nice idea, though you would have to change all the IOs to inputs or outputs at the same time.
 
Top