I really need help with DDS on the FRDM-KL25z Mbed

Thread Starter

digitalundernet

Joined Aug 22, 2012
10
This is making me feel really stupid but I need some help. I'm trying to make a Hybrid synthesizer for fun. With hybrid synthesis the VCO is replaced with a digital Oscillator.
With all the research papers I've read I've got the impression its really a matter of placing a value on the output pin from a look up table, basically a big array. So the formula boils down to print value from the LUT to the analog I/O and increment the counter, then repeat. I could use a separate chip to do the waveform generation but its sounded better to do it on the chip like the ESQ-1 does.
I haven't programmed in a few years but hitting such a simple roadblock is really frustrating. If anyone can help that would be amazing.
http://pastebin.com/QL9bGreA <---code
 

MrChips

Joined Oct 2, 2009
29,874
Welcome to AAC and I hope we can be of assistance (we meaning anyone of us on AAC).

Great. So you have given us an overview of what you are trying to do.
Googling ESQ-1 gives us some idea of what you are talking about. But your description lacks some clarity.

So lets get down to specific details.

1) You want to build a music synthesizer for fun.
2) You want to generate the musical note digitally using a digital oscillator, what ever that means.
3) What next? You lost me here.
 

Thread Starter

digitalundernet

Joined Aug 22, 2012
10
So my problem is when it comes to actually generating the waveform. The common way of doing this is called Direct Digital Synthesis (DDS). You have a lookup table of address and a loop that just moves to the next address. For audio we need to sample at 44100 times a second and adjust the accumulator. Here's a good example of it http://jeelabs.org/2011/12/04/generating-sine-waves-with-dds/

I've got the table and stuff going but like I said I havent programmed in quite a while so I keep getting noise on the output pin
 

MrChips

Joined Oct 2, 2009
29,874
I am still lost.

Forget the fact that you haven't programmed in a while.

What are you programming?

What do you mean by output pin?
 

Thread Starter

digitalundernet

Joined Aug 22, 2012
10
DDS is a form of wavetable synthesis. The end goal of the program is something that can generate sine/square/Triangle/ and random waves.

The output pin of the FRDM-KL25z microcontroller I'm programming this on.

Like this
 

ActivePower

Joined Mar 15, 2012
155
You are writing data to your analog pin continuously - won't that produce a distorted array of values. You said so yourself there needs to be a finite time period between two level transitions.

I am not very familiar with the mbed hardware's analog interface but knowing as it uses the ARM-Cortex MX processors, I'd venture it is a DAC. The lower-end uCs (8-bit ones) rely on PWM for DDS and since the PWM register is 8-bit it can assume values from 0-255 i.e. 0 V to 5 V. Depending on the resolution of your DAC (10 bit is fairly common on higher-end processors) you'd need to tune your lookup table accordingly.

Secondly, figure out how you want to space your values when you write them to the DAC. If you write them continuously you'd end up with a spaghetti of values trying to assert different voltages on the pin which would result in it becoming indeterminate - the noise which you refer to. Depending on the size of your lookup table and how fine you want your resulting wave to be it could vary from a few useconds to less (both the factors are inter-related).

IIRC there was an Atmel app note on DDS. Google for it.

HTH.
 

THE_RB

Joined Feb 11, 2008
5,438
I did some code here;
http://www.libstock.com/projects/vi...-notes-with-pic16-or-pic18-and-any-xtal-value

that will generate any musical note at extremely high note accuracy. Probably the best on the internet at the moment, the note accuracy is down to 0.0001 Hz if I remember right.

The code is in C so it can be adapted to your mbed project.

For wavetable DDS you can just use my code at a higher frequency than the note, and sequence the wavetable from that. For example, if you have a wavetable of 50 entries, generate the note at 50 times higher frequency then each event just output the new wavetable value.
 
Top