How to use DAC mode normal?

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.
Post Reply
Batman
Posts: 7
Joined: Sun Aug 26, 2018 6:04 pm

How to use DAC mode normal?

Post by Batman » Tue Jul 23, 2019 7:57 pm

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)

User avatar
jimmo
Posts: 660
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: How to use DAC mode normal?

Post by jimmo » Wed Jul 24, 2019 2:05 am

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.

User avatar
jimmo
Posts: 660
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: How to use DAC mode normal?

Post by jimmo » Wed Jul 24, 2019 7:20 am

I had a quick look, nothing obvious jumped out at me. Raised https://github.com/micropython/micropython/issues/4944

Batman
Posts: 7
Joined: Sun Aug 26, 2018 6:04 pm

Re: How to use DAC mode normal?

Post by Batman » Wed Jul 24, 2019 1:57 pm

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

Batman
Posts: 7
Joined: Sun Aug 26, 2018 6:04 pm

Re: How to use DAC mode normal?

Post by Batman » Thu Jul 25, 2019 2:36 pm

Great! The issue seems be fixed as per

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

Will a new dfu file become available?

User avatar
jimmo
Posts: 660
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: How to use DAC mode normal?

Post by jimmo » Thu Jul 25, 2019 11:34 pm

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.

Batman
Posts: 7
Joined: Sun Aug 26, 2018 6:04 pm

Re: How to use DAC mode normal?

Post by Batman » Thu Aug 01, 2019 4:54 pm

I flashed the new firmware and I can confirm this issue is solved. Great work.

Post Reply