Skip to content

Basic Signal Generation

Nick Johnson edited this page Jul 30, 2015 · 1 revision

Basic sinewave generation with the Tsunami

The Tsunami is capable of generating waveforms from DC all the way up to 2 megahertz. The Tsunami has a really easy to use Arduino library that makes doing this really straightforward. Here's the code to initialize the Tsunami and set the frequency to 440Hz - A4, for those of you who make music.

void setup() {
    // Initialize the Tsunami
    Tsunami.begin();
}

void loop() {
    Tsunami.setFrequency(440.0);
}

By default, the Tsunami will output at its loudest amplitude - 6 volts peak to peak - and with 0 DC offset. We can adjust those parameters just as easily as setting the frequency:

void main() {
    Tsunami.setAmplitude(1.0); // 1 volt peak-peak
    Tsunami.setOffset(-1.0); // -1 volt DC offset.
    Tsunami.setFrequency(440.0);
}

Let's make things a little more interesting and demonstrate how to do a frequency sweep. Let's do it musically, going up in octaves:

void main() {
    float frequency = 110.0;
    while(frequency < 8000.0) {
        Tsunami.setFrequency(frequency);
        frequency *= 1.05946309;
        delay(500);
    }
}

First, we set the starting frequency to 110 hz - A2 - and tell the Tsunami to output it. Then, we multiply the frequency by 1.05.... This is the twelfth root of two, which is to say that it will take 12 steps to double the frequency: that's the number of notes in an octave. Next, we delay half a second, and the loop repeats again until we reach 8 kilohertz - just after playing the musical note B8.

If you hook a speaker up to the Tsunami while it's running this code, you'll hear a series of musical scales, with notes half a second apart. Easy!

Clone this wiki locally