Noise Issue with Teensy 4.1, Audio Shield, and PAM8403 Amplifier

sudharsan

Member
Hi everyone,

I’m working on a Teensy 4.1 audio project using the Teensy Audio Shield (SGTL5000) and a PAM8403 amplifier. The system plays audio from an SD card, but I’m consistently getting noisy output on the speaker connected via the PAM8403.
Below are my details and tests:

Hardware Details:
Microcontroller: Teensy 4.1
Audio Shield: SGTL5000-based Teensy Audio Shield
Amplifier: PAM8403, single-channel (right channel only connected).
Speaker: (Add details: e.g., 4-ohm, 3W, etc.)
Connections:
Teensy 4.1 and Audio Shield: Standard I2S connections.

LRCLK: Pin 20
BCLK: Pin 21

DIN: Pin 7
MCLK: Pin 23

PAM8403 Amplifier:
Input Signal: Right channel from Teensy Audio Shield (R pin).
Input Ground: GND of Audio Shield.
Power: 5V power supply GND with Teensy and Audio Shield).
Speaker: Connected to PAM8403 output pins.

Why does the PAM8403 produce noise while the other setups are clear?
Is there a way to improve the PAM8403’s performance with the Teensy Audio Shield?
Any recommendations for alternative amplifier setups or optimizations?




C:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1;        // xy=69,177
AudioFilterStateVariable filter1; // xy=309,92
AudioFilterStateVariable filter2; // xy=312,257
AudioMixer4 mixer2;               // xy=584,261
AudioMixer4 mixer1;               // xy=602,114
AudioAnalyzePeak peak1;           // xy=810,386
AudioAnalyzePeak peak2;           // xy=836,450
AudioOutputI2S i2s1;              // xy=899,223
AudioConnection patchCord1(playSdWav1, 0, filter1, 0);
AudioConnection patchCord2(playSdWav1, 1, filter2, 0);
AudioConnection patchCord3(filter1, 0, mixer1, 0);
AudioConnection patchCord4(filter1, 1, mixer1, 1);
AudioConnection patchCord5(filter1, 2, mixer1, 2);
AudioConnection patchCord6(filter2, 0, mixer2, 0);
AudioConnection patchCord7(filter2, 1, mixer2, 1);
AudioConnection patchCord8(filter2, 2, mixer2, 2);
AudioConnection patchCord9(mixer2, 0, i2s1, 1);
AudioConnection patchCord10(mixer2, peak2);
AudioConnection patchCord11(mixer1, 0, i2s1, 0);
AudioConnection patchCord12(mixer1, peak1);
AudioControlSGTL5000 sgtl5000_1; // xy=539,383
// GUItool: end automatically generated code

#define SDCARD_CS_PIN BUILTIN_SDCARD
void setup() {
  Serial.begin(9600);
  delay(200);
  Wire.begin();
  delay(200);
  AudioMemory(8);
  delay(200);

  sgtl5000_1.enable();
  delay(200);
  sgtl5000_1.volume(1);
  sgtl5000_1.dacVolume(1);

  delay(1000);

  while (!Serial && millis() < 3000);
  delay(200);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  mixer1.gain(0, 1);
  mixer2.gain(0, 1);
  pinMode(13, OUTPUT);
}

void loop() {
  playSdWav1.play("SDTEST1.WAV");
  while (playSdWav1.isPlaying()) {
    // Additional tasks can be performed here
  }
  delay(500);
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(500);
}
 
What kind of noise do you hear? Is it noise during playack from SD card?

What exactly is meant by "other setups"? Do you have another configuration where there is this noise not audible?

What power source are you using? Have you tried (as a test) to use different power sources for Teensy and the amp?
 
When I connect the power supply from the Laptop USB port noise will occurs and Other setup is that the connection between the teesny4.1 and the pam8403 through the audio shield.

-> for the teensy4.1 I am using laptop USB port
-> for Audio shield I get 3.3V from the teensy4.1
-> for the PAM8403 I get 5V from the teensy4.1

I have also tried with 5V power bank as a source, instead of using Laptop USB.
 
Hi,
These class D amps inject terrible amount of noise in power rails. The are in fact very difficult to use. I say that, but I use them a lot, since they are so efficient ! I can get rid of the noise doing this :
- try big cap (100 to 200uF) on amp + - power supply. USB specs discourage caps > 10 uF but I think most devices can handle it now.
- use as short as possible wires from amp to speakers. This really helps.
- use as short as possible power rails
- try to connect different GND to the amp - , or all of them
Grounding and short wires !

You can also use I2S amp like the MAX98357A. No noise, but not as much power, especially with basses.

Good luck !
Emmanuel
 
I’ve already tried the methods you’ve mentioned, including adding large capacitors (100-200uF) to the power supply, shortening the wires from the amp to the speakers, and minimizing the length of the power rails. I’ve also made sure to connect the different GNDs properly but same issue exists.Could impedance matching between the PAM8403 and the Audio Shield REV D be causing the issue?
 
I am still trying to understand:

What kind of noise are we talking of? Is the noise only present during SD-card playback? Or always?

Without the class D amp, connecting the line-out of the audioshield to another amplifier, there is no noise problem?
 
This Noise is what i am receving even without SD-card playback. With SD Card playback , I do get the sound but along with noise.
Right now i have checked only with class D amp.
 
If you disconnect the input signal and short both L and R inputs on the PAM8403 module to GND, is the noise still there?
If yes, the source is the amp and most likely the 5V power bus.
The output signal from the Audio board should be the Line OUT R (or L). There is another pin labelled R near the headphone jack.
teensy4b_audio_back.jpg
 
These amps are really a pain. If noticed also that some of them, depending of the supplier, are not exactly the same. Some avec smaller caps and tend to produce more noise. When you insert a cap, be sure to solder it directly on the amp, on + and - pins.
You can also try to insert a volume pot between the audio shield output and the amp. This way, the noise floor will be lower when listening at lower volume. A 10k pot do the job well.
 
I disconnect the input signal and short both L and R inputs on the PAM8403 module to GND, But Still the noise is there.Here I will attach the exact connection detail for your reference.
Audio_shield_conection_details.jpg

Note:
I couldnt stack the Audio shield and Teensy4.1, So I connect this by using single stand cables.
Ground connection between the teensy and audio shield is GND(near to pin 0) not G (near to 5V)
 
Ok, if the module, with it's inputs tied to GND still produces the noise, it is either: a bad board or dirty 5V supply rail.
More tests:
Disconnect the 5V line from the Teensy and try to power it from another source (powerbank maybe?) Teensy + Audio board gets the power from the USB, power amp from another source. Is the noise still there?
Audio_shield_conection_details2.jpg
 
Ok, if the module, with it's inputs tied to GND still produces the noise, it is either: a bad board or dirty 5V supply rail.
More tests:
Disconnect the 5V line from the Teensy and try to power it from another source (powerbank maybe?) Teensy + Audio board gets the power from the USB, power amp from another source. Is the noise still there?
View attachment 36734
I disconnect the 5V of PAM8403 from the teensy4.1 and powered up with 5V power bank, but still the noise is there,
and in this setup,But if i short both R G of PAM8403 and then power up the PAM8403 by using power bank, in this case I did not hear any noise.
 
We have the amp module, powered from the power bank and with inputs shorted being silent.
Noise is there if the R+GND are connected to the TeensyAudioBoard, am i correct?
I2S is relatively high speed interface, MCLK clocks everything inside the codec chip. It could be the wiring is affecting it.
Using the same setup with amp module powered from the power bank:
- connect the R+GND of the Audio Board to the power amp.
- disconnect the I2S and I2C wires between the Teensy and the Audio board, leave only the GND + 3.3V. This way the codec chip will be powered up, but won't be initialized and will not receive any data over I2S. In theory should output silence.
If there is no noise, that would indicate the noise is generated by the corrupted I2S data.
It is recommended to add a series termination resistor (100 Ohm) close to the Teensy MCLK pin (23), maybe it will help? Also make the I2S wires as short as possible.

I'd add 10k pull up resistors on the I2C bus if you don't have them yet.
 
Hello everyone, I try with new teensy4.1, I got the output without any noise, But I don't know what is the exact problem in the previous teensy4.1 (which I tried before), Once I found the Issue, I will let you know guys, thank you for your replay in your busy schedule. Thanks a lot for support.
 
Caveat, I am not calculating this, it is just a comment. You can decide if it is useful.

For my instrumentation work, I always filter the 5v supply, inductor with a resistor and two caps, like this:

1739142372069.png


And here is what it looks like assembled, the filter in in the lower right corner. This was hand assembled, tweezers, quickchip and a reflow oven from ebay,

Controller_T4_mounted.jpg




Another thing to look out for is long wires, and more so if not shielded and more so again with high impedance.
 
Interesting. I would like to test it, but the schematic résolution is low. Could you post a new schematic with higher resolution ?
Thank you
Emmanuel
 
Sure, here is the filter circuit by itself.

1739185963462.png



And here are the components from the BOM. If you use different components, keep in mind that low ESR is important.

C1 C5​
22uF​
CAP CER 22UF 25V X5R​
490-12389-1-ND​
L1​
10uH​
FIXED IND 10UH 1.2A 180 MOHM SMD​
587-2886-1-ND​
R11​
100R​
RES 100 OHM 1% 1/4W 0603​
10-ERJ-UP3F1000VCT-ND​



In case it might be of interest, here are links to my "controller" boards on github. These are simply carriers for a T4 and for a T4.1, with filtered power, SPI, digital i/o and analog inputs with protection diodes. The connectors are a "standard" that I have settled on for my instrumentation circuits.

https://github.com/drmcnelson/SPI-Instrumentation-Controller-T4.0
https://github.com/drmcnelson/SPI-Instrumentation-Controller-T4.1

The set of instrumentation boards are found at the following.

https://github.com/drmcnelson?tab=repositories

I am adding to the set as time and funds permit.


And you can find the instrumentation circuits
 
If power is from a USB cable, please know the USB 2.0 specification in section 7.2.4.1 "Inrush Current Limiting" on page 177 requires USB devices have no more than 10uF direct capacitive load.

Teensy 4.x already has about 2.6uF directly connected, and during its complicated startup sequence more groups of capacitors get charged via circuitry which isn't strictly compliant with the USB inrush limiting requirements, but hopefully not too far off.

Adding 44uF might cause issues with some USB hosts and hubs.
 
Last edited:
Hmmm.... probably a good point.

Perhaps it has not been an issue because I use powered hubs for everything, and they all have at least 1A (5W) per port.

But since you mentioned it, I will think about it a bit, and then probably update the carrier design to add something to manage the in-rush for the filtered power and peripherals.

I should probably look at the datasheet for the teensy's 3.3V LDO again too.

Thank you, that's very super helpful.
 
P/S having a bunch of 10uf bypass caps between power planes and ground is pretty routine. So this a broadly relevant issue.
 
1uF with 0.1uF right against the pin is sort of typical (but not universal) for analog chips.

10uF is typical for bypassing power planes. And they are distributed over the board almost copiously in low noise analog designs.
 
Back
Top