Decoupling capacitor help

Hello all,

This is a continuation post of a previous question in the Arduino Zero sub-forum (https://forum.arduino.cc/index.php?topic=420734.0). I am posting here because I have realised my problem is electronics and does not relate to Zero.

I have had problems with erratic circuit behaviour and after it was suggested to me that decoupling capacitors be added, I initially had no success. However with more careful testing I have found that they are definitely helping - but the result is not yet perfect. I therefore think that the problem could be to do with selection of correct capacitances, and possibly placement as well.

The circuit is an array of 8 shift registers (74HC165) being used to read 64 digital inputs. I am using a Due but have had similar problems with a Zero.

Here is a diagram of my circuit and the code used to read the inputs.

/*
   COMMENTS
*/
#include <math.h>

#define STRLEN 25

//dont use pins 0 or 1 it screws upload

#define ledCLKPin 2 // aka CLK
#define ledCSPin 3 // aka LOAD
#define ledDINPin 4 //MAX7219 Pin 1
#define cPin 26 // CP (26)
#define ePin 24 // CE (24)
#define pPin 22 // PL (22)
#define outputPin 28 // (28)
#define stepDelay 2

#include "LedControl.h" //  need the library
LedControl lc = LedControl(ledDINPin, ledCLKPin, ledCSPin, 1); //


// 1 as we are only using 1 MAX7219

char buffer[STRLEN];
int  bufferIndex = 0;

int readings[8][8]; // [0][0] is a1, [0][7] is a8, [7][0] is h1, [7][7] is h8
float voltages[8][8];

void setup()
{
  int intCounter = 0;
  Serial.begin(9600);
  pinMode(ledDINPin, OUTPUT);
  pinMode(ledCLKPin, OUTPUT);
  pinMode(ledCSPin, OUTPUT);
  pinMode(cPin, OUTPUT);
  pinMode(pPin, OUTPUT);
  pinMode(ePin, OUTPUT);
  pinMode(outputPin, INPUT);
  defaultSettings();

  //led setup

  // the zero refers to the MAX7219 number, it is zero for 1 chip
  lc.shutdown(0, false); // turn off power saving, enables display
  lc.setIntensity(0, 1); // sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen

  Serial.println("Completed setup().");
}

void defaultSettings()
{
  digitalWrite(cPin, LOW);
  digitalWrite(pPin, HIGH);
  digitalWrite(ePin, HIGH);
}

void loop()
{
  readAll();
  printArray(); //slows it down a lot!
  updateLED();
  //delay(scanDelay); //was delay 2
  Serial.println("Completed loop().");
}

void readAll()
{
  defaultSettings();
  delay(stepDelay);
  digitalWrite(pPin, LOW); delay(stepDelay); digitalWrite(pPin, HIGH); //refresh readings .. way delay 100
  delay(stepDelay);
  digitalWrite(ePin, LOW); //enable clock
  delay(stepDelay);

  for (int i = 0; i < 8; i++)
  {
    for (int j = 0; j < 8; j++) //order of readings given is A1..A8..H1..H8
    {
      digitalWrite(cPin, LOW);
      delay(stepDelay); //temp
      readings[i][j] = digitalRead(outputPin); //perhaps should reverse in order because chip outputs in reverse
      //voltages[i][j] = analogRead(A0) * (3.3 / 1023.0);
      digitalWrite(cPin, HIGH);
      delay(stepDelay); //was delay 10
    }
  }
}

void printArray()
{
  Serial.println("Array values: ");
  for (int i = 0; i < 8; i++)
  {
    for (int j = 0; j < 8; j++)
    {
      Serial.print(readings[i][j]);
    }
    Serial.print("   ");
    for (int j = 0; j < 8; j++)
    {
      Serial.print(voltages[i][j]);
      Serial.print(" ");
    }

    Serial.println();
  }
}

void updateLED()
{
  for (int i = 0; i < 8; i++)
  {
    for (int j = 0; j < 8; j++)
    {
      lc.setLed(0, i, j, readings[i][j]);
      //delay(25);
    }
  }
}

My problem is that the readings start to go awry the more switches are closed i.e. inputs into the shift registers reading HIGH. Before I added any capacitors this started to happen when more than 10 inputs were HIGH, now it’s stable up to about 45 but still starts to go wrong as I approach 64. The capacitors I have chosen so far are based on various tutorial examples so I would have thought they would be roughly right. I have cut the legs short and placed the IC capacitors right onto the Vcc pins of the 74HC165 chips.

Currently I am using capacitances as follows:

  • 10µF 16V Tantalum Bead Capacitor for Caps A and B
  • 0.1µF ceramic capacitor for Caps C1-8

My questions are:

  • Is the behaviour I am seeing (i.e. problem getting worse with increasing number of HIGH inputs) consistent with the decoupling capacitors being insufficient?
  • Does the max7219-driven LED array need decoupling (labelled as Cap A) and could that be affecting the shift registers even though it is on the 5v supply and the shift register circuit is on 3.3v?
  • What capacitances should I be trying for caps A, B and C1-8 to get it to start working more reliably?

As an aside, is there any reason why my trusty old Duemilanove continues to work perfectly without any decoupling capacitors while my Zero and Due need them?

Really appreciate any help anyone is able to provide.
Thanks,
Chris

It looks like you're using 1K pull-down resistors, and using 3.3V as VCC for the shift registers. With 45 switches closed, you'll draw 3.3 mA * 45 =~ 160 mA. I don't know how much spare power the Due's 3.3V regulator has. Is this too much? Would you be happier with a higher resistance for pull-downs - maybe, 10K?

We don't know how much power the LED array takes. Is it enough to threaten the 500 mA limit for USB power?

The routing for VCC and GND to the shift registers looks to be convoluted. You might want to consider taking power to each of the two banks of shift registers from the connection point, as opposed to the daisy chain arrangement that I think I see in the diagram.

Change the resistor values to 20k to 30 k.

And change the pull down to pull up resistors.

The decoupling capacitors must be as close to the power and ground connections on the chips and the leads of the capacitors must be kept as short as you can. The capacitors have to be of the ceramic type but the actual value is not important, anything between 0.1uF and 10nF will be fine.

While you're at it, get a jumper and measure the two power buses (3.3V and 5V) from one end of the breadboard to the other and verify that all bus voltages are "nominal")

Put a meter across both buses (one at a time) and monitor the buses after making all the recommended changes. Post the measurements for both buses.

Pull up, pull down, 1k, 10k, 20-30k.
Shouldn't we first ask what sensor is being used.
Leo..

What sensor ?

I saw something about switches.

Now I notice that you are using LED arrays. How many? These are likely to take a lot of current so you will need some larger bulk capacitors across the supply as well, 47uF to 1000uF is normal.

Thanks for all the input I will work through those.

Some immediate responses:
Despite trying to make the diagram as accurate as possible I don't think the resistors shown are correct so I will check what I am using and amend.

The sensors being used and fed into the registers are reed relay switches on the same 3.3v supply.

I am not using the USB supply I am using VIN at 7v.

The LED array is 8x8 driven by MAX7219 (http://www.ebay.co.uk/itm/MAX7219-Red-8x8-LED-Dot-Matrix-Display-Module-for-Arduino-5-dupont-line-CHIP-23-/221924728203?hash=item33abbe9d8b)

ultraproro:
The sensors being used and fed into the registers are reed relay switches on the same 3.3v supply.

Then 10k seems a reasonable value.
Pull up or pull down does not make any difference if your wiring is ok.
If you had to start over, use pull up resistors and connect the reed switches to ground.
Then there is no chance of shorting the supply to ground.
Leo..

You could use 20k. You won't see a difference and it will draw less current.

The wiring could pick up more hash if the resistor value gets too high.
I assume the chess pieces use magnets to close the reed switches.
If all 32 pieces are on the board, then total current draw with 10k resistors would only be ~10.5mA.
I doubt if the original 1k resistors (105mA) are the problem.
The Zero has AFAIK a 1Amp switching 5volt regulator, and an 800mA 3,3volt rail.
Leo…

Hi everyone. Many thanks again for all of your responses. I have looked again at my pull-down resistors and I am in fact using 1k Ohm resisters.

Based on many of the comments above I understand this is lower than recommended and may be the cause of the problem? If so, grateful if anyone could explain the problem here. Is it that as a result of the resistances being too low, too much overall current is allowed to flow? Is it because, when the inputs are HIGH, the low resistance on that resistor means that an unnecessarily large amount of current is allowed to flow to ground? Is there any reason then why pull down resistors shouldn't always be as high as possible?

I will change to 20k Ohm as recommended and report back.

As to the other points mentioned, I understand that the pull up vs pull down approach is more stylistic than critical. I see that using the pull up approach with grounded switches means there would be less risk of a problem due to a short in the circuit. However if the view is that the pull down approach should also work fine I won't change it at this point.

raschemmel: I'm afraid I don't fully understand the test you suggested. Is it designed to check for faults in the breadboard by checking voltage is consistent up and down the rails, or were you looking to test the current draw?

Thanks again all,
Chris

Put a meter across both buses (one at a time) and monitor the buses after making all the recommended changes. Post the measurements for both buses.

Some breadboard have red and blue power buses that are not connected in the middle.
You have to put a jumper in the middle of each of the buses to connect the left side to the right side. This is done to allow the user to run a 5V circuit on the left half while running a 12V circuit on the right half. The problem is that not everyone knows this and without the jumper in the middle all the circuitry on one side will be “dead”
Full sized breadboard.jpg

I suspected the low-valued resistors, because you reported that you had trouble when more of them carry current, and that you don’t have trouble when fewer carry current. I don’t have a strong reason to believe that’s the cause of the problem, other than that it would explain the symptoms that you see. It may be that the voltage regulator on the Due has plenty of oomph for this application. It may also be that the regulator goes into thermal limit well below its nominal current rating. Changing resistors is easy and cheap, so it seems like a good idea to me.

ultraproro:
Is there any reason then why pull down resistors shouldn’t always be as high as possible?

Yes. If the pull-some-direction resistors have too high a value, they might not reliably hold the input at the default voltage level in the presence of electrical noise.

raschemmel:
Some breadboard have red and blue power buses that are not connected in the middle.
You have to put a jumper in the middle of each of the buses to connect the left side to the right side. This is done to allow the user to run a 5V circuit on the left half while running a 12V circuit on the right half. The problem is that not everyone knows this and without the jumper in the middle all the circuitry on one side will be "dead"

Ah yes, thanks, I've certainly made sure they're connected up.

Rather than change all the resistors, if i just want to reduce the current flowing to ground, could i not just add one more large resistor in series?

ultraproro:
Rather than change all the resistors, if i just want to reduce the current flowing to ground, could i not just add one more large resistor in series?

No.

Think about it, that connects all your inputs together then one switch will affect the voltage on all inputs.

Reporting back on this - changing the resistors did indeed fix the problem.
I have also soldered up a (much more compact!) circuit on some strip board which I think has helped eliminate any lingering reliability issues from the breadboard connections.

MANY thanks to all for your help.