Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Pixel clock and hsync values are off

Hello NI support,

I seem to be having some trouble using the DAQmx C api and using PCI-6602 hardware.

I am trying to write a program to valididate monitor mode settings ( e.g. 1024x768 @ 60Hz, 1280x1024 @ 60Hz, etc...) using PCI-6602 and DAQmx C library. I already have a program using traditional DAQ but need to port to DAQmx. Legacy code works fine. The problem is mapping functions from traditional DAQ and DAQmx.

For ONE of my measurements, I am trying to count the number of pixels that that appear on one period of Hsync signal.  If monitor was set to 1024 x 768 @ 60 Hz, then there should be AT LEAST 1024 pixel count for one period of Hsync signal and when I set to 1280 x 1024 @ 60 hz then there should be AT LEAST 1280 pixel count in one period of Hsync signal.

That is how it is working for my program using traditional DAQ library.

For my program using DAQmx the numbers I am getting seem to be off. I think I may be using DAQmx functions incorrectly.

Problem:

When I set monitor to 1024x768 and take measurement, the pixel count is about 400 - correct value should be at least 1024

When I set monitor to 1280x1024 and take masurement, the pixel count is about 50 - correct value should be at least 1280

 

 Here is sample code.

#define

 GATE_HSYNC "/Dev1/PFI26"

#define

SRC_PIXEL_CLK "/Dev1/PFI15"

DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

//Create period measurement

DAQmxErrChk (DAQmxCreateCIPeriodChan(taskHandle,

"Dev1/ctr1","",0.00000100,1,DAQmx_Val_Ticks,DAQmx_Val_Rising,DAQmx_Val_LowFreq1Ctr,0.000100,4,""));

//Set source using pixel clock signal

DAQmxSetTimingAttribute(taskHandle,DAQmx_SampClk_Src,SRC_PIXEL_CLK ));

//Set gate using HSync signal

DAQmxSetChanAttribute(taskHandle,

"/Dev1/ctr1",DAQmx_CI_PulseWidth_Term,GATE_HSYNC,0);

DAQmxStartTask(taskHandle);

while

( 1 )

{

DAQmxErrChk( DAQmxReadCounterF64(taskHandle,BUFFER,30,data,BUFFER,&read,0));

printf(

"Acquired %d samples\n",read);

iSamplesRead += read;

if(iSamplesRead >= BUFFER)

break;

}

 

From attached image, the "Hsync"  and "DE" signals is what I'm trying to measure using Pixel clk signal as source for each signal.

Am I using DAQmx API wrong? Should I be using different DAQmx functions? I am new to PCI-6602 hardware and DAQmx and DAQ(traditional) so any insight would be appreciated.

Thanks

glo

0 Kudos
Message 1 of 8
(6,168 Views)

Hi glo,

You mentioned a image but I believe you did not attach it to your previous post. Also could you please verify the number of iterations of you while loop and also

what is the anticipated pixel clock rate

Looking at your code I believe the call you should make is

DAQmxSetChanAttribute(taskHandle,"/Dev1/ctr1",DAQmx_CI_Period_Term,GATE_HSYNC,0);

rather than

DAQmxSetChanAttribute(taskHandle,"/Dev1/ctr1",DAQmx_CI_PulseWidth_Term,GATE_HSYNC,0);

Also please refer to the DAQmx examples which can be found in the following location:

since you are counting the number of pulses that occur on the line, it may be more applicable to have an event counting application. There is a shipping example located at C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Count Digital Events

Hope this helps!

 

JaceD
Signal Sources Product Support Engineer
National Instruments
0 Kudos
Message 2 of 8
(6,139 Views)
0 Kudos
Message 3 of 8
(6,119 Views)

Hi JaceD,

Sorry for my late response and thanks for your quick reply.

I attached the image again. I am trying to count the HSync, VSync and DE signals. The expected results should be when I increase monitor resolution, the number of ticks should increase. Currently results is opposite

Current observation shows increasing monitor resolutions seems to decrease the count, which is opposite of expected results.

I tried your suggestions about using counting using digital events but the results seem to be the same.

 I tried using PCI-6602 internal clk - 80MhzTimeBase instead of the pixel clock and results seem to be the same. The expected results is opposite of what I expect.

I tried to count VSync, DE signals but this shows same behaviour.

Any insight would be apprecited.

Thanks again for reply.

Cheers,

Geoff

PS. attached code again.

//Gate

#define GATE_Red    "/Dev1/PFI38"

#define GATE_Green "/Dev1/PFI34"

#define GATE_Blue    "/Dev1/PFI30"

#define GATE_VSYNC "/Dev1/PFI22" //Vsync

#define GATE_HSYNC "/Dev1/PFI26" //Hsync

#define  GATE_DE         "/Dev1/PFI18" //Data Enable

//Source

#define

SRC_PIXEL_CLK "/Dev1/PFI15"

#define SRC_ICLK "/Dev/80MhzTimebase"

 

DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

//Create period measurement

DAQmxErrChk (DAQmxCreateCIPeriodChan(taskHandle,

"Dev1/ctr1","",0.00000100,1,DAQmx_Val_Ticks,DAQmx_Val_Rising,DAQmx_Val_LowFreq1Ctr,0.000100,4,""));

//Set source using pixel clock signal

DAQmxSetTimingAttribute(taskHandle,DAQmx_SampClk_Src,SRC_ICLK));

//Set gate signal that I am trying to measure

DAQmxSetChanAttribute(taskHandle,

"/Dev1/ctr1",DAQmx_CI_Period_Term,GATE_HSYNC,0);

DAQmxStartTask(taskHandle);

0 Kudos
Message 4 of 8
(6,110 Views)

Hello JaceD,

I think there might something wrong with calculations on my side. I am double checking .... 😞

Please disregard previous post for now  .... unless you see something wrong with my code please let me know.

Thanks again. Cheers,

Geoff 

0 Kudos
Message 5 of 8
(6,098 Views)
Hello NI Support,
 
I have PCI-6602 hardware and I am having trouble taking a period measurement.
 
I have a signal ( e.g monitor's hsync signal ) connected to gate input of counter 0. I use
DAQmxSetChanAttribute with DAQmx_CI_Period_Term property to connect terminal /Dev1/PFI26 to counter 0
 
I am trying to connect another signal ( e.g pixel clock signal to counter 0 ) as source to try and measure the hsync signal. I use
 
DAQmxSetTimingAttribute with DAQmx_SampClk_Src property to connect terminal /Dev1/Ctr6InternalOutput ( or /Dev1/PFI15) to counter 0.
 
Using DAQmx_SampClk_src property does not seem to work.
 
My code runs but seems like the counter is still using 80MhzTimebase to measure the Hsync signal. 
 
 
From previous threads, it looks like we are suppose to use  DAQmxCfgSampClkTiming. I tried this function but I am getting an error
 
Measurements: Invalid timing type for this channel.
Property: DAQmx_SampTimingType
You have requested DAQmx_Val_SampClk
You can Select: DAQmx_Val_Implicit,DAQmx_Val_OnDemand
 
Is there some configuration on a counter I am suppose to do before using DAQmxCfgSampClkTiming? Is this function not supported on my hardware?
 
My DAQmx code snippet is below. I have also attached snippet of code using legacy daq. I am just trying to connect terminals to a counter. Legacy code seems much easier to use. I could be wrong but for DAQmx there seems to be an "infinite" number of functions to connect terminals to counter 🙂 
e.g.
DAQmxCfgSampClkTiming,
DAQmxConnectTerms,
DAQmxSetChanAttribute with any one of these properties DAQmx_SampClk_Src, DAQmx_SampClk_MasterTimebase_src, DAQmx_Timebase_Src
 
Which one of these should I use?
 
Any insight appreciated. Thanks for your patience.
 
Geoff
 
 
//DAQmx Code

//Gate

#define GATE_Red    "/Dev1/PFI38"

#define GATE_Green "/Dev1/PFI34"

#define GATE_Blue    "/Dev1/PFI30"

#define GATE_VSYNC "/Dev1/PFI22" //Vsync

#define GATE_HSYNC "/Dev1/PFI26" //Hsync

//Source

#define

SRC_PIXEL_CLK "/Dev1/PFI15"

//#define SRC_PIXEL_CLK  "/Dev1/Ctr6InternalOutput"

#define SRC_ICLK "/Dev/80MhzTimebase"

//Create period measurement

DAQmxErrChk (DAQmxCreateCIPeriodChan(taskHandle,"Dev1/ctr1","",0.00000100,1,DAQmx_Val_Ticks,DAQmx_Val_Rising,DAQmx_Val_LowFreq1Ctr,0.000100,4,""));

//Set source using pixel clock signal

DAQmxSetTimingAttribute(taskHandle,DAQmx_SampClk_Src,SRC_PIXEL_CLK));

//DAQmxCfgSampClkTiming(taskHandle, SRC_PIXEL_CLK, 1000, DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000); - I get  -200300 error message

//Set gate signal that I am trying to measure

DAQmxSetChanAttribute(taskHandle,"/Dev1/ctr1",DAQmx_CI_Period_Term,GATE_HSYNC,0);

DAQmxStartTask(taskHandle);

 
Legacy sample
 
// Using counter "timerId" as Period measurement (Buffered )
// timerId = 0..7 ( counter index )
// device = handle to device ( e.g. Dev1 )
// StartInput.gate = should be like /Dev1/PFIX
// StartInput.logic = should be like DAQmx_Val_Rising/Falling
// ND_XXXXX = NI constants
 
// Select counter timerID to take buffered period measurement
pGPCTR_Set_Application( device, timerId, ND_BUFFERED_PERIOD_MSR ) ;

// Select gate input/polarity

pGPCTR_Change_Parameter( device, timerId, ND_GATE, startInput.gate  );

 pGPCTR_Change_Parameter( device, timerId, ND_GATE_POLARITY, startInput.logic[startEdge]  );

// Select source input/polarity

pGPCTR_Change_Parameter( device, timerId, ND_SOURCE, countInput.source ) );

pGPCTR_Change_Parameter( device, timerId, ND_SOURCE_POLARITY, countInput.logic[countEdge] ) );

0 Kudos
Message 6 of 8
(6,064 Views)

Hi Geoff,

 

I believe that the correct property to set is DAQmxSetCICtrTimebaseSrc(TaskHandle taskHandle, const char channel[], const char *data); 
The use of this function is best described in the NI-DAQmx C Reference Help file. I have provided the text below for ease of use.

Specifies the terminal of the timebase to use for the counter.

Typically, NI-DAQmx uses one of the internal counter timebases when performing counter measurements. Use this property to specify an external timebase and produce custom measurement ranges that are not possible with the internal timebases.

The location of this information in the NI-DAQmx C Reference Help is NI-DAQmx C Properties>>List of Channel Properties>>Counter Input >> General Properties >> Counter Timebase >> Source.

I hope this helps! Please let us know how this works or if you have any more questions.

 

JaceD
Signal Sources Product Support Engineer
National Instruments
0 Kudos
Message 7 of 8
(6,037 Views)
Hi JaceD,
 
I just did a couple of test runs of my program and it looks like your suggestion is working!!! 🙂
 
AWSOME!!!
 
Looks like I can rest this week-end and on to phase 2 of my app next week 🙂
 
Appreciate your assistence. Thanks again!
 
Cheers,
 
Geoff
 
For anyone else who is interested, I included the DAQmx functions that I am using to let me connect desired pins to the gate input and source input of a counter.
 
 
//DAQmx Code

//Gate

#define GATE_Red    "/Dev1/PFI38"

#define GATE_Green "/Dev1/PFI34"

#define GATE_Blue    "/Dev1/PFI30"

#define GATE_VSYNC "/Dev1/PFI22" //Vsync

#define GATE_HSYNC "/Dev1/PFI26" //Hsync

//Source

#define

SRC_PIXEL_CLK "/Dev1/PFI15"

#define SRC_ICLK "/Dev/80MhzTimebase"

...

//Create period measurement

DAQmxErrChk (DAQmxCreateCIPeriodChan(taskHandle,"Dev1/ctr1","",0.00000100,1,DAQmx_Val_Ticks,DAQmx_Val_Rising,DAQmx_Val_LowFreq1Ctr,0.000100,4,""));

...

//Set source input of counter. Using pixel clock signal to measure signal of the counter's gate input

DAQmxSetCICtrTimebaseSrc(taskHandle,"Dev1/ctr1",SRC_PIXEL_CLK)

...

//Set gate input of counter. The signal I am trying to measure.

DAQmxSetChanAttribute(taskHandle,"/Dev1/ctr1",DAQmx_CI_Period_Term,GATE_HSYNC,0);

DAQmxStartTask(taskHandle);

...

0 Kudos
Message 8 of 8
(6,028 Views)