go away spammer

Author Topic: ..little help with 74HC595 shift register  (Read 5734 times)

0 Members and 1 Guest are viewing this topic.

Offline richardkalafTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
..little help with 74HC595 shift register
« on: February 17, 2010, 01:00:36 PM »
Hello folks..

First of all I'd like to say hello as i'm new to the forum, and hope to be posting at the right place, by the way.

The thing is, i'm trying to figure out how to use the 74HC595 8-bit shift register, so i have it wired like this:

QA a QH > 8 leds connected only to test it's behavior.
G(pin 13) > connected to GND
QH'(pin 9) > N/C
GND (pin 8) > GND
Vcc (pin 16 ) > +5V
SCLR(pin 10) > +5V
SI (pin 14) > RB0 on pic 16F628A
SCK(pin 11) > RB1 on pic 16F628A
RCK(pin 12) > RB2 on pic 16F628A

So far have i got it right?

Now how do i test it?

Is there a way i can test the IC "manually"? Like ,generating pulses on the pins with push-buttons? Just to get to know better it's behavior?

If not, what do i need to do on the uC ? Generate a pulse on SCK, then 1-8 pulses on SI, then a pulse on RCK ?

By the way, i'm using PIC CCS C Compiler .

Hope no one pulls my ear for something like "you're posting on the wrong place!" or "That topic has already been covered!", cuz i already searched it before and didn't find anything here.

Regards to all.

Richard

Offline little-c

  • Robot Overlord
  • ****
  • Posts: 186
  • Helpful? 1
Re: ..little help with 74HC595 shift register
« Reply #1 on: February 17, 2010, 01:45:02 PM »
hello,

first thing, it helps to post links to the relevent data sheets, not everyone can remember exactly how these things work ;)

on to the problem,
page 4 of this data sheet;
http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf
pins 1-7 are output, which I assume you have wired up correctly.
8 is ground, correct.
9 your not using, but its serrial out. shouldn't be a problem.

pin 10, master reset (active LOW).resets when pin is low. on a +5v logic. should be fine. has it got a capacitor on it to smooth out power fluctuations?

pin 11 shift register clock input,

pin 12 storage register clock input

pin 13 output enable (active LOW)  tie this to ground. ie force it low.

pin 14 searial data input.

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: ..little help with 74HC595 shift register
« Reply #2 on: February 17, 2010, 01:50:40 PM »
All looks ok so far. Yes you can test with switches if you want to. To work it:

1) Set SCK and RCK low.

2) Present bit data on SI.
3) Pulse SCK high then low.
4) Repeat steps 2 & 3 for each bit.

5) After all bits are shifted in pulse RCK high then low.

Offline richardkalafTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: ..little help with 74HC595 shift register
« Reply #3 on: February 17, 2010, 02:07:52 PM »
Little-C , no caps on pin 10. Nice tip though.

Ok guys , tks for the tips so far. I'll try to test it with buttons as soon as i get home and let you know what happened. If it works, i'll try on the pic.

cheers.

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: ..little help with 74HC595 shift register
« Reply #4 on: February 17, 2010, 04:24:30 PM »
Little-C , no caps on pin 10. Nice tip though.

Ok guys , tks for the tips so far. I'll try to test it with buttons as soon as i get home and let you know what happened. If it works, i'll try on the pic.

cheers.

You will probably need to debounce your switches...

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: ..little help with 74HC595 shift register
« Reply #5 on: February 17, 2010, 05:58:18 PM »
Also don't forget to current limit the LEDs with series resistors.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: ..little help with 74HC595 shift register
« Reply #6 on: February 17, 2010, 06:49:22 PM »
And wash your hands before and after (and brush your teeth)  ;D
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline richardkalafTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: ..little help with 74HC595 shift register
« Reply #7 on: February 17, 2010, 07:43:05 PM »
LOL tks Soeren that one was the most helpfull ;)

Ok guys, i got the led´s to light up , but in an odd way:

I skipped the test with the switches and did it directly on the PIC connected as i mentioned before.
I added the cap to the MR pin.

Compiled the following code:

#include<16F628A.h>

#use delay(clock=8mhz, xtal)     /* defines crystal frequency */

#fuses hs, nowdt, noprotect, noput
/* hs oscilator used and no watch dog timer, no code protection, no power up timer is used */

#define DS PIN_B0 //data bit
#define SH PIN_B2 //shift clock
#define ST PIN_B1 //latch


void main()

{
loop:

delay_ms(200);
output_bit(DS,1);
output_bit(SH,1);output_bit(SH,0);
output_bit(ST,1);output_bit(ST,0);

delay_ms(200);

goto loop;

}

The result: Leds light up sequentially from Q0 to Q7, and stays on.
I´m still trying to fully understand what i just did, and start controlling each led as i please now.

I have observed an odd behavior though. Even when i hold the PIC´s MCLR pin active (the uC was supposed to stay halted right?) i get random erratic flashes on Q0, and when i approach my finger to the circuit all the leds start to blink erratically,and if i touch the wire they stop.

Am i an ET, or maybe my circuit is possessed?

Tks for the help so far. ;)

Offline little-c

  • Robot Overlord
  • ****
  • Posts: 186
  • Helpful? 1
Re: ..little help with 74HC595 shift register
« Reply #8 on: February 19, 2010, 02:09:41 AM »
caps on power, and use a voltage regulator? if its using an ac generated supply its a 50hz on/off cycle, which could be playing with the system.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: ..little help with 74HC595 shift register
« Reply #9 on: February 19, 2010, 06:33:24 AM »
Hi,

[...] when i approach my finger to the circuit all the leds start to blink erratically,and if i touch the wire they stop.
I rest my case ;)
You have build a missing handwash detector.

Seriously, aside from the caps you need, if this is on a solderless breadboard, check if the contacts have gone poor (wiggle the pins and wires to see if it changes anything).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline richardkalafTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: ..little help with 74HC595 shift register
« Reply #10 on: February 19, 2010, 07:20:18 AM »
Oh good, i thought you guys gave up on me... lol

I'm using a breadboard but it's brand new, and i've played with the wires already to see if it changes but it doesn't . Also, don't you think there's something wrong with my code?

I've played with commenting, changing the order, changing values of the 3 main lines ( DS , SH , ST ) and it seems that i can get action on the outputs with only the SH line active on the code. Of course they light up in a little crazy fashion ,but they do.
I'm trying to identify each line's behavior in practice, and find out how i would procede if i wanted to..say, light just LED "Q3" . Or even better, blink it.

By the way, i'm not using a voltage regulator, but i'm feeding the circuit with a nice brand new digital regulated power source ( 0-30V , 0-3A) . I'll try to add the caps anyway.

PS: Strange things happen with me and the circuits since i've left chernobyl...  (just kidding)

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: ..little help with 74HC595 shift register
« Reply #11 on: February 19, 2010, 08:44:31 AM »
Hi,

I'm using a breadboard but it's brand new, and i've played with the wires already to see if it changes but it doesn't .
OK.


Also, don't you think there's something wrong with my code?
I've played with commenting, changing the order, changing values of the 3 main lines ( DS , SH , ST ) and it seems that i can get action on the outputs with only the SH line active on the code. Of course they light up in a little crazy fashion ,but they do.
I'm trying to identify each line's behavior in practice, and find out how i would procede if i wanted to..say, light just LED "Q3" . Or even better, blink it.
First things first. When it works as planned, then you can start making patterns, but don't let that muddy the waters just yet.

Code: [Select]
void main()

{
loop:

delay_ms(200);
output_bit(DS,1);
/*
You never change this bit. If you don't intend to, just set it outside the loop.
While this is not causing the particular issue, it's sloppy programming ;)
*/

output_bit(SH,1);
delay_ms(1);        // try a short delay here, just for testing.
output_bit(SH,0);

delay_ms(1);

output_bit(ST,1);
delay_ms(1);
output_bit(ST,0);

delay_ms(200);    //-No reason for this, just increase the line on top of the loop if needed

goto loop;
}
This routine will just sweep the lamps on one by one and then the code loops for no reason, constantly latching/strobing the same data into the '595. That might do some strange random flashing as well, if frequencies clash in some way.

When the above works (or not) perhaps try this:
Code: [Select]
void main()

{
n=1       // remember to initialize n as a boolean

loop:
delay_ms(400);
output_bit(DS,n);

output_bit(SH,1);
delay_ms(1);        // try a short delay here, just for testing.
output_bit(SH,0);

delay_ms(1);
output_bit(ST,1);
delay_ms(1);
output_bit(ST,0);

  if (n==1)
    {n=0}
  else
    {n=1}

goto loop;
}

Would be wise to make a macro or a procedure for shift-in as well as for strobing.


By the way, i'm not using a voltage regulator, but i'm feeding the circuit with a nice brand new digital regulated power source ( 0-30V , 0-3A) . I'll try to add the caps anyway.
No matter how nice it is, the leads between it and the circuit will follow the laws of physics (resistance and inductance), so please add a cap.


PS: Strange things happen with me and the circuits since i've left chernobyl...  (just kidding)
Yeah, but at least you save having a desk lamp ;D
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline richardkalafTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: ..little help with 74HC595 shift register
« Reply #12 on: February 19, 2010, 09:48:15 AM »
Tks a lot Soeren. Who knew you could be so helpfull when not telling me to go wash my hands lol . Seriously though thanks for the time spent to try and help me.

I'll do the ajustments you sugested and get to the testing as soon as i get home and i'll let you know.

This is a great forum by the way. People really try to help and seem to have an elevated knowledge level. You can usually tell that when no one starts making fun of others because they are still a begginer at something.  We all need help even to be born , so...

Tks again!

 


Get Your Ad Here