Pages: [1]   Go Down
Author Topic: Shift Register Consistency  (Read 633 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey:

Im using four 74HC595 in parallel. I am shifting out using a modified shiftOut function. My query is about how consistent the registers latch is.

For some reason my whenever the latch is set to HIGH the last pin at least is going HIGH for a split second even though I have not told it to. (I only tell it to be HIGH at the very end before it loops)

I have included the example app along with my 'Shifter' library.

Any help greatly appreciated...


DigitalJohn


Example App:

Code:
#include <SPI.h>

#include <Shifter.h>

Shifter shift(3,6,5,5);


void setup()
{
 
  shift.clear();
 
  // start the serial library:
  Serial.begin(9600);
 
}


void loop()
{
  shift.clear();
 
  delay(10000);
 
  shift.swipeFromTo(0, 36, 250);
  shift.clear();
 
  delay(3000);
 
  shift.set(39, true);
  shift.apply();
 
  delay(1000);
}


Shifter Library
Code:
#include "WProgram.h"
#include "Shifter.h"

Shifter::Shifter(int latchPin, int clockPin, int dataPin, int registers)
{
  _latchPin = latchPin;
  _clockPin = clockPin;
  _dataPin = dataPin;
  _registers = registers;
 
  pinMode(_latchPin, OUTPUT);
  pinMode(_clockPin, OUTPUT);
  pinMode(_dataPin, OUTPUT);
 
  clear();
}

void Shifter::clear()
{
for (int i = 0; i < (_registers*8); i++)
{
_data[i] = false;
}
 
  apply();
}

void Shifter::swipe(int pause)
{
for (int i = 0; i < (_registers*8); i++)
{
if(i > 0) _data[i-1] = false;
_data[i] = true;
  apply();
  delay(pause);
}
clear();
}

void Shifter::swipeFromTo(int from, int to, int pause)
{
for (int i = from; i < to; i++)
{
if(i > 0) _data[i-1] = false;
_data[i] = true;
  apply();
  delay(pause);
}
clear();
}

void Shifter::swipeBack(int pause)
{
for (int i = (_registers*8); i >= 0; i--)
{
if(i < (_registers*8)) _data[i+1] = false;
_data[i] = true;
  apply();
  delay(pause);
}
clear();
}

void Shifter::apply()
{
digitalWrite(_latchPin, LOW);

for (int i = 0; i < _registers*8; i++)  {
digitalWrite(_dataPin, _data[i]);
digitalWrite(_clockPin, HIGH);
digitalWrite(_clockPin, LOW);
}

digitalWrite(_latchPin, HIGH);
}

void Shifter::set(int position, bool value)
{
  _data[position] = value;
}

void Shifter::pulse(int position, int duration)
{
for (int i = 0; i < (_registers*8); i++)
{
_data[i] = false;
}

set(position, true);
apply();

delay(duration);

clear();

}
Logged

London
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

By the way im only using pins output 1-36 and 40 from the shift registers. Is it ok for 37-39 to be 'floating'?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

By the way im only using pins output 1-36 and 40 from the shift registers. Is it ok for 37-39 to be 'floating'?

The term 'floating' only applies to input pins, not output pins unless the device has 'tri-state' output modes.
And yes, it's ok not to have anything wired to unneeded output pins of the shift register.

Lefty

 
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
By the way im only using pins output 1-36 and 40 from the shift registers. Is it ok for 37-39 to be 'floating'?

Question:
- Four 74HC595 means 4*8 output pins. Where do you get the other 4? There are 4 serial output pins, maybe that is why it flashes briefly?

Only my 2 cents...

kind regards,
snakes
Logged

Pages: [1]   Go Up
Jump to: