Signal Generators

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get around the fact that you can't nest repeat loops in a script?

script genMyWaveforms
repeat 20
   repeat 15
      generate SignalA  marker1 (0)
   end repeat
end script
I am trying to generate a trigger, followed by 15 waveforms, and then repeated 20 times. I have gotten the 1 trigger followed by 15 waveforms. However, when I put in the second repeat I get an error. Apparently Labview doesn't allow these 2 nested loops. Is there a workaround that doesn't involve writing out generate SignalA 15 times? I read in a help file something about generate n, so I tried generate 15 SignalA, generate SignalA 15, but that didn't work either. Any help would be appreciated.
Thanks
0 Kudos
Message 1 of 7
(5,759 Views)

Hi sox,

 

Looking at this, you have two nested loops, but nothing is in the first loop. As you said, you're generating Signal A 15 times and then repeating these 15 signals 20 times. Is there any reason you can't just put them together and do something like:

 

script genMyWaveforms

repeat 300 (this is 15 times 20)

generate SignalA marker1(0)

end repeat

end script 

 

Just roughly typed out of course. Hope this helps!

Lea D.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 7
(5,743 Views)

Sorry, I forgot to add something else.

 

The NI Script Editor Help clarifies this a bit further. You can do:

 

repeat forever
    <instructions>
    repeat <N>
        <instructions>
    end repeat
    <instructions>
end repeat

or:

repeat forever
    <instructions>
    repeat until scripttrigger0
        <instructions>
    end Repeat
    <instructions>

 

However, our scripting editor does not support doing two finite loops nested within eachother. If you're using LabVIEW, you might be able to put a for loop around what you're putting in the script, but anything that's in that for loop and not in the script will have to be coded into LabVIEW.

 

Hope this helps/clarifies further.

Lea D.
Applications Engineering
National Instruments
0 Kudos
Message 3 of 7
(5,735 Views)

Lea,

 

Thank you, but ....

 

I need to generate a trigger every 15 times. I thought about just doing a repeat 300, but how do I generate a trigger every 15 times without some complicated formula trying to figure out how many samples will have occurred etc.

I used 20, and 15 in my example, but in reality these will be variables that get put into the script.

 

Thanks in advance,

 

Go Sox (and Patriots)

 

0 Kudos
Message 4 of 7
(5,726 Views)

Hi Go Sox

 

Will the following script do as you wish?

 

script myScript1
        Repeat 20
            Generate SignalA marker0(0)
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA
            Generate SignalA     
        end repeat
end script

 

If so, I know it seems to be a brute force approach, but the only method I know of to create the functionality that you desire.  The script can be created programatically by creating a program that includes all the possible ways that you may need to generate a script.  A little bit of work up front, but pretty easy afterwards.

 

I've attached a simple VI to generate your scrip[t with the ability to vary the number of times the trigger is generated and the number of times the waveform repeats between triggers.  Youc an expand on this to create some fairly complex scripts.

 

One more note, there is a limit to how many times you explicitly put generate statements in a row.  Unfortunately, I'm do not know what that is, but I think you can get to 128 or 256 without an issue.

 

I hope this helps.

Jerry (Go Giants)

0 Kudos
Message 5 of 7
(5,717 Views)

A small clarification. Two snippets written above:

 

Apparently Labview doesn't allow these 2 nested loops.

 

However, our scripting editor does not support doing two finite loops nested within eachother.

 

Just to clarify something: The nested-loop limitation is not in LabVIEW nor in the Script Editor (either one would sound very silly). The limitation is in the SMC (Synchronization and Memory Core) board, the digital engine in your signal generator. The driver compiles your script into SMC-specific instructions. Because of how the SMC fetches data from memory and the speed requirements on this, there are limits on what it can do.

Marcos Kirsch
Chief Software Engineer
NI Driver Software
0 Kudos
Message 6 of 7
(5,709 Views)

Thank you all (even the Giants fan Smiley Very Happy). I will try the brute force approach with the long script.

 

Hopefully National Instruments will add the "nested loop ability" to it's Signal Generators, as well as being able to generate a marker (ie trigger output) before a waveform.

 

Thanks again

 

Go Sox (and Pats)

0 Kudos
Message 7 of 7
(5,698 Views)