From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

NI PCI-6542: Creating Dynamic Waveforms Using the HSDIO Library

Solved!
Go to solution

Hello!

 

I am having problems understanding how to create waveforms using the HSDIO library to run on my PCI-6542 board. I need to create a program that turns one channel on for 12.5 microseconds, waits a set amount of time(i.e. 100 samples),  and turns another channel on for 12.5 microseconds.

 

This program is to be used in a phased array ultrasonic system.

 

Below is the Dynamic Generation example program that turns channels 0 - 2 on for 1024 samples.

 

/************************************************************************
*
*  Example Program:
*    DynamicGeneration.c
*
*  Description:
*    Generates a simple pattern on specified channels.
*
*  Pin Connection Information:
*    None.
*
************************************************************************/


/* Includes */
#include <stdio.h>
#include <limits.h>
#include "niHSDIO.h"

/* Defines */
#define WAVEFORM_SIZE 1024

int main(void)
{
   ViRsrc deviceID = "Dev1";
   ViConstString channelList = "0-2";
   ViReal64 sampleClockRate = 50.0e6;
   ViInt32 dataWidth = 4;
  
   ViUInt32 waveformDataU32[WAVEFORM_SIZE];
   ViConstString waveformName = "myWfm";
   ViInt32 timeout = 10000; /* milliseconds */
   
   ViSession vi = VI_NULL;
   ViStatus error = VI_SUCCESS;
   ViChar errDesc[1024];
   ViInt32 i;
   
   
   /* Initialize generation session */
   checkErr(niHSDIO_InitGenerationSession(
            deviceID, VI_FALSE, VI_FALSE, VI_NULL, &vi));
   
   /* Assign channels for dynamic generation */
   checkErr(niHSDIO_AssignDynamicChannels (vi, channelList));
   
 
   /* Configure sample clock parameters */
   checkErr(niHSDIO_ConfigureSampleClock(
            vi, NIHSDIO_VAL_ON_BOARD_CLOCK_STR, sampleClockRate));
            
   /* Query the Data Width Attribute */
   checkErr(niHSDIO_GetAttributeViInt32(
            vi, VI_NULL, NIHSDIO_ATTR_DATA_WIDTH, &dataWidth));

/* Populate waveform with ramp data */ for (i = 0; i < WAVEFORM_SIZE; i++) { waveformDataU32[i] = i; } checkErr(niHSDIO_WriteNamedWaveformU32( vi, waveformName, WAVEFORM_SIZE, waveformDataU32)); /* Initiate generation */ checkErr(niHSDIO_Initiate(vi)); /* Wait for generation to complete */ checkErr(niHSDIO_WaitUntilDone(vi, timeout)); Error: if (error == VI_SUCCESS) { /* print result */ printf("Done without error.\n"); } else { /* Get error description and print */ niHSDIO_GetError(vi, &error, sizeof(errDesc)/sizeof(ViChar), errDesc); printf("\nError encountered\n===================\n%s\n", errDesc); } /* close the session */ niHSDIO_close(vi); /* prompt to exit (for pop-up console windows) */ printf("\nHit <Enter> to continue...\n"); getchar(); return error; }

 

Questions:

How can I change the values in waveformDataU32 to create off and on states(instead of just always on)?

How do I select the channel that waveformDataU32 is applied to?

 

Thanks!

Zachary Geier

0 Kudos
Message 1 of 5
(5,359 Views)

Hello,

 

This is where we select which channels to use.  In this case, we select the three channels, 0-2:

ViConstString channelList = "0-2";

The following code is where we generate the data on the lines.  Try changing this piece of code to change the data&colon;

 for (i = 0; i < WAVEFORM_SIZE; i++)
   {
	   waveformDataU32[i] = i;
   }

 

 

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 2 of 5
(5,330 Views)

I understand that the waveformDataU32 array is populated with values from 0 to 1023, but how does this correlate to Digital off and on states?

 

Here is my current understanding of digital waveforms:

This creates a waveform that sets digital outputs 0-2 off for 200 samples and on for 800 samples

 for (i = 0; i < WAVEFORM_SIZE; i++){
     if(i < 200){                     //If sample number is less than 200
          waveformDataU32[i] = 0;     //Turn off channels 0-2
     }
     else{
          waveformDataU32[i] = 1;     //Else turn on channels 0-2 for 800 samples
     }    
 }

 

What am I not understanding about the waveformDataU32 array and how it is formatted based on this example?

 

Thanks,

Zachary Geier

0 Kudos
Message 3 of 5
(5,324 Views)
Solution
Accepted by topic author zdgeier

The waveformDataU32 array is an array of 32 bit integers. Each bit corresponds to a line on the device.  So on the first clock cycle, this program outputs:

 

 

0000 0000 0000 0000 0000 0000 0000 0000

 

Then it outputs the following, changing on each clock pulse:

0000 0000 0000 0000 0000 0000 0000 0001,

0000 0000 0000 0000 0000 0000 0000 0010,

...

 

and so on all the way up to 1023:

0000 0000 0000 0000 00000011 1111 1111

 

 

In the example you include at the bottom, you are setting the least significant bit (LSB) to zero and one, effectively only changing one line on the output. To change all of the lines, you should use 4,294,967,295 or 0xFFFFFFFF instead:

 for (i = 0; i < WAVEFORM_SIZE; i++){
     if(i < 200){                     //If sample number is less than 200
          waveformDataU32[i] = 0;     //Turn off channels 0-2
     }
     else{
          waveformDataU32[i] = 4,294,967,295;     //Else turn on all channels for 800 samples
     }    
 }

 

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 4 of 5
(5,308 Views)

Thanks so much!

 

Zachary Geier

0 Kudos
Message 5 of 5
(5,284 Views)