I’ve got a project where I have 2 LEDs being driven by Timer0 and an audio output using Timer1 and Timer2 (see PCM audio example). The timers shouldn’t ever interfere with each other.
The audio output is on digital pin 3 (OC2B) and the 2 LEDS are on digital pins 5&6 (OC0A and B).
However, when I set different values for LED brightness (using analogWrite), I can here a very quiet pulse wave on my audio output. This is definitely the PWM signal for the LEDs - I can hear the pulse width change as I change LED brightness.
Is it possible to get crosstalk between interrupt pins?
I’ve checked and there’s absolutely no programming that could create the very quiet pulse wave on the audio output. It must be a hardware thing, not a software thing.
If anyone else has had these problems, I’d be keen for ideas on how to reduce the interference.
It sounds to me like a power supply problem - the LEDs are causing a voltage drop somewhere. How do you have everything wired up?
A-ha! That just helped a lot. I was running from USB power. When I switched to an external 12V PSU (into Uno's DC socket), that just reduced the interference substantially. It's at least half the volume now.
The LEDs are going from digital pins 5&6 to 1k resistors and on to LEDs.
The audio output is from digital pin 3. Then through 4k/1k pot divider to get volume to line level. Then 2 stage LPF to remove PWM frequency, then big cap to remove DC offset (so can plug into audio input).
Actually just realised that the resistors were wrong values on LED, so they were right at the limits of their brightness. Now I've switched them to 1ks, the interference has gone completely. I also don't burn my retinas out when I look at the LEDs!
It will also help if you add some decoupling between the audio and digital sides.