Sunday, October 16, 2011

Circuit-05 - Shift Registers

Purpose: To use a shift register to make 8 LED's count in binary

Materials:
  • Arduino x 1
  • Breadboard x 1
  • Arduino Holder x 1
  • CIRC-05 Breadboard Sheet x 1
  • Shift Register (74HC595) x 1
  • Wire x  ∞
  • LED x 8
  • 330 Ohm Resistor x 8

References:

Program Details: This circuit is very similar to Circuit-02 because we are using a lot of wires, as well as 8 LEDs. However, this time we will control 8 LEDs with only 3 pins using a shift register. Before doing this circuit, you should learn a bit more about how shift registers work. In this specific shift register, we will be using 3 pins, data, clock and latch. First to use it, we clock the data, then lock it using the latch. To lock in the latch, we set the data pin to LOW, then pulse the clock, then set the data pin to HIGH and repeat as many times as needed. Then the latch is pulsed which transfers the data (8 bits) to the shift register LEDs.

Some new programming terms are introduced as well. First off, a new type of variable, const. A constant variable is one that remains the same throughout the program. Secondly, a new method is used, shiftout (data, clock, MSBFIRST, value), which shifts out the 8 bit program to the shift register. The long way to create this method is given, which uses bit-masks to change the data pin and clock pin to high and low multiple times also known as pulsing. 
 

Time to complete: 20 mins to assemble
                               15 mins to code

Results: The first time we ran the program on the arduino, only 6 of the LEDs were lighting up. One of the LED's was broken so we replaced it with another LED and it worked. The last LED didn't work because the resistor was not placed in correctly.

Photo: 


Video: 


Tips:
  • Make sure you place the shift register properly (cutout side on top)
  • To make the circuit in an organized manner, start with placing the shift register, then the resistors, then the LEDs, then connect the wires from the shift register output's to the LEDs, then attach the wires from the Arduino Latch, Clock and Data to the arduino pins, and finally attach the remaining wires. 

Further Work: I will change the program so that I control each LED rather than just using the pre-built methods. To do this, i will turn each LED off and on at certain intervals.

Program Modifications:
The program is the exact one from the link below.

Program:

int data = 2;      // assigns pin2 to data
int clock = 3;    // assigns pin3 to clock
int latch = 4;     // assigns pin4 to latch

//Used to control single LEDs
int ledState = 0;
const int ON = HIGH;    //constants cannot be changed later in the program
const int OFF = LOW;
         
                       
void setup()      //runs once when program is intialized 
{
  //assings data, clock and latch with an output
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
}// ends setup 


void loop()                          // loop runs as long as there is power
{
  int delayTime = 100;         // sets delayTime to 100 ms
  for(int i = 0; i < 256; i++)
  {
   updateLEDs(i);               // goes to updateLEDs method
   delay(delayTime);           // delays 100 milliseconds
  }
}// ends loop


void updateLEDs(int value)                         // Sends the LED signals to the shift register
{
  digitalWrite(latch, LOW);                         // Pulls the chips latch to low
  shiftOut(data, clock, MSBFIRST, value); // Shifts out the 8 bits to the shift register
  digitalWrite(latch, HIGH);                        // Pulls the latch to high to display data
}// ends updateLEDs method

No comments:

Post a Comment