Page 1 of 1

How to use DAC mode normal?

Posted: Tue Jul 23, 2019 7:57 pm
by Batman
I am trying to output a block wave of given frequency and duration on pin x6 (DAC 2).

I can use the following to get output on pin x6. However, this seems to run forever.

Code: Select all

dac.write_timed(buffer, 20, mode=DAC.CIRCULAR)
I was hoping I could use the following code to send a predefined signal (in buffer) to the DAC at a given sample rate. However, the following does not result in any output on the pin.

Code: Select all

dac.write_timed(buffer, 20, mode=DAC.NORMAL)
Could someone explain to me what I am doing wrong? maybe I do not properly understand the difference between DAC.NORMAL and DAC.CIRCULAR? However, I can't find any documentation about what these flags are supposed to do.


I have posted a minimal, self-contained example below if someone wants to test it. This is a minimally working example:

Code: Select all

import math
import pyb
from pyb import DAC,delay

wave =  [255,0] * 10
buffer = bytearray(wave)

# This does produce a block wave on pin x6
print('Start 1')
dac = DAC(2)
dac.write_timed(buffer, 20, mode=DAC.CIRCULAR)

delay(5000)

# This does not give me any output on pin x6
print('Start 2')
dac = DAC(2)
dac.write_timed(buffer, 20, mode=DAC.NORMAL)
delay(2000)

Re: How to use DAC mode normal?

Posted: Wed Jul 24, 2019 2:05 am
by jimmo
I can repro this problem on a pybv1.1.

I think your understanding of CIRCULAR and NORMAL matches mine :) (Normal does a single transmission of the waveform, circular loops it).

I'll investigate and get back to you.

Re: How to use DAC mode normal?

Posted: Wed Jul 24, 2019 7:20 am
by jimmo
I had a quick look, nothing obvious jumped out at me. Raised https://github.com/micropython/micropython/issues/4944

Re: How to use DAC mode normal?

Posted: Wed Jul 24, 2019 1:57 pm
by Batman
Thank you for checking and raising the issue.

In case this informative, I have just installed this firmware version:

pybv11-20190722-v1.11-167-g331c224e0.dfu

Re: How to use DAC mode normal?

Posted: Thu Jul 25, 2019 2:36 pm
by Batman
Great! The issue seems be fixed as per

https://github.com/micropython/micropython/issues/4944

Will a new dfu file become available?

Re: How to use DAC mode normal?

Posted: Thu Jul 25, 2019 11:34 pm
by jimmo
I think they update daily, although there don't appear to be any pyb v1.1 nightly builds on the download page right now? If it doesn't show up later today I'll do a build for you and upload it somewhere.

Re: How to use DAC mode normal?

Posted: Thu Aug 01, 2019 4:54 pm
by Batman
I flashed the new firmware and I can confirm this issue is solved. Great work.