DAC differences between M0 and M4?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
OutstandingBill
 
Posts: 60
Joined: Fri Nov 29, 2019 3:22 pm

DAC differences between M0 and M4?

Post by OutstandingBill »

Hi!

I've noticed some interesting differences in the behaviours of the DAC on the Itsy M0 and the one on the Itsy M4. Here's a video of the observations.

I noticed these things:
- The quiescent voltage on the M0 is 1.5V, whereas on the M4 is 0V (default is 1.5V according to readthedocs).
- With my very slow sample rate (1sps), the M0 jumps to each sample point and stays there, whereas the M4 jumps to each sample point, and then starts to fall back towards 0V.
- Neither seems to be applying any interpolation - there is no smooth transition from one sample to the next.

Is anyone able to confirm that last observation (that's the bit I'm most interested in)? Perhaps if I supplied some undocumented optional parameters, it might interpolate? I'd also love to hear if there's some other approach I could use.

I'd also be interested to understand the differences, particularly why the M4 doesn't stick at a voltage between samples.

Background

I'm trying to build an LFO using an Itsy M4. One cycle of the LFO waveform might last as long as five seconds. I need the LFO to have a smooth output because step-wise changes can become audible in the analog circuit that uses the LFO, hence my interest in whether the DAC interpolates. My efforts until recently have centred around an algorithm to set the voltage on A0 every time a method is called (using the current time and LFO frequency to determine what the voltage should be), whilst also polling the sensors, etc. It occurred to me that I might be able to use something like audiocore.RawSample, so I used the code from the tutorial page and tweaked it a bit to give me more of an LFO-like frequency without requiring an unmanageably large array. The idea was to find out if the onboard DAC does any interpolation. I am pretty sure I would need it to interpolate in order to get a smooth-enough output from a sample small enough to fit into the M4's memory.

Here's the code I used when making the observations.

Code: Select all

"""CircuitPython Essentials Audio Out tone example"""
import time
import array
import math
import board
import digitalio
from audiocore import RawSample

try:
    from audioio import AudioOut
except ImportError:
    try:
        from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
        pass  # not always supported by every board!

button = digitalio.DigitalInOut(board.A1)
button.switch_to_input(pull=digitalio.Pull.UP)

tone_volume = 0.8  # Increase this to increase the volume of the tone.
frequency = 800  # Set this to the Hz of the tone you want to generate.
length = 8000 // frequency
sine_wave = array.array("H", [0] * length)
for i in range(length):
    sine_wave[i] = int((1 + math.sin(math.pi * 2 * i / length)) * tone_volume * (2 ** 15 - 1))

audio = AudioOut(board.A0)
sine_wave_sample = RawSample(sine_wave, sample_rate=1)

while True:
    if not button.value:
        audio.play(sine_wave_sample, loop=True)
        time.sleep(20)
        audio.stop()

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”