-
Notifications
You must be signed in to change notification settings - Fork 12
Reference
- Output functionality
- sleep()
- reset()
- setAmplitude()
- setFrequency()
- selectFrequency()
- setOffset()
- Input functionality
- measurePeakVoltage()
- measureCurrentVoltage()
- measureFrequency()
- measurePhase()
- Auxiliary functionality
- enableSignOutput()
- disableSignOutput()
- enableAuxiliaryFiltering()
- disableAuxiliaryFiltering()
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.
Tsunami.sleep(asleep)
- asleep: Whether or not the signal generator is asleep (boolean).
Tsunami.sleep(true)
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.
Tsunami.reset(inReset);
- inReset: Whether or not the signal generator should be held in reset.
Tsunami.reset(true);
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.
Tsunami.setAmplitude(amplitude)
- amplitude: The desired amplitude of the output signal, in millivolts. 1 volt is 1000 millivolts.
Tsunami.setAmplitude(1024); // Sets the output amplitude to 1.024v.
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.
Tsunami.setFrequency(frequency)
Tsunami.setFrequency(register, frequency)
- 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.
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
}
Selects which of the two frequency registers to use to generate an output signal on the Tsunami.
Tsunami.selectFrequency(register)
- register: Select which frequency register should be used to generate the output signal. The signal generator has two frequency registers, numbered 0 and 1.
See [setFrequency][#setFrequency] for a detailed example.
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.
Tsunami.setOffset(offset)
- offset: The offset voltage, in millivolts.
// Generate a signal from 0 to 1 volt.
Tsunami.setAmplitude(1000);
Tsunami.setOffset(500);
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.
int peak = Tsunami.measurePeakVoltage()
int peak = Tsunami.measurePeakVoltage();
Serial.print("Peak voltage: ");
Serial.println(peak);
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).
int voltage = Tsunami.measureCurrentVoltage()
int voltage = Tsunami.measureCurrentVoltage();
Serial.print("Current voltage: ");
Serial.println(voltage);
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.
float frequency = Tsunami.measureFrequency()
float frequency = Tsunami.measureFrequency()
Serial.print("Frequency: ");
Serial.println(frequency);
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.
float phase = Tsunami.measurePhase()
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);
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.
Tsunami.enableSignOutput()
Disables sign output on the Tsunami's auxiliary connector. See enableSignOutput for details.
Tsunami.disableSignOutput()
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.
Tsunami.enableAuxiliaryFiltering()
// 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()
Disables filtering the Tsunami auxiliary output. See enableAuxiliaryFiltering for details and examples.