Blogroll

Powered by Blogger.

Monday, 28 July 2014

Controlling 74LS138, 3 - Line to 8 - Line Decoder / Demultiplexer, using Arduino

by realfinetime  |  in IC at  04:35

          We have already seen Controlling 74138, 3-Line to 8-Line Decoder/Demultiplexer, using Switches. Controlling 74138 using Arduino is more simpler. Circuit is done as shown in the following diagram. Here an arduino mega board is used for controlling 74138. Select pins ( A, B and C ) and enable pins ( G1, G2A and G2B ) are connected to digital pins of arduino. Connections are:

G1 pin of 74138 is connected to the 8th digital pin of arduino.
G2B pin of 74138 is connected to the 9th digital pin of arduino.
G2A pin of 74138 is connected to the 10th digital pin of arduino.
C pin of 74138 is connected to the 11th digital pin of arduino.
B pin of 74138 is connected to the 12th digital pin of arduino.
A pin of 74138 is connected to the 13th digital pin of arduino.




Pinout diagram of 74138

          Pinout diagram of 74138 is given below. It has three enable pins ( G1, G2A, G2B ), three select pins ( A, B, C ) and eight output pins ( Y0 - Y7 ). Vcc is normally 5V and is supplied from Arduino board or from 7805 voltage regulator. 74138 will take data inputs through the select pins and outputs through the output pin having the number same as input. That is,

if the select pins are at L L L ( 0 in decimal ) in the order C B A, output will be through Y0.
if the select pins are at L L H ( 1 in decimal ) in the order C B A, output will be through Y1.
If the select pins are at L H L ( 2 in decimal ) in the order C B A, output will be through Y2.
If the select pins are at L H H ( 3 in decimal ) in the order C B A, output will be through Y3.
If the select pins are at H L L ( 4 in decimal ) in the order C B A, output will be through Y4.
If the select pins are at H L H ( 5 in decimal ) in the order C B A, output will be through Y5.
If the select pins are at H H L ( 6 in decimal ) in the order C B A, output will be through Y6.
If the select pins are at H H H ( 7 in decimal ) in the order C B A, output will be through Y7.

74138 always gives a complemented output. LED will turn off, if there is an output. LED will turn on, if there is no output.






Truth table of 74138

          Truth table of 74138 is given below. 74138 gives inverted output. That is, LED will turn off, if there is an output through corresponding pin. If the output is HIGH ( H ), LED corresponding to that output will turn ON. Similarly, If the output is LOW ( L ), LED corresponding to that output will turn OFF.

          From the truth table, it is clear that G1 should be HIGH ( H ) always. If G1 is LOW ( L ), all the outputs will be HIGH ( H ) and will not change, even if the select (A, B and C) pins change. That is, all the LEDs will turn on. Similarly, G2A and G2B should be LOW ( L ) always. Otherwise, all the outputs will be HIGH ( H ) and will not change, even if the select (A, B and C) pins change.

          If G1 is HIGH ( H ), G2A is LOW ( L ) and G2B is LOW ( L ) , outputs will change with change in select pins ( A, B and C ). Changes in output with change in input is clearly given in the truth table given above.


Program

Now upload the following program to your arduino board.

int G1 = 8;        // G1 pin of 74138 is connected to the 8th pin of arduino
int G2B = 9;     // G2B pin of 74138 is connected to the 9th pin of arduino
int G2A = 10;   // G2A pin of 74138 is connected to the 10th pin of arduino

int C = 11;        // C pin of 74138 is connected to the 11th pin of arduino
int B = 12;        // B pin of 74138 is connected to the 12th pin of arduino
int A = 13;        // A pin of 74138 is connected to the 13th pin of arduino

// the setup routine runs once when you press reset:
void setup() {              
  // initialize the digital pins as an output.
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);

  pinMode(G2B, OUTPUT);
  pinMode(G2A, OUTPUT);
  pinMode(G1, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(G2B, LOW);   // Set G2B to LOW
  digitalWrite(G2A, LOW);   // Set G2A to LOW
  digitalWrite(G1, HIGH);     // Set G1 to HIGH


  // Input 0 0 0 ( 0 in decimal ) in the order C B A. Output will be through Y0
  digitalWrite(A, LOW);  
  digitalWrite(B, LOW);  
  digitalWrite(C, LOW);  
  delay(1000);          

  // Input 0 0 1 ( 1 in decimal ) in the order C B A. Output will be through Y1
  digitalWrite(A, HIGH);  
  digitalWrite(B, LOW);  
  digitalWrite(C, LOW);  
  delay(1000);

  // Input 0 1 0 ( 2 in decimal ) in the order C B A. Output will be through Y2
  digitalWrite(A, LOW);  
  digitalWrite(B, HIGH);  
  digitalWrite(C, LOW);  
  delay(1000);

  // Input 0 1 1 ( 3 in decimal ) in the order C B A. Output will be through Y3
  digitalWrite(A, HIGH);  
  digitalWrite(B, HIGH);  
  digitalWrite(C, LOW);  
  delay(1000);

  // Input 1 0 0 ( 4 in decimal ) in the order C B A. Output will be through Y4
  digitalWrite(A, LOW);  
  digitalWrite(B, LOW);  
  digitalWrite(C, HIGH);  
  delay(1000);

  // Input 1 0 1 ( 5 in decimal ) in the order C B A. Output will be through Y5
  digitalWrite(A, HIGH);  
  digitalWrite(B, LOW);  
  digitalWrite(C, HIGH);  
  delay(1000);

  // Input 1 1 0 ( 6 in decimal ) in the order C B A. Output will be through Y6
  digitalWrite(A, LOW);  
  digitalWrite(B, HIGH);  
  digitalWrite(C, HIGH);  
  delay(1000);

  // Input 1 1 1 ( 7 in decimal ) in the order C B A. Output will be through Y7
  digitalWrite(A, HIGH);  
  digitalWrite(B, HIGH);  
  digitalWrite(C, HIGH);  
  delay(1000);
}

Output will be a running LEDs. Reduce the time delay to increase the speed of running LEDs.

0 comments:

IMPORTANT NOTICE

All the circuits, published in this blog is only after testing and getting proper results in my private lab. When you try these circuits, you should check the supply voltage, polarity of components, presence of childrens nearby and shorts in the circuits. This website will not be responsible for any harm happened to you or your components caused by your carelessness.

For More Electronic Tips

Blog Archive

Proudly Powered by Blogger.