DAC.write() generates unexpected perturbation

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Posts: 4
Joined: Thu Nov 10, 2016 5:06 pm

DAC.write() generates unexpected perturbation

Post by jgui » Sun Oct 18, 2020 8:44 pm

For a project I need to generate a clean voltage profile and found an unexpected behavior when using DAC.write(): each call of this method generates a wave on the output, even when called with the same value.

So I try to use DAC.write_timed() and in this case this wave is not generated.

Amplitude of this wave:
- is proportional to DAC output (around 100mV (peak to peak) when the DAC output is close to max, around 0 when and DAC output is close to min).
- do not depend on other DAC parameters (buffering, bits).

Does anyone face this issue? Any idea of the root cause?

Here are some pictures to illustrate and corresponding code:

Code: Select all

from array import array
import micropython
from pyb import DAC

def timerCbk(timer):
    global dac
    global y

dac = DAC(1, bits=12, buffering=False)
DacUpdateFreq = 1000
y = 0

#case = 0
case = 1
#case = 2
if case == 0:
elif case == 1:
    timer = pyb.Timer(4, freq=DacUpdateFreq)
elif case == 2:
    buf = array('H', int(y) for i in range(128))
    dac.write_timed(buf, DacUpdateFreq, mode=DAC.CIRCULAR)
case = 0:
case=0.png (236 KiB) Viewed 348 times
case = 1:
case=1.png (250.24 KiB) Viewed 348 times
case = 2:
case=2.png (240.4 KiB) Viewed 348 times
I notice also that similar waves are visible every one second when only the REPL is running and each time a key is pressed in the REPL terminal on PC.
Also when the file system is accessed (saving a file to SD card for example), DAC output is perturbated.
Also some other pins are perturbated along with the DAC output (similar shape, wave amplitude always the same whatever DAC value).

User avatar
Posts: 4917
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

Re: DAC.write() generates unexpected perturbation

Post by pythoncoder » Mon Oct 19, 2020 5:54 am

I would suspect a grounding problem whereby changes in the instantaneous supply current are causing voltage spikes.
Peter Hinch

Post Reply