Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted I/O with the DIO 6552

Here is what I'm trying to essentially create:
   ViConstString script1 =
      "script myScript1 "
      "  repeat 200"
      "     generate myWfm1 "
      "     if myWfm1 passed"
      "          generate myWfm2 "
      "  end repeat "
      "end script";
 
im trying to find some way of creating decisions based upon whether or not the waveform passed the digital burst test.
For example, my waveforms consists of several pins some input and some output with values such as 0,1,Z,H,L.
 
Any suggestions would help me alot, thanks.
0 Kudos
Message 1 of 9
(4,725 Views)
Jakeus,

655x devices can export an error event whenever there is a sample mismatch (H or L fail to match); you can export that event to a PFI line, then use that PFI line to trigger and "if-else" statement in your script.

The property that you set to export the error event is "Events>>Sample Error>>Output Terminal". With the configure trigger VI you configure a ScriptTrigger to come from the same PFI line. In your generation script you can now set an "if" statement like this:

"script myScript1 "
" repeat 200"
" generate myWfm1 "
" if scriptTrigger0"
" else "
" generate myWfm2 "
" end if "
" end repeat "
"end script";

If an error is found while generating myWfm1, myWfm2 will not be generated. The NI Script Editor has a good help file with other examples for the If Else statement.

Let me know if you have any questions.

Juan Carlos
0 Kudos
Message 2 of 9
(4,711 Views)
A couple more questions:
 
#1:
I'm tryin to find this export error event function in Labwindows CVI, but I seem unable to find it. 
I'm looking in:
NI HS-DIO Instrument -> Utility Functions -> Set/Get Attribute -> Set Attribute -> SetAttributeViInt32
There are many Attribute ID's you can choose from, some "events" being "ready for start", "ready for advance", "end of record",  "data active event", and "marker event".  If I'm looking in the wrong place completely, please let me know.
 
 
#2:
"if scriptTrigger0", this is saying, "If the value on PFI0 goes high, then.." but only when I use this function to setup the script trigger:
niHSDIO_ConfigureDigitalLevelScriptTrigger (&vi, NIHSDIO_VAL_SCRIPT_TRIGGER0, NIHSDIO_VAL_PFI0_STR, NIHSDIO_VAL_HIGH);
 
I could also make it trigger on a low level by changing the function to:
niHSDIO_ConfigureDigitalLevelScriptTrigger (&vi, NIHSDIO_VAL_SCRIPT_TRIGGER0, NIHSDIO_VAL_PFI0_STR, NIHSDIO_VAL_LOW);
 
 
#3:
And my waveforms, is there some way to designate 'H','L',0,1,'Z'?
For example:
myWfm1=[0,0,0,0,1,1,1,1];
myWfm2=[L,L,L,L,H,H,H,H];
myWfm3=[Z,Z,Z,Z,Z,Z,Z,Z];
 
I guess what I'm asking is, does the waveform take characters, integers, or strings...?

Message Edited by Jakeus on 03-06-2007 11:09 AM

0 Kudos
Message 3 of 9
(4,696 Views)
Hi Jakeus,

To set the output terminal attribute you'll need the string version of the set attribute function (niHSDIO_SetAttributeViString). The attribute that you are looking for is NIHSDIO_ATTR_HWC_SAMPLE_ERROR_EVENT_OUTPUT_TERMINAL. The attribute should be in the .h file. However, hardware compare attributes were not added to CVI's FP file in the first driver release of hardware compare. You can add the Set Attribute function call with the FP and then manualy add the attribute.

for this particular application, I would recomend to use the niHSDIO_ConfigureDigitalEdgeScriptTrigger function. This way, the first rising edge of the error event will be latched and your if statement will read it. As far as the script goes,you'll say something like "if value on PFI0 goes high do nothing, else generate waveform 2". The error event will only be high while the error sample is detected, while there are succesfull compares the event will be low.

As far as introducing Z,H,L, etc. They are defined as U8s.In the niHSDIO.h file you'll find the definitions for the corresponding digital values. Here's a copy:

#define NI_DIO_0 0
#define NI_DIO_1 1
#define NI_DIO_Z 2
#define NI_DIO_L 3
#define NI_DIO_H 4
#define NI_DIO_X 5
#define NI_DIO_T 6
#define NI_DIO_V 7

You store this values in a 1D array that you pass to the niHSDIO_WriteNamedWaveformWDT function. I would recommend using the Digital Waveform Editor to create your patterns and then to write them from file, but it is possible to build test patterns programmaticaly. The lattest version of the HSDIO driver includes a number of examples for C programming of hardware compare.

Something that I forgot to mention in my previous post is to add a wait statement before the if-else command. This will be necesary to allow samples that are in teh cable and the device pipeline to be properly evaluated. Without the wait there is the posibility that that if -else statement is evaluated before all the samples are properly compared. Depending on your setup, 16 samples or so for the wait should be enough.

Good luck with your application.

Juan Carlos
Message 4 of 9
(4,683 Views)
Thanks for all the help, it is greatly appreciated!
I think with the information you've shown me I should be able to get it working, or close to.
 
One method I have been exploring was using the DWE to create my patterns.
So far I was just importing ASCII comma separated text, example:
 
data,data2
0,1
1,0
H,1
L,1
L,L
1,1
0,X
X,Z
 
In attempts to make it more automatic, I am trying to go directly to a HWS file, but from looking at it, it seems like that might be impossible.
Do you know of any way to convert an imported text file to HWS directly?  Thus bypassing the user having to import the file to DWE then save it to HWS.
 
Thanks again for all the help,
 
- Jacob.
0 Kudos
Message 5 of 9
(4,668 Views)

Alright, I've been messing around with getting the program to work properly, and I've hit a brick wall.  This is my code thus far to test what I'm wanting.  You can safely assume a main and all the variables are declared properly.  My wiring is also pretty simple.  I connected the physical channels 0 and 8.  What I'm trying to do is send data on channel 0 and on channel 8 verify that it was sent.  I had figured I could just write the data(0,1,Z) to channel 0, and the expected data (H,L,X) to channel 8, but I can't seem to get it working.  If I attempt to write any data that is not a 0,1 or Z, I get an error because it is a generate session.  However, I tried using an acquisition session in conjunction with it, but I had no way of writing the values I'm trying to compare to the acquision session.  What key concept am I missing here?

Code:

   ViConstString script =
      "script myScript "
      "   repeat forever "
      "     generate myWfm "  //script to generate the same pattern over and over
      "   end repeat "
      "end script";
     
     
   for (i = 0; i < WAVEFORM_SIZE; i++)
   {
      if(i%2==0)
      {
       waveformDataU8[i]=1; //if the counter is even, output a logic 1
      }
   if(i%2!=0)
      {
       waveformDataU8[i]=0; //if the counter is odd, output a logic 0
      }
   }  
  
   checkErr(niHSDIO_InitGenerationSession(deviceID, VI_FALSE, VI_FALSE, VI_NULL, &vi)); //init the session
   checkErr(niHSDIO_AssignDynamicChannels (vi, channelList)); //assign channels
   checkErr(niHSDIO_ConfigureSampleClock(vi, NIHSDIO_VAL_ON_BOARD_CLOCK_STR, sampleClockRate)); //configure clock rate
   checkErr(niHSDIO_ConfigureGenerationMode(vi, NIHSDIO_VAL_SCRIPTED)); //set for scripted mode
   checkErr(niHSDIO_WriteNamedWaveformWDT (vi, waveformName, WAVEFORM_SIZE, NIHSDIO_VAL_GROUP_BY_SAMPLE, waveformDataU8)); //write the waveform to the 6552's memory
   checkErr(niHSDIO_WriteScript(vi, script)); //write the script to the 6552
   checkErr(niHSDIO_Initiate(vi)); //start the process
   
   
   printf("Generation initiated.\n");
   printf("Hit <Enter> to abort generation.\n");
   getchar(); //repeat the script until the user presses enter
  
   /* Abort generation */
   checkErr(niHSDIO_Abort(vi)); //abort the generation sequence

0 Kudos
Message 6 of 9
(4,644 Views)
Update:
 
I might of figured out my problem (although I'm about to leave my workstation for a bit), but I think what I need to do is use this function:
 
checkErr(niHSDIO_SetAttributeViInt32 (vi,"",HSDIO_ATTR_HWC_HARDWARE_COMPARE_MODE, NIHSDIO_VAL_HWC_STIMULUS_AND_EXPECTED_RESPONSE));
 
If anyone can confirm or deny what I'm thinking, please let me know.
 
 - Thanks,
 
Jacob.
0 Kudos
Message 7 of 9
(4,639 Views)
Jacob,

You are on the right track. You do need to enable hardware compare to be able to write compare data (H,X,L). You will also need to have an acquisition session where you configure you acquisition settings. The acquisition session will be used to retrieve the error information.

I found a good CVI example at http://zone.ni.com/devzone/cda/epd/p/id/3419 It's not exactly what you are doing, but it will help you get an idea of the calls required.

Now a note on synchronization; when you send data at one end of the cable and compare the response, there will be a round trip delay that you have to account for. Depending on the speed that you are running this, it could be insignificant or could be several clock cycles. The example above sends an event aligned with the data that is then used as a start trigger, since the event has the same delay as the data, then the acquisition will start at the right time. The 655x boards also offer and internal data active event that you can delay; this event is called "DelayedDataActiveEvent" you can use this as a source for your acquisition start trigger. The the attribute NIHSDIO_ATTR_DATA_ACTIVE_INTERNAL_ROUTE_DELAY will set the number of clock cycles that you want to delay the start of you acquisition. There are some more details in this link:
http://zone.ni.com/devzone/cda/tut/p/id/3671

As far as importing text files, the only tool that I know of is the Digital Waveform Editor, you could use the parsing and array functions in CVI to pars the text file, I know this may be time consuming, but since each data file is different is hard to find tools that are generic enough.

I hope this helps

Juan Carlos
Message 8 of 9
(4,624 Views)

Oh thats a perfect example!  That is basically what I'm trying to accomplish in a nutshell.  It works great, except for one part.  So I made some minor changes to it, and got some unexpected results.

Changes:

1.  Changed the acquision session to run off the internal clock

2.  Change the acquision session start trigger to PFI1, the same trigger as the data active event on the generation session.

 

The program works fine when I try running it values less than 27 MHz.  When I try to go above 27MHz, the program cannot correctly determine where the errors are.  Is this due to the changes I made or something elsewhere?

0 Kudos
Message 9 of 9
(4,597 Views)