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);
}