How to configure direction of I/O during runtime

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RuGl_1600761
Employee
Employee
25 replies posted 25 sign-ins 10 replies posted

I use PSOC5. I want to reconfigure an I/O during runtime. Receiving an command on USB I have to set (eg) I/O1 to input and I/O2 to output. Receiving a different command I/O1 shall be output and I/O2 shall be input. But I want to have a push pull output and not an open drain I/O. How can I adchive this ?

rgl
0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

RuGl,

Yes it is possible to do what you ask.

There are two ways to implement this.  One is a design-time schematic implementation the other is purely in SW.

Design-time

Here is a schematic snip for TopDesign:

In your application:

Write a '0' to CR_OE_cntrl and Pin_IO1 is an input and Pin_IO2 is an output PP.  Ie:

CR_OE_cntrl_Write(0);

Write a '1' to CR_OE_cntrl and Pin_IO1 is an output PP and Pin_IO2 is an input.

CR_OE_cntrl_Write(1);

This method is straight-forward and is visually obvious.  However it does consume one Control Register and one UDB block.

SW only

Let's assume yo have two pins allocated in your TopDesign => Pin_IO1 and Pin_IO2 .

To change the drive mode of Pin_IO1 to input, issue the API call:

Pin_IO1_SetDriveMode(Pin_IO1_DM_DIG_HIZ);

To set it to output Strong make the API call:

Pin_IO1_SetDriveMode(Pin_IO1_DM_STRONG);

To change the drive mode of Pin_IO2, just change the API calls above to substitute Pin_IO2 instead of Pin_IO1.

Pros/Cons

The design-time schematic method requires a few more PSoC resources but is simpler in the code since both IOs can be switched with one API call.

The SW only method saves the resources but requires two API calls.

Your choice.

Caveat

Because you want Push-Pull (PP) strong drive you have to be careful the the external sources of outputs (ext_in_out1 and ext_in_out2) are open drain with pull up/downs.

If you are getting a command via USB to change the Pin_IO1 and Pin_IO2 drive mode, how do you guarantee that the output sources of ext_in_out1 or ext_in_out2 are not strong driving their signal in the opposite direction of Pin_IO1 or Pin_IO2?

For example if Pin_IO1 is being driven by ext_in_out1 to 5V and you switch Pin_IO1 to output strong with a signal of 0 (ie 0V), then you can potentially damage the PSoC pin.

If you cannot afford to use open drains on ext_in_out1 and ext_in_out2, then consider at least placing a 1K series resistance in the signal.  This will limit the current to 5mA in the case where one is driven to 5V and the other to 0V.

Len

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
1 Reply
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

RuGl,

Yes it is possible to do what you ask.

There are two ways to implement this.  One is a design-time schematic implementation the other is purely in SW.

Design-time

Here is a schematic snip for TopDesign:

In your application:

Write a '0' to CR_OE_cntrl and Pin_IO1 is an input and Pin_IO2 is an output PP.  Ie:

CR_OE_cntrl_Write(0);

Write a '1' to CR_OE_cntrl and Pin_IO1 is an output PP and Pin_IO2 is an input.

CR_OE_cntrl_Write(1);

This method is straight-forward and is visually obvious.  However it does consume one Control Register and one UDB block.

SW only

Let's assume yo have two pins allocated in your TopDesign => Pin_IO1 and Pin_IO2 .

To change the drive mode of Pin_IO1 to input, issue the API call:

Pin_IO1_SetDriveMode(Pin_IO1_DM_DIG_HIZ);

To set it to output Strong make the API call:

Pin_IO1_SetDriveMode(Pin_IO1_DM_STRONG);

To change the drive mode of Pin_IO2, just change the API calls above to substitute Pin_IO2 instead of Pin_IO1.

Pros/Cons

The design-time schematic method requires a few more PSoC resources but is simpler in the code since both IOs can be switched with one API call.

The SW only method saves the resources but requires two API calls.

Your choice.

Caveat

Because you want Push-Pull (PP) strong drive you have to be careful the the external sources of outputs (ext_in_out1 and ext_in_out2) are open drain with pull up/downs.

If you are getting a command via USB to change the Pin_IO1 and Pin_IO2 drive mode, how do you guarantee that the output sources of ext_in_out1 or ext_in_out2 are not strong driving their signal in the opposite direction of Pin_IO1 or Pin_IO2?

For example if Pin_IO1 is being driven by ext_in_out1 to 5V and you switch Pin_IO1 to output strong with a signal of 0 (ie 0V), then you can potentially damage the PSoC pin.

If you cannot afford to use open drains on ext_in_out1 and ext_in_out2, then consider at least placing a 1K series resistance in the signal.  This will limit the current to 5mA in the case where one is driven to 5V and the other to 0V.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes