This is just a small note about how to generate waveforms when the Teensy Audio Library isn’t an option—for example, if you are trying to embed the DRV2667 in a much smaller or lower-cost application.
The most common way to do waveform synthesis on a generic microcontroller is to write waveform-specific routines that interact with a phase accumulator. Over here in the old, outdated WEFT repo you can see the phase accumulator code:
…as you can see, for each case of the wavetype we want to generate, we do a different operation on the phase accumulator variable called
phase. With each iteration of the main loop,
phase is incremented a tiny bit (the
phaseOffset), looping back around to zero once it hits 2𝜋. This works well and is easy to experiment with (ie, what happens if you change
phaseOffset?), but it is not very accurate in terms of reproducing exact frequencies. Also, adding waveforms or having them interact (summed, multiplied, etc) quickly gets complex.
But! Because Teensy comes with such an excellent Audio Library, we can make a more flexible signal-generation system like so:
…in this example, we start up one each of all our waveforms right at the beginning of the sketch, then use the mixer objects to suppress, sum, or highlight one or many waveforms as we wish. Keeping a static number of waveforms going all the time helps with memory usage, keeping it predictable, and allows frequency adjustments to be handled in a nice modular method on its own:
There is one more way, presently, to generate waveforms—with the DRV2667’s built-in waveform synthesis methods. Since it is pretty involved (but well-designed!), I’m going to focus on analog waveforms for now. Ask me about this when we’re wrapping up, though, as there are some cool features to expand upon!