Shift Register Consistency

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:

#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

#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();

}

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'?

DigitalJohn:
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

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