Discussion:
Handshake adds a sample at the beginning and omits a sample at the end
(too old to reply)
jdviolin
2008-06-20 23:40:06 UTC
Permalink
I am using a NI-6534 for Serial Digital Input.  I am using the DAQmxCfgBurstHandshakingTimingImportClock() function in the same manner as in this post:

http://forums.ni.com/ni/board/message?board.id=70&thread.id=8334&view=by_date_ascending&page=1

That is, I'm using an "Enable" pulse to gate my data transmission.  My
data transmission consists of a single, serial input data line and a
clock, on which the data is sampled (on the falling edge).  The clock
is connected to PCLK and the Enable signal is connected to REQ signal. 
Here is a diagram:

<img src="" style="padding: 7px 8px; background-color: #F6FEFF; border-left: 1px solid #8FF1FF; margin: 10px 0px; display: inline-block; color: #3B5053; font-size: 13px; ">Loading Image...

I am having trouble with the sampling.&nbsp; The first sample I get is
always '0', and I always miss the last sample of my data stream.&nbsp; Here
is a scope shot of the data (notice, it is viewed on the positive,
differential side, so ignore the voltages).&nbsp; Enable is on the bottom,
then data, then clock on the top.&nbsp; The data I sent out was 0x24.....&nbsp;
You can clearly see the '0 0 1 0&nbsp;&nbsp;&nbsp; 0 1 0 0' in the waveform, so I know
the data transmission hardware is working properly:

<img src="" style="padding: 7px 8px; background-color: #F6FEFF; border-left: 1px solid #8FF1FF; margin: 10px 0px; display: inline-block; color: #3B5053; font-size: 13px; ">Loading Image...

Any ideas?&nbsp; I will try to put up some pseudo-code Monday.&nbsp; Thanks for your assistance.

JOHN
DJ L.
2008-06-23 20:40:09 UTC
Permalink
Hey John,
&nbsp;
It looks like the rising edge of the enable line is fairly close to&nbsp;what could&nbsp;potentially be the first&nbsp;falling edge of the clock. I was wondering if you have tried sampling on the rising edge of the clock, as the scope shows the rising edge lines up nicely to the data being valid. Or&nbsp;can you&nbsp;shift your back half of&nbsp;a clock period? Let us know if that helps.
&nbsp;
Regards,DJ L.
jdviolin
2008-06-23 22:10:08 UTC
Permalink
I apologize for that.&nbsp; I took that scope shot with the Clock probe on the [-] minus side of the differential signal.&nbsp; Here is a better picture showing the correct relationship between Clock and Enable.<img src="" style="padding: 7px 8px; background-color: #F6FEFF; border-left: 1px solid #8FF1FF; margin: 10px 0px; display: inline-block; color: #3B5053; font-size: 13px; ">Loading Image... Here is some modified code.&nbsp; I haven't actually compiled this version, but it is an accurate example://FUNCTION CALL:rxHssTxDataStartHandshakeTEST(VAL_BINARY, iNumBytes, 1);//GLOBAL VARIABLES:char gTEST_cInputLineA[MAX_STR_SZ] = "PXI1Slot3/port0/line0"; //DIOA[0:7]char gTEST_cInputClkA[MAX_STR_SZ] = "/PXI1Slot3/PFI4"; //aka REQ1int gTEST_iInputSourcePol = DAQmx_Val_Falling;int gTEST_iInputSourceRate = 2000000;int gTEST_iNumBytes=0;int gTEST_iFormat = 0;char gTEST_cFileName[MAX_PATH_SIZE]={0};//DEFINITIONS#define mNumSamplesPerClock&nbsp;&nbsp;&nbsp;&nbsp; 2 // samples per clock period#define mNumEnbBytesBefore&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 // bytes of clock cycles with deasserted enable before data#define mNumEnbBytesAfter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 // bytes of clock cycles with deasserted enable after data#define mNumNibblesPerWord&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8 // bits per byte#define mCalcNumOutSamples(n)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((n + mNumEnbBytesBefore + mNumEnbBytesAfter) * mNumNibblesPerWord * mNumSamplesPerClock)//FUNCTION:int rxHssTxDataStartHandshakeTEST(int iFormat, unsigned int uiNumBytes, int iEnbActHi){ &nbsp;&nbsp;&nbsp; TaskHandle hTaskHandle = 0;&nbsp;&nbsp;&nbsp; char strLine[256]={0};&nbsp;&nbsp;&nbsp; char strClk[256]={0};&nbsp;&nbsp;&nbsp; char strFileName[256]={0};&nbsp;&nbsp;&nbsp; unsigned int uiNumSamples = mCalcNumOutSamples(uiNumBytes);&nbsp;&nbsp;&nbsp; //Setup Input Data Lines and Clock line&nbsp;&nbsp;&nbsp; strcpy(strLine, gTEST_cInputLineA);&nbsp;&nbsp;&nbsp; strcpy(strClk, gTEST_cInputClkA);&nbsp;&nbsp;&nbsp; //Setup Output data file, Data file format, and number of data bytes&nbsp;&nbsp;&nbsp; strcpy (gTEST_cFileName, "HssTemp.dat");&nbsp;&nbsp;&nbsp; gTEST_iFormat = iFormat;&nbsp;&nbsp;&nbsp; gTEST_iNumBytes = uiNumBytes;&nbsp;&nbsp;&nbsp; //Setup Task&nbsp;&nbsp;&nbsp; DAQmxCreateTask ("", &amp;hTaskHandle);&nbsp;&nbsp;&nbsp; DAQmxCreateDIChan(hTaskHandle, strLine, "", DAQmx_Val_ChanPerLine);&nbsp;&nbsp;&nbsp; DAQmxCfgBurstHandshakingTimingImportClock (hTaskHandle, DAQmx_Val_FiniteSamps,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uiNumSamples, gTEST_iInputSourceRate, strClk, gTEST_iInputSourcePol,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DAQmx_Val_Low, DAQmx_Val_ActiveHigh);&nbsp;&nbsp;&nbsp; //Register Done Event&nbsp;&nbsp;&nbsp; DAQmxRegisterDoneEvent(hTaskHandle, 0, HandshakeCallbackTEST, &amp;uiNumBytes);&nbsp;&nbsp;&nbsp; //Start Task&nbsp;&nbsp;&nbsp; DAQmxStartTask(hTaskHandle);&nbsp;&nbsp;&nbsp; gTEST_hTaskHandle = hTaskHandle;&nbsp;&nbsp;&nbsp; return iStatus;} //CALLBACK FUNCTION:int32 CVICALLBACK HandshakeCallbackTEST(TaskHandle taskHandle, int32 status, void *callbackData){ &nbsp;&nbsp;&nbsp; TaskHandle hTaskHandle = gTEST_hTaskHandle;&nbsp;&nbsp;&nbsp; readInputDataTEST(gTEST_iNumBytes, gTEST_cFileName, hTaskHandle);&nbsp;&nbsp;&nbsp; return 0;} //SUBFUNCTIONint readInputDataTEST(unsigned int uiNumBytes, const char cRawFileName[], TaskHandle hTaskHandle){ &nbsp;&nbsp;&nbsp; unsigned char *ucBuffRaw = NULL;&nbsp;&nbsp;&nbsp; unsigned int uiNumSamples=0, uiSamplesRead=0;&nbsp;&nbsp;&nbsp; //Calculate Number of samples&nbsp;&nbsp;&nbsp; uiNumSamples = mCalcNumInSamples(uiNumBytes);&nbsp;&nbsp;&nbsp; ucBuffRaw = calloc(uiNumSamples, 1);&nbsp;&nbsp;&nbsp; //Read Input Samples&nbsp;&nbsp;&nbsp; DAQmxReadDigitalU8 (hTaskHandle, -1, 10.0, DAQmx_Val_GroupByChannel, ucBuffRaw,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uiNumSamples, &amp;uiSamplesRead, 0);&nbsp;&nbsp;&nbsp; //Output data to a file&nbsp;&nbsp;&nbsp; ArrayToFile (cRawFileName, ucBuffRaw, VAL_UNSIGNED_CHAR, uiNumSamples
DJ L.
2008-06-24 18:40:10 UTC
Permalink
Hey John,
&nbsp;
I see that the data has changed from the last screenshot. You said that your device wrote '0 0 1 0&nbsp;&nbsp;&nbsp; 0 1 0 0', but it looks like the data that will be sampled on the falling edge of this new screenshot seems to be '1 1 0 0&nbsp;&nbsp; 1 1 1 0'. Is this correct, or am I missing something?
&nbsp;
From what the subject of the thread implies, and what you mentioned in your first post, it sounds as if you wrote&nbsp;'1 1 0 0&nbsp;&nbsp; 1 1 1 0' to the 6534, but it actually reads '0 1 1 0&nbsp; &nbsp;0 1 1 1', basically adding a '0' in front of the data and dropping the last value. Is this the issue that you are seeing?
&nbsp;
Regards,
DJ L.
DJ L.
2008-06-24 19:10:09 UTC
Permalink
Hey John,
&nbsp;
What are you trying to do overall? Are you trying to acquire a finite amount of data when a trigger comes in? Or are you trying to continuously acquire until the enable signal goes back low? Have you looked at any of the shipping examples that come with the driver. Also, have you checked out the NI 6533/34 for NI-DAQmx Help document? In there you can find (by searching for) "Burst Protocol Timing Diagrams" which you might want to make sure you are following. There is also good information about "Burst Handshaking Timing Type Startup Sequence" as well as other information on Burst. Hope the help file also helps.
&nbsp;
Regards,
DJ L.
jdviolin
2008-06-24 19:10:10 UTC
Permalink
DJ, Thank you for your quick response!!!&nbsp; The data I transmit is different every time.&nbsp; In my test software, I have a function that compares the expected data (which I generate and transmit to the device) to the actual data (which is generated by the code snippet I posted earlier, received from the device).&nbsp; The data is selected from several patterns or is just random data.&nbsp; In the first post, the data was '0010 0100', and in the second the data was '1100 1110'Today I took a scope shot of the transmission on the TTL side of the differential receiver.&nbsp; This is what I saw:<img src="" style="padding: 7px 8px; background-color: #F6FEFF; border-left: 1px solid #8FF1FF; margin: 10px 0px; display: inline-block; color: #3B5053; font-size: 13px; ">Loading Image... (This data was '1010 0000 1')I purchased the differential receiver device as a TTL device, but you can tell the voltage levels are not even close to 5V - they are closer to 3V.&nbsp; Now, according to the Datasheet for the PXI-6534, the Minimum Input Voltage for a high level is 2V, so this seems to meet that specification, but do you think this could be the caues of my problems.I have tested the hardware before in a loopback configuration, in which the PXI-6534 is transmitting data to itself, and this works.&nbsp; There is something about using the hardware I am trying to test that causes it to add a bit.I am trying to create a driver for a device that begins acquiring digital samples when an enable signal gets asserted.&nbsp; We frequently use a Clock, Data, and Enable Signalling protocol for many of our applications.&nbsp; The serial stream stops when the Enable signal gets de-asserted.&nbsp; These transmissions can happen repeatedly, although our preliminary goal is just to capture a single transmission.&nbsp; We have tried several ways of doing this, including setting up a multithreaded callback function using CmtScheduleThreadPoolFunction with the DAQ read functions in the callback function.&nbsp; However, this turned out to be labouriously slow, and we are attempting to find a more streamlined method.&nbsp; We thought the protocol for the Burst Handshaking mode matched our signalling protocol the best and would provide a more efficient and native data processing medium.&nbsp; At this point, it would be convenient to have working drivers that both input and output data in this format.&nbsp; We have created an output driver, and are working on the input driver.&nbsp; I have seen all the example code I can find on the Burst Handshaking mode and used it to develop the code I presented to you earlier.&nbsp; There really isn't much example code out there - the resources you mentioned are about all there is.&nbsp; There is almost no mention of it in the forums, as a whole.Thanks again for your help!!!JOHN
Loading...