While sequence mode enables a signal generator to output a series of waveforms upon receiving triggers, it does have its limitations. Fundamentally, sequence mode requires that each step is configured before signal generation has begun. To configure a dynamic script, where the output is conditional, you must use a more advanced form of sequencing called scripting.
With scripting, a signal generator can dynamically output a sequence of waveforms based on hardware or software events in the system. In addition, it is the most advanced waveform control feature because of its flexibility. You can use scripting not only to link and loop between multiple waveforms but also to generate a waveform conditional on an event that occurs in the device under test. In this section, explore basic script language elements using several example scripts.
Fundamentals of the Script Language
The basic idea of scripting is that a named waveform can be stored in memory on the signal generator and then called by a script that determines which waveform is generated at a given time. The script is also downloaded to the arbitrary waveform generator before signal generation.
In software, the scripting programming interface requires three basic functions. Each of these is shown in Figure 10.
Figure 10. Configuring a Script in LabVIEW
First, each waveform is downloaded to the arbitrary waveform generator (AWG) as a named waveform. It is absolutely necessary that a named waveform is written because the script identifies each waveform by name. Second, the script is written to the waveform. The script contains various commands that determine the order in which each waveform is generated. Finally, the generation is initiated and the AWG begins generating a waveform from the SMC output engine.
Introduction to Script Triggers
Script triggers enable the generation of even more complex scripts. With scripting, you can use a real-world signal to determine which waveform you should generate on the fly. This signal can come from a PXI trigger line on the backplane or a PFI (programmable function interface) trigger from the front panel connector.
You can configure the script trigger in software with the niFgen Configure Script Trigger VI. Using this function, you can configure either a level or edge trigger for a specific trigger line. After the function call in Figure 11, a script can use “scriptTrigger0” as a variable to determine the order in which various waveforms are generated.
Figure 11. Configuring a Script Trigger
In the scripting language, the script trigger is handled as a variable associated with a specific hardware condition. As illustrated in the Figure 11 example script, scriptTrigger0 must be evaluated as a true/false Boolean logic statement. This is shown in Figure 12.
Figure 12. Evaluating a Script Trigger
Because with script triggers you can use conditional statements within the scripting language, the signal generator can output a signal that is dependent on a signal from a real-world device under test. The next section examines some basic statements of the scripting language to provide an overview of scripting capabilities.
Basics of the Script Language
The script language contains several basic commands, which determine the order in which you can generate waveforms. This section lists the basic commands and walks through a couple of basic sequences that use them. The basic scripting command set includes commands such as the following:
Generate n – instructs the output engine to generate a sequence of waveforms ‘n’ times.
Repeat until – repeats a sequence until a particular condition has been met.
If/Else – a conditional statement where the script trigger operates as a Boolean variable.
Wait until – a delay statement that causes the output engine to wait until a condition has been met to resume signal generation.
Clear – erases any instances of triggers that might have occurred.
Repeat Until Command
With the “Repeat until” command, you can repeatedly generate a waveform until a trigger occurs. Figure 13 shows the set of commands required to implement a simple script that uses this command.
Figure 13. Example Script Using the “Repeat until” Command
Notice that “scriptTrigger0” is being used as the variable that determines which waveform should be generated. Use the flowchart in Figure 14 to visualize the script language.
Figure 14. Flowchart of Script Containing the “Repeat until” Command
In this specific script, the signal generator begins by generating “waveform0” first. Then it loops through generating “waveform1” and repeats this waveform until “scripttrigger0” evaluates to TRUE. Once this event occurs, the signal generator generates “waveform2” before finishing the sequence. Figure 15 shows the output signal resulting from this script.
Figure 15. Signal Generator Output with the “Repeat until” Script
As Figure 15 illustrates, the AWG continues to generate “waveform1” until “scripttrigger0” evaluates to TRUE.
Wait Until Command
With the “Wait until” command, you can configure a signal generator to halt generation of any waveform until a hardware condition occurs. Figure 16 shows an example script using “Wait until.” Again, notice that “scriptTrigger0” is used as the variable to determine when the AWG resumes waveform generation.
Figure 16. Example Script Using the “Wait until” Command
Notice the use of the “Clear” statement before the “Wait until” statement. The Clear statement is used to ignore any trigger conditions that may have occurred while “waveform0” was being generated. Figure 17 features a flowchart of this specific script.
Figure 17. Flowchart of Script Containing the “Wait until” Command
In this specific script, the AWG begins by generating “waveform0” first. After this, the signal generator outputs the last sample of “waveform0” until the trigger condition is met. Once the trigger condition occurs, the AWG resumes the script and generates “waveform1” and then “waveform2.” The physical output of the generator is shown in Figure 18.
Figure 18. Signal Generator Output with the “Wait until” Script
You can use the “If/else” command sequence to determine the order in which waveforms are generated depending on a hardware condition. In addition, when these commands are nested, you can use them to implement a truth table in which the waveform to generate depends on several trigger conditions. Figure 19 shows a simple script using the “If/else” command sequence.
Figure 19. Example Script Using the “If/else” Command
In addition, Figure 20 shows a flowchart representing the order in which particular waveforms are generated.
Figure 20. Flowchart of Script Containing the “If/else” Command
In this example, the AWG begins by generating “waveform0” first. Next, “scripttrigger0” is evaluated to determine which waveform is generated next. If “scripttrigger0” evaluates to FALSE, then “waveform1” is generated. If “scriptrigger0” evaluates to TRUE, then “waveform2” is generated. Figure 21 illustrates the physical output of the AWG, as shown as a function of time.
Figure 21. Signal Generator Output with the “If/else” Script
In Figure 21, when “scripttrigger0” evaluates to TRUE, “waveform2” is generated. Note that this example shows only a single conditional statement. With National Instruments AWGs, you can configure up to four script triggers. As a result, you can nest “If/else” statements to represent even more complicated logical statements.