Offline
Jr. Member
Karma: 0
Posts: 95
|
 |
« on: October 29, 2012, 03:26:30 pm » |
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 #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
God Member
Karma: 12
Posts: 588
A life? Where can I download one of those?
|
 |
« Reply #1 on: October 29, 2012, 08:03:39 pm » |
Sweet. Will be following this thread.
|
|
|
|
|
Logged
|
//LiNK
|
|
|
|
0
Offline
Tesla Member
Karma: 71
Posts: 6624
Arduino rocks
|
 |
« Reply #2 on: October 30, 2012, 06:10:34 am » |
why the 5ms delays?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 248
Posts: 16535
Available for Design & Build services
|
 |
« Reply #4 on: October 30, 2012, 09:42:09 am » |
Why use software when you have fast onboard hardware - the SPI port? #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
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 95
|
 |
« Reply #5 on: October 30, 2012, 01:02:16 pm » |
Why use software when you have fast onboard hardware - the SPI port? #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
Jr. Member
Karma: 0
Posts: 95
|
 |
« Reply #6 on: October 30, 2012, 01:06:12 pm » |
Unfortunately this library has the same problem, the clock frequency isn't supposed to be controlled.
|
|
|
|
|
Logged
|
რასაცა გასცემ შენია, რაც არა - დაკარგულია!
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 95
|
 |
« Reply #7 on: October 30, 2012, 01:23:15 pm » |
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
Offline
Brattain Member
Karma: 248
Posts: 16535
Available for Design & Build services
|
 |
« Reply #8 on: October 30, 2012, 01:43:37 pm » |
Why not just use a shift register without a 2nd stage then? Like 74AC299 or equivalent?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 95
|
 |
« Reply #9 on: October 30, 2012, 01:44:34 pm » |
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
Offline
Brattain Member
Karma: 248
Posts: 16535
Available for Design & Build services
|
 |
« Reply #10 on: October 30, 2012, 01:47:38 pm » |
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
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 95
|
 |
« Reply #11 on: October 30, 2012, 01:48:23 pm » |
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
Offline
Brattain Member
Karma: 248
Posts: 16535
Available for Design & Build services
|
 |
« Reply #12 on: October 30, 2012, 01:52:00 pm » |
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
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 95
|
 |
« Reply #13 on: October 30, 2012, 01:55:10 pm » |
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
Jr. Member
Karma: 0
Posts: 95
|
 |
« Reply #14 on: October 30, 2012, 01:57:34 pm » |
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
|
რასაცა გასცემ შენია, რაც არა - დაკარგულია!
|
|
|
|
|