Pages: [1] 2   Go Down
Author Topic: Shift Register 595 Library  (Read 2581 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm going to develop shift register driving circuit and code. Actually I use TI TPIC6A595 register, that is almost the same as 74HC595 (main difference is that TPIC drives more current).
There is library at Arduino Playground for 595 http://arduino.cc/playground/Code/ShiftRegister595, but this library actually doesn't work. ShiftOut function goes endless loop due to typing mistake, also there are some other mistakes.
I get it working making some changes but as guess better I write a new library with ability to change clock frequency and some other useful features.
Just now I can write out working variant of ShiftOut function
Code:
#define MCLOCKDELAY delay(5)
...
void ShiftRegister595::shiftOut(byte out){
  bool pinState = false;
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  digitalWrite(dataPin, LOW);
  digitalWrite(clockPin, LOW);
  for (int i=7; i>=0; i--) 
  {
    digitalWrite(clockPin, LOW);
    if ( out & (1<<i) )
    {
      pinState= true;
    }
    else
    {
      pinState= false;
    }
    digitalWrite(dataPin, pinState);
    MCLOCKDELAY;
    digitalWrite(clockPin, HIGH);
    MCLOCKDELAY;
    //digitalWrite(dataPin, LOW);
  }
  digitalWrite(clockPin, LOW);
  MCLOCKDELAY;
}
I'll put here whole library when I done with it.
Logged

რასაცა გასცემ შენია, რაც არა - დაკარგულია!

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sweet.  Will be following this thread.
Logged

//LiNK

0
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12725
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

why the 5ms delays?
Logged

[ I won't respond to messages, use the forum please ]

France
Offline Offline
Edison Member
*
Karma: 38
Posts: 1012
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a good and simple library, why write another? smiley

http://bildr.org/2011/08/74hc595-breakout-arduino/
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 549
Posts: 27427
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why use software when you have fast onboard hardware - the SPI port?
Code:
#include <SPI.h>

digitalWrite(RCKpin, LOW);
SPI.transfer(your_data_byte);
digitalWrite(SRCKpin, HIGH);

SCK, goes to SRCK (shift register)
MOSI goes to serial data in
MISO not used
SS got to RCK (output register)
OE/ to GND if not using for PWM
MCLR to +5 if not being used
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Full Member
***
Karma: 1
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why use software when you have fast onboard hardware - the SPI port?
Code:
#include <SPI.h>

digitalWrite(RCKpin, LOW);
SPI.transfer(your_data_byte);
digitalWrite(SRCKpin, HIGH);

SCK, goes to SRCK (shift register)
MOSI goes to serial data in
MISO not used
SS got to RCK (output register)
OE/ to GND if not using for PWM
MCLR to +5 if not being used

It is good point but my application has some requirements that makes me to writing software shifter.
I should drive few registers (not in serial mode) , also I'm going to use only 2 wires to drive register, how? I'll explain later.
And another point is that due to long distance between amtega and register I should use low frequency clock, but I can't serve only one register long time, therefore I'm going to drive registers via loop and timed clocking.
Logged

რასაცა გასცემ შენია, რაც არა - დაკარგულია!

Offline Offline
Full Member
***
Karma: 1
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a good and simple library, why write another? smiley

http://bildr.org/2011/08/74hc595-breakout-arduino/
Unfortunately this library has the same problem, the clock frequency isn't supposed to be controlled.
Logged

რასაცა გასცემ შენია, რაც არა - დაკარგულია!

Offline Offline
Full Member
***
Karma: 1
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is simple model of register driving logic via 2 wires.
Idea is to generate RCK rising via SRCK, just by R-C and diode.

you should use R & C according Clock frequency and packages interval.
It is supposed that there is some interval between pakages sent to register. For my application it is normal, if you need continuous shifting mode, you can't use my logic.
Logged

რასაცა გასცემ შენია, რაც არა - დაკარგულია!

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 549
Posts: 27427
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not just use a shift register without a 2nd stage then?
Like 74AC299 or equivalent?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Full Member
***
Karma: 1
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lets run the circuit simulator and see what we have

You can see that after clock signal goes off, capacitor C1 begins discharging through resistor R1 and we have delayed RCK signal.
Keep in mind register datasheet to figure out logic levels for stable working.
For example for my TPIC6A595 we have:
High-level input voltage at least: 0.85*VCC;
Low-level input voltage max: 0.15*VCC;
Logged

რასაცა გასცემ შენია, რაც არა - დაკარგულია!

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 549
Posts: 27427
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, I understand the concept just fine - I'd just rather see a nice clean clock edge vs a slow capacitor charging up signal to drive the 2nd state Clock line.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Full Member
***
Karma: 1
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not just use a shift register without a 2nd stage then?
Like 74AC299 or equivalent?
Do you mean shift register without buffer register?
Then you have dirty data on output while you send serial data in.
Logged

რასაცა გასცემ შენია, რაც არა - დაკარგულია!

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 549
Posts: 27427
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I suppose having all outputs change together on the RCLK after shifting a bit in is somewhat better.
But since only 1 bit is changing, I'm not sure you'd see much difference.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Full Member
***
Karma: 1
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Slow rising shouldn't considered as problem if RC is calculated correct.
Here is two things:
1) register in has hysteresis to guarantee that there isn't any debounce.  
2) RCK rise should be delayed from SRCK, this guarantees that all data is send correctly.
Logged

რასაცა გასცემ შენია, რაც არა - დაკარგულია!

Offline Offline
Full Member
***
Karma: 1
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suppose having all outputs change together on the RCLK after shifting a bit in is somewhat better.
But since only 1 bit is changing, I'm not sure you'd see much difference.
I don't understand exactly what do you mean.
Look, my task is to drive shift register via 2 signal wires (clock and data), do you have any better idea how should I do it?
Logged

რასაცა გასცემ შენია, რაც არა - დაკარგულია!

Pages: [1] 2   Go Up
Jump to: