Author Topic: Touch Synth WIP: Atmega328pb unstable outputting audio over PWM into a speaker  (Read 1216 times)

ch_scr and 1 Guest are viewing this topic.

Offline chiptuneTopic starter

  • Contributor
  • Posts: 18
  • Country: us
The A-Star board has a 4.7uF decoupling capacitor - would that make that much of a difference?

If you mean C3 4.7 μF and R2 (1 Ω), then they are probably a requirement of the specific LDO datasheet (I can't see the LDO part number), as it specifies (I suspect) a minimum ESR (equivalent series resistance, some types of capacitor can have a value, which is too low, to work well), for that capacitor, to ensure it damps down oscillations (for stability).

So, it shouldn't matter, as you are not using an LDO.

In your PCB layout.  Are things like the crystal, its supporting (load) capacitors and the decoupling capacitors, very, very close to the IC pin(s), that need them?

Did you source all your parts from reliable sources?

I.e. Not from AliExpress/Ebay Chinese sellers, with x10 .. x50 parts for $0.25 total, for things that normally cost at least $2 each, everywhere else?
(Because of possible, fakes, rejected components, substandard-clones, reused components, faulty parts, etc).

Very, very close, on both the MCU and the amp. All my parts are from LCSC, the parts provider for JLCPCB.

I am now wondering specifically about the value 4.7uF because I can see it on the Nano schematic as well https://www.arduino.cc/en/uploads/Main/Arduino_Nano-Rev3.2-SCH.pdf

One last update: No more issues when I disable the crystal and use the internal oscillator instead (but of course the audio quality is now terrible). I am not sure what to make of that.

Should I have a ground plane behind a 20MHz oscillator and its copper traces?
Would the 4.7uF polarized capacitor have helped?
« Last Edit: July 14, 2024, 05:17:46 am by chiptune »
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4703
  • Country: gb
I'd suggest posting the PCB layouts.  Then people here can check it out, especially as regards things like the crystal section, missing or poorly placed decoupling capacitors (as already mentioned by another poster), and other things.
 

Offline chiptuneTopic starter

  • Contributor
  • Posts: 18
  • Country: us
I'd suggest posting the PCB layouts.  Then people here can check it out, especially as regards things like the crystal section, missing or poorly placed decoupling capacitors (as already mentioned by another poster), and other things.

I went over my PCB design and evaluated it against various posted guidelines and two things are clear violations from what I can tell:
1) I used vias on my crystal signal lines, didn't cross the audio output though
2) I violated the length tolerance for the audio differential pair - not sure I can do better because of the switching jack
3) not clear: I have a ground plane under the crystal - lots of differences of opinion here

What I don't understand is why I need the combination of 3 things to fail:
1) unpowered speaker
2) using the external crystal
3) high volume PWM output - either through the pot or through the code

It must be all 3 happening for things to fail - I can see how 2) and 3) together might cause interference, but I don't see what role 1) would play here.
« Last Edit: July 14, 2024, 08:04:54 pm by chiptune »
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4703
  • Country: gb
I went over my PCB design

I'm probably stating the obvious here.
I'll speak for myself.

If the PCB design is hidden away, in some secret black box.  I can't really see how you want me to help you with it.

Hand waving, some descriptions of what YOU think is wrong with it don't really help, that much.  As I can't see it.
 
The following users thanked this post: chiptune

Offline chiptuneTopic starter

  • Contributor
  • Posts: 18
  • Country: us
Sorry, spent some time getting my hands on a better oscilloscope. I now see an occasional and very momentary voltage drop across the MCU, from 5.2V to ~4.3V. I think that is the main issue. I have decoupling caps on one pin of the MCU (100nF and 1uF) but I don't think they are close enough and I should have done the same on AVCC. I think on the higher external clock this drop causes a brown-out. I am thinking of adding another 4.7uF as well as a 120uF bulk capacitor to be safe.

I also realized that I didn't pick a good crystal for the MCU. From the AVR hardware design guidelines: https://ww1.microchip.com/downloads/en/AppNotes/AN2519-AVR-Microcontroller-Hardware-Design-Considerations-00002519B.pdf
Page 16, Section 5.3:

"For the newer AVR PB, the recommended capacitor value range is 12 pF - 22 pF, the total capacitance (Ce + Ci + Cs) for each pin must not exceed 22 pF."

My crystal's load capacitance alone is 20pF, so I probably have 30pF to 40pF at XTAL. The diagram in the guide has a crystal with 9pF load capacitance and external capacitors of value 6.5pF each.

My power traces are also a bit too thin.

The top and bottom PCB design are attached. Thank you MK14.
« Last Edit: Yesterday at 05:56:09 pm by chiptune »
 
The following users thanked this post: MK14

Online ch_scr

  • Frequent Contributor
  • **
  • Posts: 844
  • Country: de
You're correct about the crystal. The ATmega328PB's datasheet gives 6pF internal capacitance per pin. Here they assume a stray of at least 3pF.
As per the formula (Ce+Ci=2Cl-Cs), your crystal (Cl=20pF) would need a Ce of 30pF.
Since the Appnote claims "For the newer AVR PB, the recommended capacitor value range is 12 pF - 22 pF, the total capacitance (Ce + Ci + Cs) for each pin must not exceed 22 pF.", and Ci=6pF; Cs assumed 3pF, Ce max would be 13pF. Since 12pF is a standard value, that seems good.
That would need a crystal with Cl=10pF. If you go for a Cl=9pF one you'd need 10pF Ce. Both those options seem fine to me.

For the decoupling capacitors, as a general rule, put one on each IC power pin (Vreg, logic IC, VoltReg, Opamp, etc.).
Look at the datasheet values but if unsure 100nF is a happy place. Those should be as close as possible to the IC power pin.
The ground pad of a capacitor should have a gnd via next to it's pad. The gnd pin of a IC should have a gnd via next to it's pad.
This provides ground plane stitching, but also (more importantly) allows the high frequency currents to take the shortest path.
(One should think about those currents while layouting and provide a path for them. An unbroken gnd plane is best.)
The bigger the decoupling capacitor value, the further away it can be located from the IC pin. (The position you have them now would be OK for 1uf)
Always check voltage regulator datasheets for the recommended supply decoupling.
MLCC have a voltage dependend de-rating. Make sure how much of your e.g. 1uF is actually left at used vs. rated voltage for the used dielectric.
« Last Edit: Yesterday at 08:19:23 pm by ch_scr »
 
The following users thanked this post: MK14, chiptune

Offline chiptuneTopic starter

  • Contributor
  • Posts: 18
  • Country: us
Thank you! The AVR guidelines also include a 4.7uF and I keep wondering if omitting that is the cause of what looks like brown-outs in my PCB.
Do you think I'd need the bulk capacitor as well given that I have an amp onboard?

I also measure the current on the 8Mhz internal oscillator at full volume and I am withdrawing ~260mA. Do you think my power traces at 0.381mm are sufficient?

Thank you again.
 

Online ch_scr

  • Frequent Contributor
  • **
  • Posts: 844
  • Country: de
A bit of extra bulk capacitance isn't hurting. When ordering a pcb, pads, like vias, are essentially free.
So it's easier to provide some extra and populate as needed. The trace width seems fine to me. Isn't there no recommended bulk capacitance in the amplifier datasheet?
Here's a trace width calculator.
My suspicion is the lack of decoupling / bad layout (especially with respect of ground return currents from the decoupling caps) is to blame.
 
The following users thanked this post: MK14

Offline xvr

  • Frequent Contributor
  • **
  • Posts: 373
  • Country: ie
    • LinkedIn
The crystal is located too far from the MCU. Ideally, the pins of the crystal should be directly connected to the pins of the microcontroller, and no other traces should cross these connections.
You have plenty of room to move the crystal closer.

And decoupling capacitors - as already said.
 
The following users thanked this post: MK14


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf