Author Topic: Shift-register circuit not working, not sure why  (Read 3749 times)

0 Members and 1 Guest are viewing this topic.

Offline kickenTopic starter

  • Contributor
  • Posts: 22
  • Country: us
Shift-register circuit not working, not sure why
« on: September 20, 2016, 06:32:56 pm »
Greetings,

I'm fairly new to the electronics scene and trying to build various things to learn from.  My latest attempt is trying to use shift registers to allow my Arduino to control a bunch of lights individually.  I created  a circuit using three separate shift registers to control the individual lights.  I've attached an image of the circuit I've built.

After trying to build it on some perfboard though I find it does not seem to work well.  The lights are 3.5v bulbs from an old string of christmas lights.  They seem to work fine at the 5v that I am using to power the circuit anyway. The problems I'm seeing is that the lights do not light up as expected.

If I shift out a value that turns all lights on then it works and they all light up.  If I try and light up only one at a time in each group then sometimes none will light, multiple will light, or the wrong one will light.  I've not been able to identify any pattern to the errors, they seem random.

Is there something wrong with the circuit that might cause this or is it most likely a problem with my attempt to create it?  I can't see any obvious problems on my perfboard like bad connections / shorts.

This is the code I am using on my Arduino to test for now.

Code: [Select]

const int PIN_DATA=3;
const int PIN_G1_CLK=4;
const int PIN_G2_CLK=5;
const int PIN_G3_CLK=6;

unsigned int clocks[3]={PIN_G1_CLK, PIN_G2_CLK, PIN_G3_CLK};
unsigned char masks[3]={1,1,1};

int dir=1;

void setup() {
  pinMode(PIN_DATA, OUTPUT);
  pinMode(PIN_G1_CLK, OUTPUT);
  pinMode(PIN_G2_CLK, OUTPUT);
  pinMode(PIN_G3_CLK, OUTPUT);

  digitalWrite(PIN_G1_CLK, LOW);
  digitalWrite(PIN_G2_CLK, LOW);
  digitalWrite(PIN_G3_CLK, LOW);
}

void loop() {
  display();
  delay(1000);
 
  if (dir == 1){
    masks[0] = masks[0] << 1;
    masks[1] = masks[1] << 1;
    masks[2] = masks[2] << 1;
  } else {
    masks[0] = masks[0] >> 1;
    masks[1] = masks[1] >> 1;
    masks[2] = masks[2] >> 1;
  }
 
  if (masks[0] == 0x80 || masks[0] == 0x00){
    masks[0] = masks[1] = masks[2] = 0xFF;
    display();
    delay(3000);
    if (dir == 1){
      dir = -1;
      masks[0] = masks[1] = masks[2] = 0x80;
    } else {
      dir = 1;
      masks[0] = masks[1] = masks[2] = 0x01;
    }
  }
}

void display(){
  int i, len = sizeof(masks)/sizeof(masks[0]);
  for (i = 0; i < len; i++){
    shiftOut(PIN_DATA, clocks[i], MSBFIRST, masks[i]);
  }
}


 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13076
Re: Shift-register circuit not working, not sure why
« Reply #1 on: September 20, 2016, 06:54:55 pm »
A picture is worth a thousand words.  Lets see a well lit, in-focus closeup of both sides of your perfboard and an overall picture of the whole project including all the interconnections.

My first suspicion is noise pickup on the shift clocks wiring, aggravated by the lack of local decoupling (assuming your schematic is accurate), but that's just a guess till I've seen the photos.

I note you don't have a 0V/ground shown on the connector to the Arduino - they *MUST* share a common 0V rail or *NOTHING* will work properly.
 
The following users thanked this post: kicken

Offline kickenTopic starter

  • Contributor
  • Posts: 22
  • Country: us
Re: Shift-register circuit not working, not sure why
« Reply #2 on: September 20, 2016, 08:16:13 pm »
Both the Arduino and the board are being powered by an old ATX power supply via the +5V line so they do share a common ground.

I don't have great camera's available, just a crappy table and phone camera.  I've taken a couple full-view shots of the board with the tablet and annotated them a little.  I'll try my phone later and see if I can get any better quality out of it, just need to charge it first.

While doing the annotating I did notice that somehow I forgot to re-connect the ground from the shift registers to the main ground line after I had re-done the layout some yesterday |O.  With the ground on it seems to work better, but still not perfectly.  Occasionally it still skips lights or get two on when there should only be one.

Capacitors and decoupling is something I still haven't really gotten a good grasp on.  If you know of any good but novice friendly reading about that I'd love to know about it.

 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9933
  • Country: us
Re: Shift-register circuit not working, not sure why
« Reply #3 on: September 20, 2016, 08:52:25 pm »
Google for 'decoupling capacitor'.

In the meantime, put a 0.1 ufd ceramic capacitor between VCC and GND at every chip.  Keep the leads as short as possible.  They used to make sockets that had the capacitor built in.  Probably still do.

Put a 100 ufd capacitor on VCC and GND where it comes onto the board.  I would use a much smaller power supply.  You really don't want a supply that can deliver a huge amount of current.  Get a 5V 2A supply like this:

https://www.amazon.com/s/?ie=UTF8&keywords=5v+2a+switching+power+supply

You can just about bet that power glitches are at the root of your problem.
 
The following users thanked this post: kicken

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: Shift-register circuit not working, not sure why
« Reply #4 on: September 20, 2016, 08:58:24 pm »
The power leads don't look thick enough to light them bulbs, there'll be lots of spikes and volt drops on them when the cold bulbs are switching on.
« Last Edit: September 21, 2016, 12:15:12 am by StillTrying »
.  That took much longer than I thought it would.
 

Offline Bskitter

  • Regular Contributor
  • *
  • Posts: 79
  • Country: cz
Re: Shift-register circuit not working, not sure why
« Reply #5 on: September 20, 2016, 09:33:24 pm »
As mentioned above, decoupling caps on all the chips might do the trick.

You definitely getting interference somewhere, I had a similar problem but only when a large voltage ran near the chips and there would be some Parasitic Capacitance/Voltage Spike, EMF.

The wires that run to the Arduino try wrap them around a ferrite core.

Try twist the power wires from the supply to the chips and the same goes for the supple for the lamps if they are being power separately. 

You could bipass the problem in your code.

In the loop constantly write data to the registers and after each loop turn on another bulb so rough example.

Array of lights values = number of lights [];

loop(){
writtetoregister(); // this writes the array to the registers
increamentnextlight(); // this changes a value in the array to high
}

Some more help.

https://www.arduino.cc/en/Tutorial/ShftOut23
 
The following users thanked this post: kicken

Offline Bskitter

  • Regular Contributor
  • *
  • Posts: 79
  • Country: cz
Re: Shift-register circuit not working, not sure why
« Reply #6 on: September 20, 2016, 09:34:33 pm »
maybe also try  0.1 ufd caps from the base of each transistor to ground
 

Offline kickenTopic starter

  • Contributor
  • Posts: 22
  • Country: us
Re: Shift-register circuit not working, not sure why
« Reply #7 on: September 20, 2016, 10:44:41 pm »
Google for 'decoupling capacitor'.

In the meantime, put a 0.1 ufd ceramic capacitor between VCC and GND at every chip.  Keep the leads as short as possible.  They used to make sockets that had the capacitor built in.  Probably still do.

Thanks. I've read various things about capacitors and decoupling over time and sometimes they still don't really make sense to me or I just don't really know when/why to use them.  My understanding at this point is that they are used before IC's generally to smooth out the power supply by providing extra energy in the case of a sudden increase in demand.  I'll keep reading though, it'll sink in eventually.  It took me a while just to understand how the transistors work in various circuits too.


Anyway adding the 0.1 uf caps to VCC of each shift register seems to have resolved the problems as far as I can tell.  I haven't added a cap to the main input yet, but I will soon.  For now it seems to be working ok without it though.

I'll definitely be finding different power supply eventually as well.  The ATX supply is just the best option I have for testing with at the moment.

 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9933
  • Country: us
Re: Shift-register circuit not working, not sure why
« Reply #8 on: September 20, 2016, 11:54:32 pm »
Here's a short answer:  To switch a capacitive load (and everything is capacitive) in zero time (we want fast rise time) takes infinite energy.  So, where does that instantaneous energy come from?  Well, eventually the power supply makes it up but for the immediate instant, that decoupling capacitor provides the energy.

The power supply is too far away and the power traces (wire) too inductive to be able to provide for these switching transients.

Not a precise answer but just one way of looking at it.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf