Page 1 of 1

DAC.write() generates unexpected perturbation

Posted: Sun Oct 18, 2020 8:44 pm
by jgui
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
micropython.alloc_emergency_exception_buf(100)

def timerCbk(timer):
    global dac
    global y
    dac.write(y)

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

#case = 0
case = 1
#case = 2
if case == 0:
    dac.write(y)
elif case == 1:
    timer = pyb.Timer(4, freq=DacUpdateFreq)
    timer.callback(timerCbk)
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
case=0.png (236 KiB) Viewed 1964 times
case = 1:
case=1.png
case=1.png (250.24 KiB) Viewed 1964 times
case = 2:
case=2.png
case=2.png (240.4 KiB) Viewed 1964 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).

Re: DAC.write() generates unexpected perturbation

Posted: Mon Oct 19, 2020 5:54 am
by pythoncoder
I would suspect a grounding problem whereby changes in the instantaneous supply current are causing voltage spikes.