How to use DAC mode normal?
Posted: 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.
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.
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:
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)
Code: Select all
dac.write_timed(buffer, 20, mode=DAC.NORMAL)
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)