[sdiy] Hardware/software LFO Designs
Tom Wiltshire
tom at electricdruid.net
Sun Jul 4 18:41:27 CEST 2010
On 4 Jul 2010, at 16:40, MTG wrote:
> OK, so I'm thinking of adding an LFO to a microcontroller based project, but I'm a total newbie at it. What I'm thinking to start with, is using an internal CPU hardware timer (one of those standard 16-bit compare/capture thingies) at "X" times the LFO rate to lookup into a table for sine, triangle, ramp, etc... then fed to a DAC. The DAC itself is 12-bit, but I don't need or want to consume my whole CPU space with lookup tables. The CPU has other things to do too. ;-)
>
> The LFO would be sub 1 Hz to maybe 100+ Hz if I can squeeze that out of the micro. I suppose for some waveforms it might be easier to calculate the LFO value on the fly. Anyone got a feel for how many bits you need to make a decent wave without nasty (unintended) distortion? This isn't meant to be ultra-hi-fi, at least not as a first pass, but I don't want it to be crap either. I could easily fit a few 4-bit, 6-bit, 7-bit or 8-bit lookup tables in.
>
> Any project sites you can think of to get my juices going? This one was kind of interesting:
>
> Voltage Controlled LFO (VCLFO 9D):
> http://www.electricdruid.com/index.php?page=projects.lfo9
Thanks for the plug, GB!
My experience with the above project was that even a 10-bit output can produce an output in which digital steps are mostly imperceptible. The underlying waveform data is all 8-bit, but the final multiplication gives a 16-bit result, of which the top 10-bits are used for the output. So it isn't even really a true 10-bit output. But mostly you wouldn't know it's digital. Obviously if you really push it, you can tell - slow sweeps of hi-res filters and such like show some steeping on certain waveforms.
Your suggested design is slightly different to mine, in that you're talking about a variable sample rate, whereas I had a fixed sample rate of 19.5KHz. I'd be interested to know what difference this makes, if any.
The trouble spots are slow waveforms with steep slopes. On my LFO I have a 'Spike' wave which is the worst case. The trouble is that with only 256 entries in the waveform table, when the slope is steep adjacent values in the table will differ widely. This is not a problem that can be solved by more vertical resolution. You could use 16-bit values in the table, but they'd still be very different one from the next (just more accurate!). Instead, you need to make the wavetable longer so that there are more intermediate values, and hence smaller steps one to another. In my ADSR code I used interpolation to fill in extra values, essentially turning a 256 entry wavetable into a 255 segment linear approximation to a curve. The improvement is significant.
HTH,
Tom
More information about the Synth-diy
mailing list