Signal Generators

cancel
Showing results for 
Search instead for 
Did you mean: 

Script to random switch between different waveforms

Solved!
Go to solution

Hello.

 

How correctly to write the script for switch between different waveforms during generation?

For example:
We are using the niFgen Allocate Named Waveform VI for allocate three Waveforms. When you run Generator, working first Waveforms. Next, the Generator is switched and used in the following only second and third Waveforms.

Or, we configured 10 Waveforms, and in the process of generating to switch not cyclically between all, but only between 2 and 5 Waveforms.

Whether it is possible to realize?

 

Max O. 

Engineer and software developer,

TeSLa.

0 Kudos
Message 1 of 23
(7,508 Views)

And switch between the waveforms need by a trigger.

 

Max O.
Engineer and software developer,
TeSLa.

0 Kudos
Message 2 of 23
(7,502 Views)

Hi Max,

 

You will want to have a different Script Trigger name for each waveform you want to trigger.  You should then use the if/else/end if instruction to check for each trigger inside a repeating loop.  For example:

 

if scriptTrigger0
    generate myWfm0
else
    if scriptTrigger1
        generate myWfm1
    //nested "else if"s for each trigger/waveform you need
    end if    //remember to have an "end if" for each "if" instruction
end if

 

Please refer to our help documentation on scripting for further information on how to write scripts for your arb in order to accomplish what you need.

 

Regards,

Regards,
Chris Elliott
x36772
0 Kudos
Message 3 of 23
(7,484 Views)

Thanks for the help, Chris.

 

So, to switch in any order between 5 waveforms need 5 triggers and the following script?

 

if scriptTrigger0
    generate myWfm0
else
    if scriptTrigger1
        generate myWfm1
    end if
    if scriptTrigger2
        generate myWfm2
    end if
    if scriptTrigger3
        generate myWfm3
    end if
    if scriptTrigger4
        generate myWfm4
    end if
end if

Regards,

 

Max O.

Engineer and software developer,

TeSLa.

0 Kudos
Message 4 of 23
(7,479 Views)
Solution
Accepted by topic author max_i

Hi Max,

 

Each steps needs an else, too.  The end ifs should occur at the end.  For example:

 

if scriptTrigger0
    generate myWfm0
else
    if scriptTrigger1
        generate myWfm1
    else
        if scriptTrigger2
            generate myWfm2
        else
            /etc...
        end if
    end if    
end if

 

Of course, this should all be wrapped in a repeating structure to continue checking for triggers.

 

Regards,

 

Regards,
Chris Elliott
x36772
0 Kudos
Message 5 of 23
(7,476 Views)

Hi Chris,

 

What right?

 

repeat forever 
if scriptTrigger0
    generate myWfm0
else
    if scriptTrigger1
        generate myWfm1
    else
        if scriptTrigger2
            generate myWfm2
        else
           if scriptTrigger3
               generate myWfm3
           else
              if scriptTrigger4
                 generate myWfm4
                end if
            end if
        end if
    end if    
end if
end repeat

 

or

 

repeat forever 
if scriptTrigger0
    Repeat until scriptTrigger0
       generate myWfm0
    end Repeat
else
    if scriptTrigger1
       Repeat until scriptTrigger1        
          generate myWfm1
       end Repeat
    else
        if scriptTrigger2
           Repeat until scriptTrigger2            
              generate myWfm2
           end Repeat
        else
            if scriptTrigger3
               Repeat until scriptTrigger3
                  generate myWfm3
               end Repeat
            else
                if scriptTrigger4
                   Repeat until scriptTrigger4
                      generate myWfm4
                   end Repeat
                end if
            end if
        end if
    end if    
end if
end repeat

 

Regards,
  
Max O.
Engineer and software developer,
TeSLa.

0 Kudos
Message 6 of 23
(7,474 Views)

Hi Max,

 

I am not sure what you mean by "right".  Both scripts are valid.  Each one will allow you to use a trigger to select which waveform is generated.

 

The first script you posted will generate waveformX with triggerX once and then wait for another trigger before generating anything again.  The second script will continously generate waveformX when triggerX is received until triggerX is sent again, at which point generation will stop and the device will await another trigger to resume generation.

 

Regards,

Regards,
Chris Elliott
x36772
0 Kudos
Message 7 of 23
(7,469 Views)

Hi Chris,

 

Possible that the its scripts and came to use (though I now doubt), but with instruction the if/else/end ifmust be preceded by a generate or wait <N> instruction.

In this case, if we add generate or wait <N> instructions to this script to get Abra-Cadabra some kind.

Clarify, what is necessary:

 

Switch in any order.png

 

When starting is not pressed any triggers that generate a waveform0 continuously.

Further, if we passed to the niFgen Send Software Edge Trigger VI - single the triggerX, begin to generate a waveformX continuously.

 

These scripts do not provide the necessary algorithms:

 

Script1.png   Script2.png

 

May be I do not fully understand the scripts work.

How to ensure continuous generation waveformX by a single sent of the triggerX?

Please, prompt.

 

Regards,  

 

Max O.

Engineer and software developer,

TeSLa.

0 Kudos
Message 8 of 23
(7,464 Views)

Hi Max,

 

You are correct that you need to precede the script I provided with a generation or wait.

 

There is no way to send scriptTriggerX to generate waveformX, and then run this continuously until another arbitrary trigger comes in to change to a new waveform.  You must specify in your repeat until instruction a specific trigger that allows the script to leave the continuous generation loop.  There are two good ways to implement this in my opinion; send scriptTriggerX once to start waveformX and then send scriptTriggerX again to stop waveformX, at which point you can send any new trigger to start a new waveform; or send scriptTriggerX once to start waveformX and then send a generic stopTrigger that you use to stop any running waveform in order to exit the repeat until structure.

 

The functionality you are asking for is quite straight-forward to implement on a function generator, as we briefly discussed in this thread.  The difficulty you are having here, I believe, is a result of the use cases for which arbitrary waveform generators are designed to be used.  The application requirements you have described to me thus far are a great fit for a function generator, and a very difficult implementation for an arbitrary waveform generator.  I would strongly recommend considering the procurement of a function generator for this application because I believe the time it is taking to do this is likely costing more than the price of a new function generator.  If you are interested, I can get you in touch with your account representative.

 

Regards,

Regards,
Chris Elliott
x36772
0 Kudos
Message 9 of 23
(7,460 Views)

Hi Chris,

 

Oh, I think I understand you.
Is obtained that the second script is quite suitable?

 

Script2.png


But, interesting second version offered by you.
Can write it?


And thanks for the suggestion!

 

Regards,

 

Max O.

Engineer and software developer,

TeSLa.

0 Kudos
Message 10 of 23
(7,458 Views)