Synchronizing DAC.write_timed() on DAC1 and DAC2

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
JoeGoodbread
Posts: 10
Joined: Sun Apr 30, 2017 8:52 pm

Synchronizing DAC.write_timed() on DAC1 and DAC2

Post by JoeGoodbread » Sun May 07, 2017 8:31 am

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.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

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

Post by dhylands » Sun May 07, 2017 6:16 pm

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.

JoeGoodbread
Posts: 10
Joined: Sun Apr 30, 2017 8:52 pm

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

Post by JoeGoodbread » Tue May 09, 2017 8:33 pm

Thanks. I'm new to this, so will take some doing!

Post Reply