Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

pfi

Greetings,

I need to read out 12 bits several times during a run. The read_out versus non read_out periods are controlled by a external signal SHIFT. The READOUT_CLK is externally generated from a function generator (FGEN_CLK) and I expect it to give 12 transitions very time SHIFT goes high.

I'm using PFI0 to trigger the readins.

SHIFT is latched twice by FGEN_CLK to get SHIFT_l
READOUT_CLK = (FGEN_CLK) AND (SHIFT_l) AND (SHIFT)
PFI0 is connected to READOUT_CLK

-------------------------------------------

Basic idea is:

1. SHIFT goes high in software.

2. READOUT_CLK starts out

3. Use DAQmxReadDigitalU32 to read in 12 bits. Here I expect the program control to stay in the reading in loop till PFI0 has seen 12 transitions.

4. SHIFT goes low in software.

-------------------------------------------

What I expect is:

SHIFT goes high.

SHIFT_l goes high and READOUT_CLK starts.

11 full pulses of the READOUT_CLK.

Positive edge of 12th pulse of READOUT_CLK. This is seen by PFI0 as the last edge (it is configured to read in 12 samples). Program comes out of loop of step 3, SHIFT goes low -> stops READOUT_CLK.

Thus I should be getting 11 full pulses and a very short 12th pulse in the READOUT_CLK. The start of READOUT_CLK should be at least 1 FGEN_CLK pulse after SHIFT going high and simultaneous with SHIFT_l going high. Termination of READOUT_CLK should be simultaneous with SHIFT going low.

However, what I get is a seemingly random number of pulses in READOUT_CLK in the window when SHIFT is high. Sometimes less than 12, sometimes greater than 12.

What am I doing wrong ?

Thanks and regards,
Kartikeya Murari
Johns Hopkins University

-------------------------------------------

Code:

#define NUM_SAMP 12

// Configure
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI0",100000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,NUM_SAMP));

//SHIFT goes high

DAQmxErrChk (DAQmxReadDigitalU32(taskHandle,NUM_SAMP,200.0,DAQmx_Val_GroupByChannel,data,NUM_SAMP,&sampsRead,NULL));

//SHIFT goes low
0 Kudos
Message 1 of 8
(3,764 Views)

Kartikeya,

Why not use DAQmx_Val_FiniteSamps instead of DAQmx_Val_ContSamps since you are taking in 12 samples? Besides that, assuming your FGEN signal is working as expected, this looks like it should work.

--
Michael P
National Instruments
0 Kudos
Message 2 of 8
(3,739 Views)
hello,

thanks for the tip.

i tried doing a couple of things.


#define NUM_SAMP 12

// Configure
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI0",100000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,NUM_SAMP));

for loop starts

    //SHIFT goes high

    DAQmxErrChk (DAQmxReadDigitalU32(taskHandle,NUM_SAMP,200.0,DAQmx_Val_GroupByChannel,data,NUM_SAMP,&sampsRead,NULL));

    //SHIFT goes low


for loop ends

runtime error for the second iteration of the for loop as configuration was set to read in 12.

#define NUM_SAMP 12

// Configure
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI0",100000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000*NUM_SAMP));

for loop starts

    //SHIFT goes high

    DAQmxErrChk (DAQmxReadDigitalU32(taskHandle,NUM_SAMP,200.0,DAQmx_Val_GroupByChannel,data,NUM_SAMP,&sampsRead,NULL));

    //SHIFT goes low


for loop ends

same as before, random number of pulses, both less than and greater than 12.

#define NUM_SAMP 12

for loop starts
   
    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI0",100000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,NUM_SAMP));
    //start taskHandle

    //SHIFT goes high

    DAQmxErrChk (DAQmxReadDigitalU32(taskHandle,NUM_SAMP,200.0,DAQmx_Val_GroupByChannel,data,NUM_SAMP,&sampsRead,NULL));

    //SHIFT goes low
    //stop taskHandle

for loop ends

consistently gave more than 12 pulses (closer to 30).


any idea whats going on ? the connections are as :


thanks and regards,
kartik
0 Kudos
Message 3 of 8
(3,726 Views)
Kartik,
 
I don't understand why you have a for loop. Do you want to read in 12 samples multiple times? If you want to do continuous digital acquisition I recommend taking a look at the example located at
 
C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Digital\Read Values\Cont Read Dig Chan-Ext Clk
 
Save a copy of this example and modify it to fit your needs.
--
Michael P
National Instruments
0 Kudos
Message 4 of 8
(3,702 Views)
Michael,

Thanks for the reply.

Like you say, I need to read 12 samples multiple times. I was initially using the example you refer to: Cont Read Dig Chan-Ext Clk. The problem with that is that I cant really do a continuous read. My read of 12 samples is done only when a SHIFT signal (generated externally) is high.

I'm testing a device which does stuff to a test case and outputs a 12 bit result. I want to test for several input test cases.

So i have:

for loop (number of device test cases)
    let the device under test do it's stuff.
    SHIFT up causing external READOUT_CLK pulsing
    start read in
    12 pulses
    stop read in
    SHIFT dn ending external READOUT_CLK pulsing
end for loop

Of course, what I should have done was to make my device generate the SHIFT and READOUT_CLK internally so I could do a true continous acquisition.

start continuos read in
for loop (number of device test cases)
   
let the device under test do it's stuff.
    device automatically generates correct SHIFT window and exactly 12 READOUT_CLK pulses in that window.
end for loop
stop continous read in

that is the problem.

thanks,
kartik
0 Kudos
Message 5 of 8
(3,699 Views)
Kartik,
 
Even though your application is a bit different from the example, I still recommend taking a look at it. One thing to note is that the timing only needs to be set up once, and the DAQmx Read is the only thing that needs to be in the loop.
--
Michael P
National Instruments
0 Kudos
Message 6 of 8
(3,698 Views)
Michael,

The example leads back to my original question.


#define NUM_SAMP 12

// Configure
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI0",100000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,NUM_SAMP));

for loop (number of test cases)
    device does it's stuff
    //SHIFT goes high starting READOUT_CLK after at least 1 pulse of FGEN_CLOCK [see circuit schematic in older post]
    DAQmxErrChk (DAQmxReadDigitalU32(taskHandle,NUM_SAMP,200.0,DAQmx_Val_GroupByChannel,data,NUM_SAMP,&sampsRead,NULL));
    //program control should come here only after 12 edges have been seen by PFI0
    //SHIFT goes low
end for loop


Now I expect the program control to stay in the
DAQmxReadDigitalU32 function till PFI0 has seen 12 edges. Thus I should get 11 full pulses and a short 12th pulse in the SHIFT window. Instead I get a random number of pulses in the SHIFT window.

I'll look into it some more and try to figure out what's going on. In the meantime, any help would be greatly appreciated !!!

Thanks,
Kartik
0 Kudos
Message 7 of 8
(3,694 Views)
In your case continuous acquisition is not what you want. The DAQmx Start Task actually reads in the data and the DAQmx Read reads the values from the buffer. So, you should actually take a look at
 
C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Digital\Read Values\Read Dig Port-Ext Clk
 
and start the task multiple times to acquire multiple groups of 12 samples.
--
Michael P
National Instruments
0 Kudos
Message 8 of 8
(3,690 Views)