Page 1 of 1

Synchronizing DAC.write_timed() on DAC1 and DAC2

Posted: Sun May 07, 2017 8:31 am
by JoeGoodbread
I am trying to get a waveform on one dac channel, and a sync pulse on the second. The two should be synchronized to about 1 microsecond or so. Here's the code:

dac1 = DAC(1)
dac1.write_timed(buf_s,pyb.Timer(6, freq = fr* (l_buf)), mode=DAC.CIRCULAR)
dac2 = DAC(2)
dac2.write_timed(buf_t,pyb.Timer(7, freq = fr* (l_buf)), mode=DAC.CIRCULAR)

The waveform in dac1 precedes that in dac2 by about 25 microseconds. When I execute the code for dac2 before that for dac1, then dac2 waveform comes 25 us ahead of dac1. Tying both to the same timer doesn't help. buf_s and buf_t each contain 1600 values. fr is about 8 kHz.

Re: Synchronizing DAC.write_timed() on DAC1 and DAC2

Posted: Sun May 07, 2017 6:16 pm
by dhylands
To make them perfectly synchronized you'd need to setup the 2 timers to be slaves of a 3rd timer. Stop the 3rd timer, initialize the DACs and then start the 3rd timer.

MicroPython doesn't directly support the timer slave modes, so you'll need to peruse the datasheet to see what exactly needs to be setup. You can then use the stm module to read and write registers directly.

Re: Synchronizing DAC.write_timed() on DAC1 and DAC2

Posted: Tue May 09, 2017 8:33 pm
by JoeGoodbread
Thanks. I'm new to this, so will take some doing!