[sdiy] Coding digital waveforms
Jerry Gray-Eskue
jerryge at cableone.net
Thu Dec 17 15:01:35 CET 2009
Justin,
The easy answer first, <<to smooth the output>> using an active low pass
filter is best. The usual compromise is to use a fixed cutoff that allows
your highest desired frequency to pass and is well below the DAC update
rate. When generating wave forms it is possible to set the cutoff frequency
on the fly. Keep in mind that anything other than a Sine wave has higher
frequency harmonics that make up the wave shape and a high order filter is
slower to settle, for a LFO this should not be an issue, but when going for
high audio frequencies later it can matter.
As for coding, you approach is sound. The devil is in the details. For real
time applications you need to be aware of execution time for functions and
code segments. Speed is of the essence but so is predictable latency. To
lock into a real time frame you must base you code on the system clock and
timer to give you a timer Tic of know period. Your code must execute fast
enough to not ever miss a Tic. Optimize your code, even if it is only at the
high level language. Good algorithms are better than carefully optimized
assemble using poor algorithms.
Wave forms may also be generated on the fly i.e. calculated. This is
typically SLOW for Sine and some other wave shapes, but the math for Ramp,
Triangle, and Saw is a simple Line Plot and with optimized code may be done
on the fly. The advantage to calculated wave forms is no need to interpolate
values or have very large lookup tables to skip interpolation. This stuff is
all tradeoffs, there is no best way to do it, there are however ways that
will not work well or at all for a given system criteria.
There is way too much more to say, I may write a book one of these days.
Feel free to ask more specific questions.
- Jerry
-----Original Message-----
From: synth-diy-bounces at dropmix.xs4all.nl
[mailto:synth-diy-bounces at dropmix.xs4all.nl]On Behalf Of Justin Owen
Sent: Thursday, December 17, 2009 7:23 AM
To: SDIY List
Subject: [sdiy] Coding digital waveforms
Hello,
I've started writing some code for Arduino to output digital waveforms to
use as tempo synced LFOs - but was hoping for some general guidance in case
there's a better way of approaching it.
At the moment I'm just using a counter to increment through an array of
values that output to a DAC. It's a fixed frequency at the moment - but the
plan is to set up a variable to tell it how 'fast' to run through the
array - or how many of the values to use. It's basic and there's loads of
room for improvement - but so far it works.
So firstly - considering that my code game is pretty basic - is there a
better way of handling it than this?
and secondly - to smooth the output (which is obviously 'stepped' right
now) - should I be looking at some type of 'lag' circuit (i.e. the
resistor/diode/cap combo) - or something else?
Thanks again to everyone that helped with the whole
micro-DAC-Multiplexer-S&H set up . Works like a charm.
Cheers all,
Justin
_______________________________________________
Synth-diy mailing list
Synth-diy at dropmix.xs4all.nl
http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
More information about the Synth-diy
mailing list