Skip to content
Nick Johnson edited this page Jun 6, 2015 · 2 revisions

Reference

Table of contents

  1. Output functionality
  2. sleep()
  3. reset()
  4. setAmplitude()
  5. setFrequency()
  6. selectFrequency()
  7. setOffset()
  8. Input functionality
  9. measurePeakVoltage()
  10. measureCurrentVoltage()
  11. measureFrequency()
  12. measurePhase()
  13. Auxiliary functionality
  14. enableSignOutput()
  15. disableSignOutput()
  16. enableAuxiliaryFiltering()
  17. disableAuxiliaryFiltering()

Output functionality

sleep()

Description

Puts the signal generator on the Tsunami to sleep, if true, or wakes it up, if false.

When the signal generator is asleep, it stops generating a signal, but otherwise continues operating as normal; when woken up again it will continue as if nothing happened.

Syntax

Tsunami.sleep(asleep)

Parameters

  • asleep: Whether or not the signal generator is asleep (boolean).

Example

Tsunami.sleep(true)

reset()

Description

Puts the signal generator on the Tsunami into or out of reset.

When the signal generator is in reset, it still accepts commands such as setFrequency, but the output is held at mid-scale (the value set by setOffset). As soon as reset is disabled, the Tsunami will start generating a signal again.

Syntax

Tsunami.reset(inReset);

Parameters

  • inReset: Whether or not the signal generator should be held in reset.

Example

Tsunami.reset(true);

setAmplitude()

Description

Sets the amplitude (voltage range) of the Tsunami's output signal, in millivolts. The amplitude is the difference between the lowest voltage the Tsunami outputs and the highest value it outputs, so an amplitude of 3000 millivolts would mean that it swings from -1.5 volts to 1.5 volts, or from 0 volts to 3 volts, depending on the value passed to setOffset.

Syntax

Tsunami.setAmplitude(amplitude)

Parameters

  • amplitude: The desired amplitude of the output signal, in millivolts. 1 volt is 1000 millivolts.

Example

Tsunami.setAmplitude(1024); // Sets the output amplitude to 1.024v.

setFrequency()

Description

Sets the output frequency for the signal generator, in hertz.

When only one parameter is provided, this function both sets the output frequency and seamlessly switches to generating it.

When two parameters are provided, this function sets one of the two frequency registers to the desired frequency, but does not change which frequency register is currently selected; this must be done with selectFrequency. Note that changing the frequency of the currently selected register when the signal generator is not sleeping or in reset may lead to glitches in the output signal.

Syntax

Tsunami.setFrequency(frequency)
Tsunami.setFrequency(register, frequency)

Parameters

  • register: Specifies which frequency register to set the frequency for. The signal generator has two frequency registers, numbered 0 and 1.
  • frequency: Specifies the frequency to set. This may be an integer or a floating point number; if concerned about code size and speed, try and use integers wherever possible.

Example

Simple usage to change the output frequency:

Tsunami.setFrequency(32768); // Starts outputting at 32,768Hz

Advanced usage to permit quickly toggling between two frequencies (frequency shift modulation):

Tsunami.reset(true);
Tsunami.setFrequency(0, 1200); // Set frequency register 0 to 1200Hz
Tsunami.setFrequency(1, 2400); // Set frequency register to 2400Hz
Tsunami.reset(false); // Start generating a signal again

while(true) {
    Tsunami.selectFrequency(0); // Generate 1200Hz
    delay(100); // Delay 100 milliseconds
    Tsunami.selectFrequency(1); // Generate 2400Hz
    delay(100); // Delay 100 milliseconds
}

selectFrequency()

Description

Selects which of the two frequency registers to use to generate an output signal on the Tsunami.

Syntax

Tsunami.selectFrequency(register)

Parameters

  • register: Select which frequency register should be used to generate the output signal. The signal generator has two frequency registers, numbered 0 and 1.

Example

See [setFrequency][#setFrequency] for a detailed example.

setOffset()

Description

Sets the offset voltage for the signal generator, in millivolts.

The offset voltage defines the voltage that the output signal is centred around. With an offset voltage of 0 (the default) and an amplitude of 1 volt, for instance, the output signal will go from -0.5 volts to 0.5 volts. With an offset of 0.5 volts and an amplitude of 1 volt, the output signal will go from 0 volts to 1 volt.

Offset may be any value from approximately -3.3 volts to 3.3 volts, but if the offset plus the amplitude exceeds approximately + or - 4 volts, the output may be clipped.

Syntax

Tsunami.setOffset(offset)

Parameters

  • offset: The offset voltage, in millivolts.

Example

// Generate a signal from 0 to 1 volt.
Tsunami.setAmplitude(1000);
Tsunami.setOffset(500);

Input functionality

measurePeakVoltage()

Description

Measures the peak positive voltage on the Tsunami's input connector, returning a value in millivolts. For instance, using this to measure a voltage that varies between +1V and -0.5V will return a value around 1000.

Syntax

int peak = Tsunami.measurePeakVoltage()

Example

int peak = Tsunami.measurePeakVoltage();
Serial.print("Peak voltage: ");
Serial.println(peak);

measureCurrentVoltage()

Description

Measures the current voltage on the Tsunami's input connector, returning a value in millivolts. This is only useful for slow moving signals (10KHz or less).

Syntax

int voltage = Tsunami.measureCurrentVoltage()

Example

int voltage = Tsunami.measureCurrentVoltage();
Serial.print("Current voltage: ");
Serial.println(voltage);

measureFrequency()

Measures the frequency of the signal on the Tsunami's input connector, returning a floating point number in hertz. Presently, this works for signals between approximately 32Hz and 8MHz, and has very high accuracy.

If the Tsunami is unable to accurately measure the frequency (for instance, because it has just changed dramatically, or because there is no input signal), it will return NAN.

Syntax

float frequency = Tsunami.measureFrequency()

Example

float frequency = Tsunami.measureFrequency()
Serial.print("Frequency: ");
Serial.println(frequency);

measurePhase()

Description

Measures the phase of the signal on the Tsunami's input connector, relative to the signal on the Tsunami's output connector. Returns a floating point number between 0 and 1.

This is useful when you want to measure the delay caused by a circuit you are testing by connecting both the Tsunami's output and input to it. If the input signal is not in some way generated or caused by the Tsunami's output, this function will return nonsensical and inconsistent results.

A phase of 0 indicates the signals are exactly in sync, while a phase of 1 indicates they are 180 degrees out of sync. Phase differences greater than 180 degrees will be 'mirrored' - so a phase difference of 181 degrees will return the same value as a phase difference of 179 degrees.

Syntax

float phase = Tsunami.measurePhase()

Example

Serial.print("Phase difference at 10KHz: ");
Tsunami.setFrequency(10000); // Output 10KHz
sleep(100); // Wait a while for the phase to catch up
float phase = Tsunami.measurePhase(); // Measure and print the phase difference
Serial.println(phase);

Auxiliary functionality

enableSignOutput()

Description

Configures the auxiliary connector on the Tsunami to output a square wave. The square wave is high when the output signal on the main connector is above its midpoint, and low when the output signal is below its midpoint. This is a convenient way to generate a 5V square wave from the Tsunami.

Note that when generating high frequency signals above about 1MHz, the square wave may have significant jitter - that is, it may vary in period from cycle to cycle - unless the frequency you are generating is an exact fraction of 16MHz.

Syntax

Tsunami.enableSignOutput()

disableSignOutput()

Description

Disables sign output on the Tsunami's auxiliary connector. See enableSignOutput for details.

Syntax

Tsunami.disableSignOutput()

enableAuxiliaryFiltering()

Description

Signals output on the Tsunami's auxiliary connector can optionally be filtered, or rectified, to produce a voltage instead of a square wave. This function enables this filtering.

If enableSignOutput has been called, the sign output signal will not be filtered to produce a voltage even if enableAuxiliaryFiltering is called.

Syntax

Tsunami.enableAuxiliaryFiltering()

Example

// Output a square wave with 50% duty cycle on the auxiliary port
pinMode(TSUNAMI_AUX, OUTPUT);
analogWrite(TSUNAMI_AUX, 128);
delay(1000);

// Enable filtering to instead produce a voltage of about 2.5V (half of 5V maximum).
Tsunami.enableAuxiliaryFiltering();
delay(1000);

// Change the voltage to about 1.25V
analogWrite(TSUNAMI_AUX, 64);
delay(1000);

// Go back to square wave output, now with a 25% duty cycle
Tsunami.disableAuxiliaryFiltering()

disableAuxiliaryFiltering()

Description

Disables filtering the Tsunami auxiliary output. See enableAuxiliaryFiltering for details and examples.