Go Down

Topic: How To Use Tri-State Buffers (Read 536 times) previous topic - next topic

isaturk

Hello I was trying to turn on/off multiple jumper cable connections to my servo. I am not talking about cutting the power, I want to physically seperate the connection like a on/off key. However since I want to do this for 6 cables at the same time and I want to eventually design my circuit into a pcb. I thought I should just buy a integrated curcuit component.

Someone recomended me to use tristate/quadstate buffers. I got one (74LS125) but I cannot achieve my goal.

This is the datasheet :
http://files.microjpm.webnode.com/200005440-8ea868fa33/74LS125%20Datasheet.pdf

Can someone please explain to me how can I use those.


Note: I was hoping something like a basic transistor. I give high to C input and get the value of A input from Y output. (I am referring to circuit diagram on the datasheet when saying A,Y,C)

SteveMann

As long as all you are switching is logic-level, this should work fine. As long as the C pin is low, then the output pin=the input pin.  If the C pin is high, then the input is disconnected from the output.

The output pins are limited to 20ma, so you need to check your servo specs.
I am usually so far out of the box that most people don't know what I am talking about.

Please do not ask for help by PM. I will not respond.
If you need help, post a question on the appropriate forum.

isaturk

I guess I could not make it work. Would you mind telling me where is my mistake.


74LS125=>Ardunio MEGA

VCC => 5V
GND => GND
1 => 5
2 => 6
3 => 7

The Code :

Code: [Select]

#define A 6
#define C 7
#define Y 5

void setup() {
  pinMode(A,OUTPUT);
  pinMode(C,OUTPUT);
  pinMode(Y,INPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(A,HIGH);
  digitalWrite(C,LOW);
  Serial.println(digitalRead(Y));
  delay(100);
}


In this form output is

Code: [Select]

1
1
1
1
0
0
0
0
1
1
1
1
1


And recurring, I think it should be 1; When A is LOW, same output. When C is HIGH, same output. Nothing changes.

I soldered the cables btw





WattsThat

You have the  C & Y pins swapped. Should be:

Code: [Select]

#define A 6
#define C 5
#define Y 7

Even with the correct pin numbers, your test code will not do anything useful as it does not test all three states the output pin can be.

You need to change the pinMode() call to "pinMode(Y,INPUT_PULLUP);" so you can test the gate output pin when it goes high impedance and then add two more tests for the other two states shown on the datasheet.
Vacuum tube guy in a solid state world

isaturk

As you may have guessed by now. I am fairly new to these stuff. I have read about tri-state buffers and input-pullup. I think I understand what you mean right now so thank you for that.

However I couldn't still manage to make it work.

This is new wiring

74LS125=>Ardunio MEGA

VCC => 5V
GND => GND
1 => 7
2 => 6
3 => 5


This is my new code

Code: [Select]

#define A 6
#define C 7
#define Y 5

void setup() {
  pinMode(A,OUTPUT);
  pinMode(C,OUTPUT);
  pinMode(Y,INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(A,LOW);
  digitalWrite(C,HIGH);
  Serial.println(digitalRead(Y));
  delay(100);
}


When A is high and C is high.

This is the result

C  A  Y

1  0  1
1  1  1
0  1  1
0  0  0

I dont think it is working as it should.
Sorry if I am being stupid.

WattsThat

How did you generate this table:

C  A  Y
1  0  1
1  1  1
0  1  1
0  0  0

The code posted certainly did not generate it. Please post the actual code used.
Vacuum tube guy in a solid state world

TomGeorge

#6
Jul 30, 2020, 05:10 am Last Edit: Jul 30, 2020, 03:50 pm by TomGeorge
Hi,
Try this code, it compiles but I am currently not in a position to try it.
Sorry big stuff up... to much blood in the coffee stream.
Code: [Select]

#define A 6
#define C 7
#define Y 5
bool Yout;

void setup() {
  pinMode(A, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(Y, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(A, LOW);
  digitalWrite(C, HIGH);
  Yout = digitalRead(Y);
  Serial.print("Hi Z output");
  SerPrint();
  delay(100);
  digitalWrite(A, HIGH);
  digitalWrite(C, HIGH);
  Yout = digitalRead(Y);
  Serial.print("Hi Z output");
  SerPrint();
  delay(100);
  digitalWrite(A, LOW);
  digitalWrite(C, LOW);
  Yout = digitalRead(Y);
  Serial.print(" Yout == Ain");
  SerPrint();
  delay(100);
  digitalWrite(A, HIGH);
  digitalWrite(C, LOW);
  Yout = digitalRead(Y);
  Serial.print(" Yout == Ain");
  SerPrint();
  delay(500);
}

void SerPrint()
{
  Serial.print("C= ");
  Serial.print(C);
  Serial.print("   Ain= ");
  Serial.print(A);
  Serial.print("   Yout= ");
  Serial.println(Yout);
}


Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Paul__B

There is a fundamental mistake in your approach.  You are conceptualising it in terms of "turning off" servos.  This is neither necessary nor appropriate though it will probably work - most of the time.

Servos respond to a stream of pulses.  If you want to cut off the pulse stream, it is only necessary to use a logic AND function.  There are AND gates, but there are various other components that can be used to the same effect such as a NAND gate followed by an inverter, or an inverter feeding a NOR gate.

I am however concerned by the "XY Problem" here.  And you refer to one servo and "6 cables at the same time".  I wonder if you are proposing to actually shut down a servo or to control six servos or what else?  Stopping the pulse feed or disconnecting it does not shut down a servo, its actual behaviour may vary and it will not necessarily cease to draw power.  :smiley-eek:

So you must first explain - properly - what it is you are proposing to do.  :smiley-roll-sweat:

TomGeorge

Hi,
I managed to find a 74LS125 and rewrote my code.
Code: [Select]

#define A 6
#define C 7
#define Y 5
bool Yout;
bool Asig;
bool Csig;


void setup()
{
  pinMode(A, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(Y, INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Hi-Z OFF");
  Asig = 0;
  Csig = 0;
  tristatetest();
  SerPrint();
  delay(500);
  Asig = 1;
  Csig = 0;
  tristatetest();
  SerPrint();
  delay(500);
  Serial.println("Hi-Z ON");
  Asig = 0;
  Csig = 1;
  tristatetest();
  SerPrint();
  delay(500);
  Asig = 1;
  Csig = 1;
  tristatetest();
  SerPrint();
  delay(500);
}


void loop()
{


}
void SerPrint()
{
  Serial.print("C= ");
  Serial.print(Csig);
  Serial.print("   Ain= ");
  Serial.print(Asig);
  Serial.print("   Yout= ");
  Serial.println(Yout);
}
void tristatetest()
{
  digitalWrite(A, Asig);
  digitalWrite(C, Csig);
  Yout = digitalRead(Y);
}




And the serial monitor.

Quote
Hi-Z OFF
C= 0   Ain= 0   Yout= 0
C= 0   Ain= 1   Yout= 1
Hi-Z ON
C= 1   Ain= 0   Yout= 1
C= 1   Ain= 1   Yout= 1
Tom.... :)


Everything runs on smoke, let the smoke out, it stops running....

isaturk

#9
Jul 30, 2020, 06:08 pm Last Edit: Jul 30, 2020, 06:23 pm by isaturk
I sincerely apologize  for the late response.

Referring to WattsThat's repsonse:

Yes, the code I posted generates that output. Maybe faulty hardware?

Referring to Tom's response:

I managed to reproduce same results from your code. However, I am a little bit confused. Whey does it show logic level high when High-Z is on. In transistors, when base value is low, output is also low independent from the input. So they can work as switches. I want to use this component as a switch as well. Is it possible. I am referring to your response at the end of my post so please keep reading.

Referring to Paul__B's response

I did not think it was relevant so I decided not to include this part in my original question. I am trying to make an autonomous aircraft powered by Ardunio Mega. Since my test equipment is expensive, I want to protect the aircraft in case of my software failing. This is why  I put a Radio Frequency Receiver on board the airplane. Using these components I want to disconnect the pwm connection from ardunio to servo and estabilish a pwm connection between RF receive and servo. I draw a diagram of the circuit I want to build. I am new to these stuff so it can be wrong or poorly drawn sorry.

https://drive.google.com/file/d/1sDRyyxp41WI_g9Bj80RYXhYdNF33b0hx/view?usp=sharing

I want to ask Tom that since high Z means high resistance(As I understood it), This curciut should work fine even though some current passes through the 74LS125 even though it is in High Z mode, right?. I am a complete beginner so you guys know the best.

Thank you for all of your responses.

P.S I have 6 servos on board



TomGeorge

#10
Jul 30, 2020, 06:40 pm Last Edit: Jul 30, 2020, 06:44 pm by TomGeorge
Hi,

Quote
Whey does it show logic level high when High-Z is on.
When the output is at Hi-Z, the pullup resistor pulls the output pin to 5V or HIGH.
If you left it without a pullup resistor, the output would be floating and that would mean your Yout would be any value.
This has to be done when testing like this with a controller, when you use it for servo signal, the pullup won't be needed as the other gate will be switching signal to the servo.

Ops diagram.

It will be interesting to see how it works, a benchtop proof of concept would be a good idea.
Hook up two gates instead of the one and feed them with inverted C and monitor Y.

Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

isaturk

Yes I thought that too.When I was experimenting, I found out something. When I set up the following wiring.

RF receiver output => LS125   A pin

Servo pwm input => LS125  Y pin

GND => LS125 C ping

I could not  manage to move the servo. (Other variables are controlled such as servo power or RF receiver health etc).

Is it possible that this module does not allow PWM signals to flow. or something like that

TomGeorge

Hi,

Have you got the gnd of the RF receiver and the gnd of the Arduino and the gnd of the LS125 all connected together?

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

isaturk

#13
Jul 31, 2020, 01:03 pm Last Edit: Jul 31, 2020, 01:05 pm by isaturk
RF is connected to battery so is servo. LS125 is connected to ardunio. Without the LS125, system works nominally

isaturk

Let's consider that tristate buffer is not the right component for this for a second. How would you do what I am trying to do?

Go Up