Pyboard noise

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
gratefulfrog
Posts: 149
Joined: Sun Mar 01, 2015 12:10 pm

Pyboard noise

Post by gratefulfrog » Fri Oct 07, 2016 4:19 pm

Hello again...

As some may know, I am building an audio application with a pyboard.

I have discovered that polling an adc or an accelerometer seems to generate a "click" which is picked up by my amplification circuit (not part of the project).

Sadly, I poll 6 adc's and 2 accelerometers at every pass in the main loop.

This generates a ton of noise and is thus not usable.

Would anyone have a suggestion as to how to eliminate or reduce that noise?

As an example, the following code makes a tic, tic, tic... changing the delay only changes the frequency of the ticking..

Code: Select all

>>> x=pyb.ADC('X19')
>>> while True:
...     pyb.delay(500)
...     x.read()

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Pyboard noise

Post by Roberthh » Fri Oct 07, 2016 7:11 pm

That's hard to tell. Ears are very sensitive to the smallest signals. Possible sources & actions:
  • - noisy Vdd: the stm3232 has a separate VDDA/VSSA for the analog section, which are connected to the A3V3/AGND pins. Try to supply the PyBoard from stable power source, or/and add a capacitor (~100µ) between A3V3 and AGND
  • ground loop: separate the GND between Pyboard and your amplifier. Connect the amplifier at X19 and AGND

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Pyboard noise

Post by dhylands » Fri Oct 07, 2016 7:17 pm

pops and clicks can also happen due to timing differences between playback and capture

gratefulfrog
Posts: 149
Joined: Sun Mar 01, 2015 12:10 pm

Re: Pyboard noise

Post by gratefulfrog » Fri Oct 07, 2016 7:31 pm

Thanks for those 2 remarks.

I am not recording or playing back, just making connections between 4 audio sources. These are on a pcb, into which is plugged the Pyboard.

When I poll the pyboard accelerometers, I get a click in the audio signal.

The same when I poll the adcs.

I am really at a loss as to how to correct this.

I am not using the A3V3, nor the AGND pins at all, they are not connected to anything.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Pyboard noise

Post by Roberthh » Sat Oct 08, 2016 6:51 am

Even if you do not use A3c3 and AGND, you can connect a capacitor there to reduce the internal noise on the supply of the STM32's analog section. The internal capacitor is just 4µ7 sized.
You should power the PyBoard and the external Audio source PCB separately without any common supply line (GND of Vcc), and have just ONE GND connection between the two boards at the AGND pin of Pyboard.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Pyboard noise

Post by pythoncoder » Sun Oct 09, 2016 10:23 am

Integrating fast digital electronics with sensitive linear circuitry such as audio is one of the more, er, "interesting" aspects of electronic design. There are several ways in which the fast transients in the digital circuitry can be coupled into the linear circuits. As @Roberthh says, grounding is crucial. You really need a "star point" where the incoming external ground connection links to any chassis metalwork. The separate audio and digital grounds should be linked to the star point, each with a single wire. There should be no other connections between the grounds: this avoids loops which can pick up noise in two ways, by inductive coupling and by resistive voltage drops.

Noise can also be coupled capacitively. This can be reduced in two ways, by physical distance between the fast digital and the linear circuits and by shielding. In a shielded solution the Pyboard might be enclosed in a conductive enclosure, with a single wire linking the enclosure with the star point. Alternatively you might shield the linear circuitry or both. Obviously this is more hassle than getting the grounding right, so try that first.

Getting noise and hum out of audio kit can be something of a black art ;)
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Pyboard noise

Post by Roberthh » Sun Oct 09, 2016 6:15 pm

It would be interesting to visualize the playback of a well known signal (e.g. sine) after capturing with the noise, to tell, whether this is a timing problem, like Dave mentioned, or a superposition problem.

gratefulfrog
Posts: 149
Joined: Sun Mar 01, 2015 12:10 pm

Re: Pyboard noise

Post by gratefulfrog » Sun Oct 09, 2016 6:18 pm

Thanks for all that, I will be int he lab on Wednesday and try to set up the sinusoid capture experiment.

In the meantime, I continue to explore...

More news soon!
Thanks to all!
B

gratefulfrog
Posts: 149
Joined: Sun Mar 01, 2015 12:10 pm

Re: Pyboard noise

Post by gratefulfrog » Thu Oct 13, 2016 4:26 pm

Gentlemen PyBoarders, I have news to report.

First, again let me thank you all for your immense help and support!

I may have assumed that you knew my project, so let me give a few words of overview:
  • I use the Pyboard to drive a network of analog switches via spi.
  • These switches route signals from an electric guitar's pickups to the output plug, which is connected via a heavily shielded cable to an electric guitar amplifier.
  • I run the circuit from a battery to avoid input noise from a PSU.
  • The pyboard is powered from a Boost converter, outputting 5V to the Vin pin.
  • The ground is common to the entire circuit, including the amp ground.
  • The pyboard is connected to a linux pc, via usb, where I enter commands to the REPL via the linux 'screen' command.
In the following tests, I am not using my circuit or my code:
  • I do not import any program into the pyboard, only the pyb module . The pyboard is powered and connected to my PCB with the analog switches, that is all.
  • The electric guitar pickups are not connected to the circuit. So there is absolutely no input. It is simply floating.
I have now done some elementary testing to get all the info:

Test 0: Evaluate the Ambient Noise
  • With the amp cable NOT connected, but laying near the circuit, with the circuit NOT powered and NOT connected to the PC, turn on the amp to full volume.
  • There is a pretty loud hum. If I turn on/off room lights there is no additional noise.
    This level of ambient noise is normal.
Test 1: Establish the Circuit Noise Baseline
  • I plug the amp cable into the circuit, but the circuit is not powered. The amp is set to full volume.
  • The Pyboard is not connect to the battery or to the PC.
  • There is a steady hum. If I turn on a room light, there is a huge pop. I attribute this to the antenna effect of the PCB and wires hanging around it. But I am not 100% sure of that.
  • I call this hum the Noise Baseline.
Test 2: Compare powered Circuit Noise to Baseline Noise
  • Next, I power the Pyboard circuit and connect to the PC via USB.
  • The amp meter reads 51mA which seems perfectly normal and ok to simply power the Pyboard.
  • Remember, the pickups are not connected so there is no input to the circuit.
  • The Noise Baseline is mainly unchanged, their are some transient whistles as the pyboard powers up, but these dissipate and we get back to the Noise Baseline, perhaps slightly noisier, but not significantly so.
Test 3: Explore effects of Pyboard commands with the amp cable not connected
  • I power the Pyboard circuit and connect to the PC via USB.
  • I unplug the amp cable from the circuit.
  • I manually run digital reads, analog reads, accelerometer reads.
  • The Noise Baseline is unchanged, No audible change whatsoever.
Test 4: Explore noise generated by Pyboard Commands
  • I power the Pyboard circuit and connect to the PC via USB.
  • I plug the amp cable from the circuit.
  • Digital read:

    Code: Select all

    >>> p=Pin('X1',Pin.IN)
    >>> p.value()
    0
    >>> while True:
    ...     delay(100)
    ...     p.value()
    ...
    # I get a very faint ticking sound from the amp, faint, but audible,
     
  • Analog read:

    Code: Select all

    >>> a=ADC('X19')
    >>> a.read()
    564
    >>> while True:
    ...     delay(100)
    ...     a.read()
    ...
    # I get a slightly louder ticking sound from the amp, stronger than the digital read, clearly audible.
    
  • Accelerometer Reading:

    Code: Select all

    >>> x=Accel()
    >>> x.x()
    4
    >>> while True:
    ...     delay(100)
    ...     x.x()
    ...
    # I get a very clear and loud ticking sound from the amp.
    
At this point, I can see a pattern. So, now I see if I can eliminate the noise.

Put a 100n capacitor between the amp input and ground.
  • The noise level is much much lower than the Circuit Noise Baseline.
  • Run the same digital, analog and accelerometer read tests.
  • There is no audible ticking noise.
Put a 180p capacitor between the amp input and ground.
  • The noise level is still much much lower than the Circuit Noise Baseline, but higher than with the 100n capacitor.
  • Run the same digital, analog and accelerometer read tests.
  • There is very slight audible ticking noise.
I have tested the guitar pickups:
  • With the 100n cap, the sound is seriously muffled, like setting the guitar tone to very very low.
  • With the 180pF cap, the sound is slightly muffled, like setting the tone to 8/10.
  • Ideally, I would like to maintain 100% tone, but not have the ticking.
Voilà for the tests. I feel like I have progressed!

Now my question is the following:

Given that I can select the polling frequency in the code by using a delay, say 100 to 200 ms, I can obtain a ticking frequency of 5-10Hz.

Is it possible to filter that frequency, but not the rest of the audible range?

Any suggestions would be great!

Cheers,
Bob

User avatar
dbc
Posts: 89
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

Re: Pyboard noise

Post by dbc » Thu Oct 13, 2016 6:26 pm

The first thing that comes to mind is I suspect that filtering at the frequency at which the ticks occur is not going to be helpful. The noise is coming from the very fast rise- and/or fall-time of the tick itself, or perhaps the tick is a switching artifact from having some noise on the signals driving the switch controls. I'm trying to picture your schematic in my head, but it's a little fuzzy. It sounds like the only connections from the PyBoard are GPIO's controlling analog switch inputs, and shared ground/power. Is that correct? If so, then voltage spikes on the power rail or ground rail could be the cause, or perhaps ground-level shifting if the grounding between the analog switch and the PyBoard has "enough" inductance. Decoupling the "analog ground" on your switch from the digital ground of the PyBoard might be a useful experiment.

Post Reply