@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
testing pyboard DAC
Re: testing pyboard DAC
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.
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.
Re: testing pyboard DAC
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:
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...
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)
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...
Re: testing pyboard DAC
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.
and the result :
Not bad, there is clearly some noise on the DAC outputs ...
I'll continue to try to get the logo turning around.
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)
I'll continue to try to get the logo turning around.