Use Multiplexing to Expanding Output Pins

Microcontroller Topics
Post Reply
User avatar
Shehani
Lieutenant
Lieutenant
Posts: 61
Joined: Mon Aug 19, 2013 2:11 pm

Use Multiplexing to Expanding Output Pins

Post by Shehani » Wed Nov 13, 2013 10:50 am

Imagine that you want to control 100 LED’s with a PIC Microcontroller. No PIC Microcontroller with a DIP package having that many IO lines. This article explains two ways to expand output pins of a Microcontroller through multiplexing. Here we are using Time Division Multiplexing to expand output pins. The first method is by using D-Latch and second method is by using Serial in Parallel Out Shift register. In this tutorial we demonstrate the working by using 64 LEDs.

Using D Flip-Flop and Decoder

This way of multiplexing uses Octal (8 – Bit) D Flip-Flop 74574 and 3-to-8 Decoder 74138. The D Flip-Flop serve as a memory to store a bit of data. So to control 64 LED we need 64 D Flip-Flops, that is eight 74574 chips. We give same data to D0 t0 D7 of all chips and each chip is enabled at different times. Thus we can individually set Logic LOW or HIGH to outputs of each chip.
74574 Octal D Flip-Flop
74574 Octal D Flip-Flop
1.png (5.3 KiB) Viewed 5801 times

The 74574 D Flip-Flop has the following pins.

?Eight Inputs (D0 – D7)
?Eight Outputs (Q0 – Q7)
?Common Clock (CP)
?Output Enable (OE – Active Low)


When the Output Enable (OE) pin is high all the output pin of 74574 will be in Logic LOW. When it is LOW the output follows the input when a LOW to HIGH pulse occurs at Common Clock (CP) pin. In other cases the output follows the previous output, ie latched. We connect 8 output pins of pic microcontroller to the eight inputs (D0 – D7) of each chip. The Clock for each chip is given at different times.
IC 74138 3-to-8 Decoder
IC 74138 3-to-8 Decoder
2.png (6.96 KiB) Viewed 5801 times

Next problem is that, we need 8 Output Pins to enable each chip. This can be solved by using a 3-to-8 decoder ( IC 74138). It converts 3 lines to 8 (Y0 – Y7). When the input is 000 the output Y0 will be activated (Y0- LOW, Other Outputs – HIGH), when it is 001 the output Y1 will be activated (LOW)

The 74138 has following pins

?Three Inputs (A, B, C)
?Eight Outputs (Y0 – Y1, active Low)
?Three Enables (2 – active low and 1 – active high)

We use the three output lines of PIC Microcontroller to select one of the 8 outputs. The chip will be enable only when its two active low enable inputs are at Logic LOW and the active high enable input is at Logic HIGH. All the output pins will be high when the chip is disabled.


Circuit Diagram

Expanding Output Pins of a PIC Microcontroller through Multiplexing
Expanding Output Pins of a PIC Microcontroller through Multiplexing
3.png (97.86 KiB) Viewed 5801 times
The following example MikroC Code works the above circuit as a Chaser.

MikroC Code

Code: Select all

void main()
{
  int i,c;
  CMCON = 0x07; // To turn off comparators
  ADCON1 = 0x06; // To turn off analog to digital converters
  TRISB = 0x00;
  TRISC = 0x00;
  TRISD = 0x00;
  PORTD = 0x00;

  do
  {
    PORTB = 1;
    for(c = 0;c<=7;c++)
    {
      for(i=0;i<=7;i++)
      {
        PORTC = i;      //To Select a particular chip
        PORTD.F0 = 1;   // Enable 74138
        Delay_ms(20);   // To give a pulse with of 20ms
        PORTD.F0 = 0;   // Disable 74138
      }
      PORTB = PORTB<<1; // Left Shift
    }
  }while(1);
}

Using Serial-in-Parallel Out Shift Register

Here we use the IC 74164 an Eight Bit Serial-in-Parallel Out Shift register. The Data is given serially through one pin. To connect 64 LEDs we need eight 74164 chips. We are giving same clock to eight chips and different data input lines. Thus we need 8 Output pin for Data and 1 Output pin for Clock of the PIC Microcontroller. We can see that the pin number is reduced than in the previous method, but this method is a bit slower compared to the previous. The IC 74164 has the following pins.

Serial in Parallel Out Shift Register 74164
Serial in Parallel Out Shift Register 74164
4.png (3.24 KiB) Viewed 5801 times
?Data (A and B, these two pins are ANDed internally)
?Clock (CP)
?Chip Enable (MR – Here we don’t use this pin)


Here we connect the data input pin A of each chip to an Output pin of PIC Microcontroller and B is tied to Vcc (LOGIC HIGH). The Clock pin (CP) of each chip is tied together and connected to another output pin of PIC Microcontroller. Thus we can easily control the 64 LEDs very easily.

Circuit Diagram




The following example MikroC Code works the above circuit as a Chaser.

MikroC Code

Code: Select all

void main()
{
  int j;
  CMCON = 0x07; // To turn off comparators
  ADCON1 = 0x06; // To turn off analog to digital converters
  TRISB = 0x00;
  TRISD = 0x00;
  PORTD = 0x00;

  do
  {
    PORTB = 0xFF;
    for(j=0;j<8;j++)
    {
      PORTD.F7 = 1;
      Delay_ms(50);
      PORTD.F7 = 0;
      PORTB = 0;
      Delay_ms(200);
    }
  }while(1);
}


Article courtesy of electrosome.com
Post Reply

Return to “Microcontrollers”