Truth Tables

Truth Tables

Circuit Specification: Truth Tables

We now need to specify how the three buttons will control the three LEDs. The most “obvious” approach is almost undoubtedly to have button A control LED A, button B control LED B, and button C control LED C. In other words, if button A is pressed, then LED A is illuminated regardless of the state of the other buttons. Let's get a bit more complicated than that.

First, we need to consider how many different combination of button-pushes (button states) there are. If there were a single button, there would only be two possible states: either the button is pushed or it isn't. If we add another button so that there are now two buttons, there are four possible combination of states: the two possible states of the original button with the second button un-pushed and the two possible states of the original button with the second button pushed. If we add yet another button so that there are now three buttons, there are eight possible combination of states: the four possible states of the two original button with the third button un-pushed and the four possible states of the two original button with the third button pushed. In general, every time we add one more button, we double the number of possible combinations. Thus, if there are $N$ buttons, there are $2^N$ possible combinations of inputs (button-pushes).

In our circuit we have three buttons and thus eight ($2^3=8$) possible combination of button states. We have the freedom to specify what each combination of inputs translates to in terms of illuminating the LEDs. First, let's make a table that merely lists all the button states. We will use a 0 to indicate that a button is not pushed and a 1 to indicate that it is pushed.

BTN A BTN B BTN C
000
001
010
011
100
101
110
111

Now let's construct a table with three more columns. The additional columns represent the states of the LEDs and we'll give them a yellow background. In these columns a 0 indicates that the LED is not illuminated while a 1 indicates it is illuminated. The following table represents the “obvious” mapping of the buttons to the LEDs—in other words, if a particular button is pushed, the corresponding LED is illuminated.

BTN A BTN B BTN C LED A LED B LED C
000 000
001 001
010 010
011 011
100 100
101 101
110 110
1 1 1 111

A table that displays inputs and outputs, such as shown above, is known as a truth table. The reason for calling these “truth tables” is related to the fact that the inputs and output to binary systems are sometimes labeled “true” and “false” (instead of 0 and 1).

Notice that for this particular way of controlling the LEDs, each button only affects one LED: the illumination of LED A only depends on button A, the illumination of LED B only depends on button B, and the illumination of LED C only depends on button C. Because of this, we can actually break this large truth table into three smaller once that give us the same information about the behavior of the system

BTN A LED A
0 0
1 1
    
BTN B LED B
0 0
1 1
    
BTN C LED C
0 0
1 1

These three truth tables effectively tell us that the state of LED A is independent of buttons B and C; the state of LED B is independent of buttons A and C; and the state of LED C is independent of buttons A and B. However, we want to allow more than one button to affect the LEDs. Assume the desired behavior of the system is this: If one button is pushed, the corresponding LED should be illuminated. If two buttons are pushed, the LED corresponding to the non-pushed button should be illuminated. And, finally, if none of the buttons are pushed or all of the buttons are pushed, then none of the LEDs should be illuminated. The truth table corresponding to this system is:

BTN A BTN B BTN C LED A LED B LED C
0 0 0 000
0 0 1 001
0 1 0 010
0 1 1 100
1 0 0 100
1 0 1 010
1 1 0 001
1 11 000

Note the conditions that cause LED A to illuminate. In English we might say, “Illuminate LED A if button A is pushed and buttons B and C are not pushed, or illuminated it if button A is not pushed and buttons B and C are pushed. Otherwise, do not illuminate LED A.” Now the question becomes: How do we translate this statement into C/C++? To do so, we need to use logical operators, which are covered in the related materials section at the right.


  • Other product and company names mentioned herein are trademarks or trade names of their respective companies. © 2014 Digilent Inc. All rights reserved.