Changing DAC.write_timed() frequency on the fly

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
User avatar
mathieu
Posts: 20
Joined: Fri Nov 10, 2017 9:57 pm

Changing DAC.write_timed() frequency on the fly

Post by mathieu » Mon Feb 11, 2019 3:39 pm

After initiating a DMA transfer from a buffer to a DAC using DAC.write_timed() in DAC.CIRCULAR mode, is there any way to change the frequency at which the buffer is written to the DAC without a new call to DAC.write_timed()? For instance by acting on Timer(6)? My goal would be to imitate some kind of Doppler audio effect, so I need to preserve the contents of the buffer as well as the index of the last read buffer element.

Thanks.

User avatar
mathieu
Posts: 20
Joined: Fri Nov 10, 2017 9:57 pm

Re: Changing DAC.write_timed() frequency on the fly

Post by mathieu » Mon Feb 11, 2019 5:26 pm

Answering my own question based on a very quick test using a blinking LED connected to the DAC pin...

Yes, it seems to work (for the blinking LED at least) by calling Timer(6).freq(f), where f is the desired frequency. This is (to me at least) unexpected and delightful in its simplicity. I've been trying for a long time to simulate Doppler effects by on-the-fly modifications to the buffer. The solution was so much simpler and elegant...

I'll try to find time to experiment with real audio output and I'll post a minimal working example here.

Post Reply