testing pyboard DAC

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.
blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: testing pyboard DAC

Post by blmorris » Mon May 19, 2014 2:58 am

@brutor- I opened issue #617 on GitHub for this. https://github.com/micropython/micropython/issues/617
The problem with DAC2 was still present for me with the most recent code from the repo. I looked at the code, but nothing obvious jumped out at me (it would have to be pretty obvious for me to spot it ;) )
triangle wave: I read your original post about artifacts again more carefully, you were clear about the persistence of the artifacts at all frequencies. I'll look forward to seeing what it looks like on my analog scope when my boards come in (on its way, just a few days now…)
-Bryan

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: testing pyboard DAC

Post by Damien » Mon May 19, 2014 6:21 pm

Thanks for the bug report. I have now fixed the DAC(2) problem (it was linking to the DMA incorrectly).

I also fixed the documentation regarding casting to an int to store into the bytearray buffer.

Re the dual-modulated-triangle output: it could be that you are doing write_timed and triangle at the same time. If you do this, then the MCU adds both signals together.

Also, I don't think you can do write_timed on both DACs at the same time. This is a hardware limitation: there is only 1 DMA channel for both DACs. Although, they are on different streams, so it may be possible.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: testing pyboard DAC

Post by Damien » Mon May 19, 2014 7:36 pm

Okay, I tested using both DACs at the same time, using write_timed, and it works!

The limitation is that they must run at the same frequency. For example, doing:

Code: Select all

from pyb import DAC
dac1 = DAC(1)
dac2 = DAC(2)
buf1 = bytearray(128 + x for x in range(10))
buf2 = bytearray(128 - x for x in range(20))
dac1.write_timed(buf1, 100, mode=DAC.CIRCULAR)
dac2.write_timed(buf2, 200, mode=DAC.CIRCULAR)
then both DAC channels will output at a 200 Hz sample rate (the frequency of the last write_timed call).

This is a micropython limitation, and could be lifted with a more sophisticated DAC interface.

Also, I'm not quite sure how you would go about synchronising the DACs...

brutor
Posts: 8
Joined: Sun May 04, 2014 7:44 am
Location: Belgium

Re: testing pyboard DAC

Post by brutor » Tue May 27, 2014 9:23 pm

Hello Damien,
Thanks, indeed the 2 DACs are OK now with a timed write.
The little DAC test is running now, but strangly I have to shift the Y-points 1 position to the left to get the correct result compared to w2aew's logo.

Code: Select all

# -*- coding: utf-8 -*-
"""
Created on Sun May  4 08:05:40 2014

@author: Brutor

test DAC micropython
XY generation of the TEK logo on a 2445 oscillo
Inspired by w2aew's video : http://www.youtube.com/watch?v=344oEu9vo7w

"""

from pyb import DAC
from pyb import LED
#import math

dac_x = DAC(1)
dac_y = DAC(2)

# Turn on the blue LED
led = LED(4)
led.on()

# TEK Logo from w2aew - y_points shifted 1 position to the left

x_points = (10, 90, 90, 110, 130, 140, 140, 90, 90, 97, 113, 120, 90, 90, 100,
            150, 150, 170, 170, 195, 220, 190, 220, 195, 170, 170, 100, 85,
            77, 70, 72, 80, 90, 60, 60, 40, 40, 10)
            
y_points = (100, 80, 82, 74, 60, 40, 40, 50, 60, 60, 50, 50, 40, 30, 30,
            100, 100, 55, 80, 80, 45, 10, 10, 35, 10, 10, 13, 23, 40, 60, 72,
            80, 80, 10, 10, 80, 80, 100)

# place the points in a bytearray

buf_x = bytearray(len(x_points))
buf_y = bytearray(len(x_points))

for j in range(len(x_points)) :
    buf_x[j] = x_points[j]
    buf_y[j] = y_points[j]
    
# Write the TEK logo on the dac outputs
# DAC outputs are RC filtered with 10k - 10nF

dac_x.write_timed(buf_x, 2000, mode=DAC.CIRCULAR)
dac_y.write_timed(buf_y, 2000, mode=DAC.CIRCULAR)
and the result :
IMG_4914_1_v1.JPG
IMG_4914_1_v1.JPG (221.64 KiB) Viewed 6711 times
Not bad, there is clearly some noise on the DAC outputs ...

I'll continue to try to get the logo turning around.

Post Reply