Example Code

Generate 2D Raster Pattern in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview: The following example has three modes for generating a 2D Raster Pattern in LabVIEW.


Description:

The following example has three modes for generating a 2D Raster Pattern in LabVIEW.  It is meant to be used to build a waveform for a 2-channel analog output device so that one channel may control the X axis, and one channel the Y.

 

The modes are as follows:

 

Single-Direction (Uniform) -- This mode updates the Y output only after the X output is at its original position.  X will take a uniform amount of time to return back to the original position.

 

Single-Direction (Fast Reset) -- Similar to above, but this mode will reset X as quickly as possible (1 sample clock tick).  May not be advisable for some hardware setups.

 

Bi-Directional -- This mode will update Y every time X gets to its maximum or minimum value.  After X gets to its maximum value, it would then scan the next line of Y on its return to the original position.


Requirements: LabVIEW 2012 (or compatible), Hardware: none.


Steps to Implement or Execute Code:

1. Insert the parameters.
2. Run the VI.
3. Look at the result on the graph.


 

Additional Information or References:

 

Generate 2D Raster Pattern in LabVIEW FP def.png

 

Generate 2D Raster Pattern in LabVIEW sn.png

 

Also see the following example for a use case that involves hardware using DAQmx:

Synchronize Analog Output Sample Clock with TTL Pulse Count


**This document has been updated to meet the current required format for the NI Code Exchange.**   

John Passiak

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
SteveP
Active Participant
Active Participant
on

John,

It looks like the last cycle of your raster has extra points on it - as many extra as the number of Y steps.  For the X scan, these are being generated by the outer For Loop's Index counter auto-indexed at the top right of that outer For Loop.  I did not see how or why they were being generated for the Y scan, so I modified the code for my use by simply extracting a sub-set of the array that is (X Number of Steps * Y Number of Steps) long.  This results in the last point of the Y raster being at Y Minimum (and only one such point at its ned that is that value) and the last X point remaining at the X Maximum (instead of ramping down to X Minimum).  Is there an intended reason these extra points are there ?

Steve

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Hi Steve,

Thanks for the feedback!  The extra points were intended to "reset" the scanner back to the original position.  I didn't want to instantly transition from the maximum to minimum value since this could be problematic when interacting with actual hardware.  This code was written for a specific application so more likely than not some modifications will need to be made depending on your exact requirements.  I hope it provided a good starting point for your application.

John Passiak
John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Hey Steve,

I added an extra button on the front panel so you may now choose not to reset the Y output if you don't want to.  Thanks again for the feedback!

John Passiak
SteveP
Active Participant
Active Participant
on

John,

A subtle note is that enabling Reset Y at End of Scan? results in the Y array size being larger than X.  When they are combined with Build Array, the end of the X array is filled with a value of 0.  If X Minimum was set to something other than 0, that results in those extra points having a different value than the last X point in the raster.

Steve

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Hi Steve,

I fixed the behavior--good catch.

John Passiak
MattA1
Member
Member
on

Hi John,

A colleague of mine has provided me with a copy of this .vi as a starting point for a LabVIEW project, but I only have LabVIEW 7.0, and this version is incompatible with that. Any suggestions as to where I can find a 7.0-compliant version?

Matt

---------------------------------------------------------------------
LabVIEW 2013, Windows 7

He who asks the question is a fool for five minutes; he who does not ask the question remains a fool forever.