Sound from Arduino Leonardo Board when using PWM Outputs

I’m not entirely sure if this is a programming question, or an electronics question, but hopefully someone can put it in the right place if I chose incorrectly.

I have an Arduino Leonardo controlling seven identical white LEDs through a high-impedance current driver I designed. Four channels (pins 10, 9, 6, and 5) which when I send them PWM commands using analogWrite() with no special configuration work perfectly. No sound, dims properly.

Three channels (pins 13, 11, and 3), when I send them PWM commands using the same commands cause the Arduino board to make an audible buzz. It’s reminiscent of what I have seen before on my control boards which used inductors in switching regulators, but they had the excuse of, well, an inductor. These make no sense, as my driver boards are not only linear regulators, but are also completely identical on every channel. So, the actual output that the Arduino sees should be completely identical between all seven channels. And yes, I am sure the sound is coming from the Arduino board, not my driver board, although I can’t pinpoint which component it is.

Does anyone have a clue as to why some channels PWMing a mere 0.3mA load are making noise while the others do not? It’s not a critical bug, but it’s strange and I’m curious if others using Leonardo see the same behavior on pins 3, 11, and 13.

Here is a video of the phenomena, hopefully you can pick up the sound. The colors are from filters, the underlying white LEDs are completely identical. The slightly high pitched squeal is inaudible, I never noticed it until this video. It’s the lower pitched buzz that is audible and a bit annoying.

This is the code running in the video. I left it as a simple state machine for clarity.

/*

*********************************
* Created 5 Nov 2013            *
* Copyright 2013, Brian Neltner *
* http://saikoled.com           *
* Licensed under GPL3           *
*********************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

A copy of the GNU General Public License can be found at
http://www.gnu.org/licenses/gpl.html

*/

#define steptime 5 // Delay between steps.
#define writevalues() for (int i=0; i<7; i++) analogWrite(outputmap[i], outputvalue[i]); // inline writing function

byte outputmap[7] = {13, 11, 10, 9, 6, 5, 3}; // Define mapping from output channel to pin.
byte outputvalue[7] = {0, 0, 0, 0, 0, 0, 0}; // Starting intensities.
byte mode; // Mode is the state machine position. 0 is booting.

void setup() {
  // Setting pins as outputs and initializing output value.
  for (int i=0; i<7; i++) {
    pinMode(outputmap[i], OUTPUT);
    analogWrite(outputmap[i], outputvalue[i]);
  }  
  mode = 0;
}
  
void loop()  {
  switch (mode) {
    case 0:
      outputvalue[0]++;
      if (outputvalue[0] == 255) mode = 1;
      break;
    case 1:
      outputvalue[0]--;
      outputvalue[1]++;
      if (outputvalue[1] == 255) mode = 2;
      break;
    case 2:
      outputvalue[1]--;
      outputvalue[2]++;
      if (outputvalue[2] == 255) mode = 3;
      break;
    case 3:
      outputvalue[2]--;
      outputvalue[3]++;
      if (outputvalue[3] == 255) mode = 4;
      break;
    case 4:
      outputvalue[3]--;
      outputvalue[4]++;
      if (outputvalue[4] == 255) mode = 5;
      break;
    case 5:
      outputvalue[4]--;
      outputvalue[5]++;
      if (outputvalue[5] == 255) mode = 6;
      break;
    case 6:
      outputvalue[5]--;
      outputvalue[6]++;
      if (outputvalue[6] == 255) mode = 7;
      break;
    case 7:
      outputvalue[6]--;
      outputvalue[5]++;
      if (outputvalue[5] == 255) mode = 8;
      break;
    case 8:
      outputvalue[5]--;
      outputvalue[4]++;
      if (outputvalue[4] == 255) mode = 9;
      break;
    case 9:
      outputvalue[4]--;
      outputvalue[3]++;
      if (outputvalue[3] == 255) mode = 10;
      break;
    case 10:
      outputvalue[3]--;
      outputvalue[2]++;
      if (outputvalue[2] == 255) mode = 11;
      break;
    case 11:
      outputvalue[2]--;
      outputvalue[1]++;
      if (outputvalue[1] == 255) mode = 12;
      break;
    case 12:
      outputvalue[1]--;
      outputvalue[0]++;
      if (outputvalue[0] == 255) mode = 1;
      break;
    default:
      break;
  }
  writevalues();
  delay(steptime);
}

on arduino UNO some PWM output have doubled(?) frequency, because their timer is used also for millis(). Probabily this “trick” is also used in leonardo, and with those pin (pins 13, 11, and 3).

I assume the sound is generated by your driver, so we need the schematics and maybe BOM used to assembly it

Thanks for the info about the frequency doubling, that could definitely be why I am hearing different tones (the lower one being much louder) on the different pins. Maybe I'll modify the register values to bring them all up to a higher PWM clock source.

I disconnected the Arduino from the driver board, and with no load the sound does go away, so clearly it is the interaction between the two at some level. However, the sound itself is distinctly coming from the Arduino, and upon listening very closely it sounds as if it is actually coming from the physical microcontroller chip. The driver boards themselves make absolutely no audible sound, which I designed them specifically not to do by avoiding switching supplies.

This is the schematic. As you can see, it's all resistors plus a transistor. With the 10k resistor on the input, and a 5V supply, there's no way that it should be trying to source more than 0.5mA. This is hardly a large load.

(sorry, I've tried several times to get the image tag to work and it's not. If you can't see the above, check here: http://postimg.org/image/ojkinfqnn/)

I'm almost more inclined to think that noise on the 5V or GND lines is causing the chip to make strange noises than anything else, but that's pretty difficult to test since I have just one 30W supply for the whole thing. Still, the LED driver board has an independent ground path and it's set up in a star topology as all noise reduction techniques would suggest. It shouldn't really be a huge deal.

It's very strange that such a tiny current would cause these issues, and I see no way that those outputs would be asking for more than that 0.5mA.

Hmm, I disconnected one board's "POWER" side, but left ground connected such that current should have been flowing into the system from the control side. This resulted in no sounds from the Arduino board.

At this point, I can imagine two possibilities. One is that I am severely mistaken in how transistors work, and something very strange is happening that is somehow looping back into the Arduino. Two is that this is noise on the 5V/GND line that is mucking around with perhaps the internal oscillator on the microcontroller or something similar. Maybe it's normally bypassed enough that it's not a problem, but I am sinking 600mA at a time on this secondary board.

You didn't seem to link to the picture, but to some other link.
I can see this quite large picture (hope it's not from some buffer).

Edit: just checked with an other browser and this img appears, so should be fine.

Your embedded image is not showing up on my browser either, not sure what’s the deal. My browser lately seems to be very badly broken, so I’ll blame my computer if it’s working for you.

I also experience high pitch sound from Arduino Leonardo board, same as yours in the video you've posted.
I'm driving LED matrix , I don't use analogwrite() in my sketch but I use millis(), shiftOut() and port manipulation.
Pins I'm using are 8,9,10, 0,1,2,3,12,11.
I don't know what part on the Leonardo board make this sound, maybe crystal or mcu?
I added capacitors wherever I could, but no avail.