Advanced Features of High-Speed Digital I/O devices : Scripting In High-Speed Digital I/O Boards

Overview

This paper belongs to the Advanced Features in High-Speed Digital I/O Devices: White Paper Series

Download a PDF of the entire Advanced Features of High-Speed Digital I/O Devices White Paper Series

This paper discusses the scripting capabilities of the National Instruments High-Speed Digital I/O boards. Features such as onboard hardware decision making are showcased in this paper.

Table of Contents

  1. Introduction
  2. Memory Utilization with Scripting
  3. Scripting Instructions
  4. Script Triggering
  5. How to Calculate Memory Based on Script Size
  6. Common Scripting Use Cases
  7. Script Language Considerations
  8. Conclusion
  9. Additional Resources

Introduction

Scripting is used for linking and looping together multiple waveforms.  A script is just a series of instructions that indicates how many waveforms saved on the onboard memory should be sent to the DUT and in what order. The script can specify the order in which the waveforms are generated, the number of times they are generated, and the triggers and markers associated with the generation.

Figure 1 - The script editor can be used to create scripts which can then be loaded into LabVIEW or other programming environments for generation of complex waveforms.

You can create a script to manage dynamic generation based on multiple waveforms and triggers. For example, you could download waveforms A, B, C, and D into device memory. You could then write a script that would wait for a trigger to initiate dynamic generation and, upon receiving this trigger, generate waveform A three times, then generate marker 0, and finally generate waveforms B, C, and D twice (BCDBCD).

A simple script example is shown below:

Script MyScript
   Generate WfmA
   Repeat Forever
      Generate WfmB subset(100,400)
      Repeat 2
         Generate WfmC
      end repeat
   end repeat
end Script

Figure 2 - Scripting can be used for linking and looping of waveforms or their subsets.

Back to top

Memory Utilization with Scripting

Since waveforms can be repeated, memory utilization becomes a valuable advantage of scripting.  In the figure below, the entire waveform takes up 1.5MB on the onboard memory of the device.

 


Figure 3 : Generating a complex digital waveform takes up a lot of onboard memory.

However, if you look closely, a part of the above waveform is repeated multiple times.  The figure below shows how we can break up the above diagram into repeating waveforms.

Figure 4: Scripting can be used to generate repetitive waveforms.  The memory occupied by the waveform after using scripting is much lesser.

A user could use a script similar to the one below to utilize memory better.

Script MyScript
Generate WfmA
 Repeat 3
  Generate WfmB
 End Repeat
Generate WfmC
End Script

 

Back to top

Scripting Instructions

Scripts consist of six primary instructions: generate, repeat/end repeat, if/else/end if, wait, and clear. Additionally, all instructions in a script are surrounded by the keywords script <script name>/end script. Multiple scripts can exist on the device at one time—you can choose which script to execute by referencing the script name.

Some examples of scripting instructions are:

  • script/end script
    Use the script/end script statement to define a set of instructions to be contained within a single script and to associate a name with that script. Script names must be unique, and they cannot have the same name as a waveform name.
  • generate
    Use the generate instruction to describe which waveform to generate.
  • repeat/end repeat
    Use the repeat/end repeat instruction to describe how to "loop" sections of a script until a particular condition is met.
  • if/else/end if
    Use the if/else/end if instruction to determine what sections of a script to execute, based on whether a particular Script trigger was received.
  • Wait
    Pause execution of a script. You can pause the script until a particular Script trigger is received or until a specified number of samples are generated.
  • Clear
    Clear a received Script trigger. The clear instruction is commonly used immediately before a wait or repeat until instruction to ensure that any Script triggers received before the wait or repeat until instructions are ignored.
Back to top

Script Triggering

There are different kinds of script triggers that you can use for triggering individual waveforms..

Types of Triggers

None  
Digital edge (29) The device does not use a Script trigger.
Digital level (30) The data operation does not start until a digital edge is detected.
Software (32) The Script trigger is active when the level of the Script trigger matches the desired level.
  The data operation does not start until a software trigger occurs.
   

Table 1: Types of Triggers for scripting

Back to top

How to Calculate Memory Based on Script Size

The memory option corresponds to the number of samples you store in memory.  For generation the memory is shared with the script.  Most scripts use very little memory (on the order of 1000 samples).  On acquisition only, you can increase the channel memory by reducing the data width.  If you are trying to convert the memory size in MB.  You have

Ex.  6552

64 mb/ch x 4 =256 MB

Since this is dedicated for both acquisition and generation the 64 mb/ch board has 512 MB of memory. Please refer to Advanced Features of High-Speed Digital I/O devices: Memory for exact calculations of Script Size.

Back to top

Common Scripting Use Cases

You can generate a single waveform using scripting.

script upOnly
  generate countUp
end script

You can generate a subset of a particular waveform.  The code below generates 40 samples from countUp starting at sample 10.

script upOnlySubset
  generate countUp subset (10, 40)
end script

You can also generate waveforms with markers.  The example below generates a marker at samples 0 (start of the waveform) and 20.

script upOnlyWithMarkers
  generate countUp marker0 (0, 20)
end script

You can generate waveforms in a sequence with no software lag in between.

script upAllOnesDown
    generate countUp
    generate allOnes
    generate countDown
end script

You can create a script to repeat a particular waveforms a finite number of times.

script up3AllOnesDown
    generate countUp
    repeat 3
        generate allOnes
    end repeat
    generate countDown
end script

script upOnesOrDown
    generate countUp
    if scripttrigger0 then
        generate allOnes
    else
        generate countDown
    end else
end script

script upAllOnesUntilTrigDown
    generate countUp
    repeat until scripttrigger0
        generate allOnes
    end repeat
generate countDown
end script

script upThenUpAndDownForever
    generate countUp
    repeat forever
        generate countUpAndDown
    end repeat
end script

script upWaitAllZerosDown
    generate countUp
    wait until scripttrigger0
    generate allZeros
    generate countDown
end script

or

script upWaitAllZerosDown
    generate countUp
    clear scripttrigger0
    wait until scripttrigger0
    generate allZeros
    generate countDown
end script

  Note:  These two scripts are similar, but a script received during generation of countUp causes the first script to move to allZeros after the smallest possible delay. By adding a clear instruction, you can ignore any triggers received before the wait instruction.

script upWait32Down
    generate countUp
    wait 32
    generate countDown
end script

script stepThroughUpAllZerosDown
    repeat forever
        generate countUp
        clear scripttrigger0
        wait until scripttrigger0

        generate allZeros
        clear scripttrigger0
        wait until scripttrigger0

        generate countDown
        clear scripttrigger0
        wait until scripttrigger0

    end repeat
end script

script burstThroughUpDownThenZerosOnes
    repeat forever
        repeat until scripttrigger0
            generate countUp
            generate countDown
        end repeat

        repeat until scripttrigger0
            generate allZeros
            generate allOnes
        end repeat
    end repeat
end script

Back to top

Script Language Considerations

  • The DHV script compiler is case insensitive.
  • There are no special instruction termination symbols. You can split one instruction across multiple lines, or you can have multiple instructions on one line.
  • Integers can be a number between 0 and 232-1. Further limitations on integer ranges depend on the context and on the size of the onboard memory.
  • alphaNumericString can have up to 256 characters.
  • Repeat loops cannot be nested, with the following exceptions: You can nest deterministic repeat and repeat until instructions, one level deep, inside repeat forever instruction.
  • User-supplied symbols for waveformName and scriptName must be unique.

    Example: The following script is not allowed:
    script badName
      generate badName
    end script
Back to top

Conclusion

Users can use scripting to generate complex waveforms and perform onboard operations such as hardware decision making based on script triggers.  Scripting can also be used to link and loop waveforms to utilize the onboard memory in the best way possible.

Back to top