Rewriting DMA source buffer for DAC output

Status
Not open for further replies.

jajanizer

Member
Hi all!
I'm implementing a very similar system to this example, which outputs a sine wave using the DMA. But, I'd like to be able to repopulate the source buffer with different wave forms. When I do this, about half of the time, it works perfectly, but the other half of the time, the output waveform contains many (or mostly) random values.

My method for repopulating the table is based off a simple Direct Digital Synthesis (DDS) algorithm, and copies the new waveform in from a lookuptable (LUT):

Code:
int place = 0;
for(int i = 0; i<bufferlength; i++) {
      sourcebuffer[i] = LUT[place];
      }
      place = place + M;   //M is the tuning word, used to skip through the lookup table to change output frequency
      if(place >= lengthLUT) {
        place = place - lengthLUT;
      }
    }
dma.sourceBuffer(sourcebuffer, sizeof(sourcebuffer));

Any ideas what might be causing this?
 
Oh, neat, thanks! Looking through the code, I'm a bit confused as to why you're calling sine_fill so many times, instead of just calling it once and filling it completely in one shot?
 
The sketch is just a proof of concept. The sine_fill is just used to put some "arbitrary data" into the raw_data buffer (more than a few sample-size chunks of data) so that with a scope you can see that signal is changing (different frequency sine waves) and thus conclude the real-time DMA buffer updates are in fact happening.

In the audio library, the raw data is coming from a WAV file or whatever, and is being ping-ponged into the DMA buffer as the done/half-done interrupt fires.
 
Status
Not open for further replies.
Back
Top