Shift-register circuit not working, not sure why - Page 1
Forum section: electronics / beginners

author: kicken
author_rank: Contributor
timestamp: September 20, 2016, 06:32:56 pm
content: 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: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={PIN_G1_CLK, PIN_G2_CLK, PIN_G3_CLK};unsigned char masks={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 = masks << 1;masks = masks << 1;masks = masks << 1;} else {masks = masks >> 1;masks = masks >> 1;masks = masks >> 1;}if (masks == 0x80 || masks == 0x00){masks = masks = masks = 0xFF;display();delay(3000);if (dir == 1){dir = -1;masks = masks = masks = 0x80;} else {dir = 1;masks = masks = masks = 0x01;}}}void display(){int i, len = sizeof(masks)/sizeof(masks);for (i = 0; i < len; i++){shiftOut(PIN_DATA, clocks, MSBFIRST, masks);}}

author: Ian.M
author_rank: Super Contributor
timestamp: September 20, 2016, 06:54:55 pm
content: 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.

author: kicken
author_rank: Contributor
timestamp: September 20, 2016, 08:16:13 pm
content: 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. 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.

author: rstofer
author_rank: Super Contributor
timestamp: September 20, 2016, 08:52:25 pm
content: 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+supplyYou can just about bet that power glitches are at the root of your problem.

author: StillTrying
author_rank: Super Contributor
timestamp: September 20, 2016, 08:58:24 pm
content: 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.

author: Bskitter
author_rank: Regular Contributor
timestamp: September 20, 2016, 09:33:24 pm
content: 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 registersincreamentnextlight(); // this changes a value in the array to high}Some more help.https://www.arduino.cc/en/Tutorial/ShftOut23

author: Bskitter
author_rank: Regular Contributor
timestamp: September 20, 2016, 09:34:33 pm
content: maybe also try 0.1 ufd caps from the base of each transistor to ground

author: kicken
author_rank: Contributor
timestamp: September 20, 2016, 10:44:41 pm
content: Quote from: rstofer on September 20, 2016, 08:52:25 pmThanks. 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.

author: rstofer
author_rank: Super Contributor
timestamp: September 20, 2016, 11:54:32 pm
content: 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.