# Why doesn't battery work with gates in simulation?

#### enesene

Joined Mar 3, 2020
22
With logic probes, circuit works right as it has to be but in real life i have to use switch to make gates input 0 or 1. I simulated it before i do but it doesn't work as it should be. (000) must be logic 1.

#### Attachments

• 17.9 KB Views: 1

#### djsfantasi

Joined Apr 11, 2010
7,566
When you’re using switches, some of the gate inputs are ‘floating’. That means, when the switch is open, the input is indeterminate. Neither high nor low consistently. In the simulation, this state isn’t represented and they let you get away with it. You need a better simulator.

in real life, each input to a CMOS gate must either be a high or low signal. To make sure this happens, you need a pull-down or pull-up resistor, depending on the input to the switch.

I’m going to assume that you’re switching Vcc to the gate. When the switch is open, you’ll need a pull-down resistor. A 4.7kΩ resistor should work, or even as much as 10kΩ. Connect it from the switch contact that goes to the gate input and to circuit ground.

This, when the switch is closed, Vcc is input to the gate. There isn’t a short because of the resistor. The gate sees a high input. When the switch is open, the gate input connects to circuit ground through the resistor and the gate sees a low input.

#### MrChips

Joined Oct 2, 2009
23,099
Simulators are only as good as the model used to perform the simulation.
Do not always believe that the results produced by the simulator is correct.

In real life, don't leave an input pin to a logic gate floating.
Regardless of the position of the real switch, what is the voltage at the input of a gate?

With nothing connected to the input of a gate, you cannot assume that the input voltage is 0V or any other voltage.
Make sure that the input pin receives a defined voltage.

#### atferrari

Joined Jan 6, 2004
4,253
I recall using pull up or pull down resistors for most of the circuits I have built.

/Edit
Coming way too late to the party.
Edit/

#### enesene

Joined Mar 3, 2020
22
When you’re using switches, some of the gate inputs are ‘floating’. That means, when the switch is open, the input is indeterminate. Neither high nor low consistently. In the simulation, this state isn’t represented and they let you get away with it. You need a better simulator.

in real life, each input to a CMOS gate must either be a high or low signal. To make sure this happens, you need a pull-down or pull-up resistor, depending on the input to the switch.

I’m going to assume that you’re switching Vcc to the gate. When the switch is open, you’ll need a pull-down resistor. A 4.7kΩ resistor should work, or even as much as 10kΩ. Connect it from the switch contact that goes to the gate input and to circuit ground.

This, when the switch is closed, Vcc is input to the gate. There isn’t a short because of the resistor. The gate sees a high input. When the switch is open, the gate input connects to circuit ground through the resistor and the gate sees a low input.
Thank you all, I take resistors as 10k and Vcc is 9V and it works. By the way does Led needs resistor like 220ohm?

#### djsfantasi

Joined Apr 11, 2010
7,566
I recall using pull up or pull down resistors for most of the circuits I have built.

/Edit
Coming way too late to the party.
Edit/
Assuming I’m not using TTL gates...

First, I ensure that any input from a switch, push button or otherwise, has a pull-up or pull-down resistor.

Second, for any input from an output of another gate, I assume that such a resistor is not necessary.

Unless (and this is where it gets complicated) it’s a tri-state output. Then once again you need a resistor.

#### djsfantasi

Joined Apr 11, 2010
7,566
Thank you all, I take resistors as 10k and Vcc is 9V and it works. By the way does Led needs resistor like 220ohm?
Probably, but you need to do some calculations to determine the actual resistor value.
1. What is the Vf (Vf) rating of the LED?
2. What is the Imax rating of the LED?
3. What if the logic high voltage of the gate (Voh)?
Then, you use these calculations:
Iled = 0.8 * Imax
R = ( Voh - Vf) / Iled
Note that Iled could possibly be lower. Try different resistor values and use the largest that provides the acceptable brightness of the LED.

#### WBahn

Joined Mar 31, 2012
26,398
Also keep in mind that most logic families are not intended to source or sink any significant current -- they are intended to drive other gates in the same logic family. So be sure that the data sheet indicates that you can source/sink the desired amount. Also keep in mind that there are typically limits both for each gate but also for the package as a whole.

#### MrChips

Joined Oct 2, 2009
23,099
By the way does Led needs resistor like 220ohm?
We don't know. You have to be more specific.
Where does the resistor go?
Can you elaborate by using a circuit schematic?
The correct value of components can be determined by calculation, not by guessing.

#### dl324

Joined Mar 30, 2015
12,688
By the way does Led needs resistor like 220ohm?
You can't expect any logic gate to have a valid logic level if you put an LED to ground on the output.

220 ohms is probably too small. Without you telling what logic family you're using, we can't answer.

As others have already mentioned, leaving inputs floating on any logic family isn't a good idea.

#### enesene

Joined Mar 3, 2020
22
Thank you. Do you know any IC which is similiar to the circuit i attach on the post? I was thinking about using transistors to make gates but i guess it's better to use ic. What do you think?

#### crutschow

Joined Mar 14, 2008
26,838
Do you know any IC which is similiar to the circuit i attach on the post? I was thinking about using transistors to make gates but i guess it's better to use ic.
I would use CD4000 series CMOS logic gates, along with a transistor buffer, (e.g. 2N7000)) to drive the LED.

#### enesene

Joined Mar 3, 2020
22
I would use CD4000 series CMOS logic gates, along with a transistor buffer, (e.g. 2N7000)) to drive the LED.
um you mean the circuit on the simulation works without led driver like transistor or mosfet but in real i should use it? i thought it's okay just to get wire from gate output and connect to led directly

#### Alec_t

Joined Sep 17, 2013
11,985
i thought it's okay just to get wire from gate output and connect to led directly
That's fine in simulation, but may damage a gate in real life. Check the datasheet for the safe output current of the gates you are using. Simulation models generally don't impose any current limits.

#### crutschow

Joined Mar 14, 2008
26,838
i thought it's okay just to get wire from gate output and connect to led directly
As Alec noted, simulations generally don't pay attention to limits.
So it depends upon the power supply voltage you have, the actual gate you are using, and how much current you want through the LED.

#### Audioguru again

Joined Oct 21, 2019
2,881
i thought it's okay just to get wire from gate output and connect to led directly
Your simulation software does not know the maximum allowed dissipation of the gate output.

The TI datasheet for a CD4081 shows that its maximum allowed output dissipation per gate is 100mW.
With a 10V supply it shows on a graph an output current of typically 19mA into a 2V red LED without a current-limiting resistor so it will deliver 17mA with a 9V supply. Then the gate output will have 7V across it and 17mA through it for a dissipation of 7V x 17mA= 119mW which is above its rating so it will be destroyed without a current-limiting resistor in series with the LED.