Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

HS-DIO 6552 Hardware Compare Issues

I am having a confusing problem with getting this hardware compare to work.  I followed this example, http://zone.ni.com/devzone/cda/epd/p/id/3419 , pretty well (at least I thought), and I could get the example working, however, not the code I created based upon it.  Here is my code, you can safely assume the variables are all defined and syntax before/after is good.
 
waveformDataU8=malloc(2*WAVEFORM_SIZE);
 for(i = 0; i < WAVEFORM_SIZE; i++)
 {
   k=i*2;
   waveformDataU8[k] = NI_DIO_0;
   waveformDataU8[k + 1] = NI_DIO_L;
 }
   
 niHSDIO_InitGenerationSession(deviceID, VI_FALSE, VI_FALSE, "", &genVi);
 niHSDIO_AssignDynamicChannels(genVi, genChannel);
 niHSDIO_SetAttributeViInt32(genVi, "", NIHSDIO_ATTR_HWC_HARDWARE_COMPARE_MODE, NIHSDIO_VAL_HWC_STIMULUS_AND_EXPECTED_RESPONSE );
 niHSDIO_ConfigureSampleClock(genVi, NIHSDIO_VAL_ON_BOARD_CLOCK_STR, sampleClockRate);
 niHSDIO_ExportSignal(genVi, NIHSDIO_VAL_DATA_ACTIVE_EVENT, "", NIHSDIO_VAL_PFI1_STR);
 niHSDIO_WriteNamedWaveformWDT(genVi, "", WAVEFORM_SIZE, NIHSDIO_VAL_GROUP_BY_SAMPLE, waveformDataU8);
  
 niHSDIO_InitAcquisitionSession (deviceID, VI_FALSE, VI_FALSE, "", &acqVi);
 niHSDIO_AssignDynamicChannels (acqVi, acqChannel);
 niHSDIO_TristateChannels (acqVi, acqChannel, VI_TRUE); 
 niHSDIO_SetAttributeViInt32 (acqVi, "", NIHSDIO_ATTR_HWC_HARDWARE_COMPARE_MODE, NIHSDIO_VAL_HWC_STIMULUS_AND_EXPECTED_RESPONSE );
 niHSDIO_ConfigureSampleClock(acqVi, NIHSDIO_VAL_ON_BOARD_CLOCK_STR, sampleClockRate);
 niHSDIO_ConfigureDigitalEdgeStartTrigger (acqVi, NIHSDIO_VAL_PFI1_STR, NIHSDIO_VAL_RISING_EDGE);
 niHSDIO_ConfigureAcquisitionSize (acqVi, WAVEFORM_SIZE, 1);  
  
    niHSDIO_Initiate (acqVi);
 niHSDIO_Initiate (genVi);
 niHSDIO_WaitUntilDone (acqVi, 3000);
  
 niHSDIO_GetAttributeViInt32(acqVi, "", NIHSDIO_ATTR_HWC_NUM_SAMPLE_ERRORS, &intErrors);
 niHSDIO_GetAttributeViReal64 (acqVi, "", NIHSDIO_ATTR_HWC_SAMPLES_COMPARED, &intTotal);
 niHSDIO_close (genVi);
 niHSDIO_close (acqVi);
  
 printf("# of errors: %i\n",intErrors);
 printf("# of samples compared: %d\n",(long)intTotal);
 printf("Hit <Enter> to abort generation.\n");
 getchar();
 
This code executes and runs perfectly, giving "0 errors, 512 samples compared".  However, when I change the data to be:
"   waveformDataU8[k] = NI_DIO_1;
   waveformDataU8[k + 1] = NI_DIO_H;"
The code executes and prints, "256 errors, 512 compared". 

Is there something wrong with my initalizations?  Something I may have forgotten..?
0 Kudos
Message 1 of 5
(3,902 Views)

Also, changing the array structure to:

   waveformDataU8[k] = NI_DIO_0;
   waveformDataU8[k + 1] = NI_DIO_X;

or

   waveformDataU8[k] = NI_DIO_1;
   waveformDataU8[k + 1] = NI_DIO_X;

 

produces 0 errors 512 samples compared. 

Any thoughts?  I'm completely stumped.

0 Kudos
Message 2 of 5
(3,891 Views)
Hi Jacob,

From a quick look at the code everything seems fine to me. There are a couple of things that you can check: Are you configuring both channels in your generation session? genChannel should contain the channel that you are generating data on and then the channel that your comparing the data. You may experience the behavior that you are seeing if you only pass one channel. If you generate on channel 1 and compare on channel 2 genChannel should be 1,2; acqChannel would be 2. The reason for this is to provide the devica a way to now where the compara data should go.

Another thing, you trigger your acquisition off PFI1 using the data active event; this will be fine at low speeds, but at higher speeds you'll need your trigger to have the same cable delay as your data. Tha is, if you are connecting your data channels at the terminal block, you would also connect your trigger there. i.e. Generate the data active event on PFI1, connect it to PFI2 in the terminal block and trigger your acquisition off of PFI2. This way your triggers have the same delay as your data. This may not be the issue that you are having, but it's something to look at.

I hope this helps.

Juan Carlos
0 Kudos
Message 3 of 5
(3,882 Views)

You got it!  I had the generation channel "0" and acquision channel "8", and my variables were defined as such.  I didn't have that channel also in the generation session.  I never saw the line "sprintf(channelString, "%s,%s", generationChannels, acquisitionChannels);" in the example.  I kept overlooking it and thought the generation channels were just the ones I entered in the text boxes.

And the cable delay you're speaking of, I think I had that problem in the example you sent me.  I was triggering fine using it all internally, but when going at speeds greater than 26MHz, it wouldn't work anymore.  I'll attempt to hook up things all at the terminal block and see what happens.

0 Kudos
Message 4 of 5
(3,867 Views)
I'm glad is working now, setting the channels with hardware compare can get a bit complicated, since you have to add the "acquisition" channels to your generation session.

Good luck.

Juan Carlos
0 Kudos
Message 5 of 5
(3,854 Views)