LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

PXI-6602 Frequency measurment

Hi
I want to measure two frequency of 2.5Mhz with GPCTR1 and 2. With GPCTR0 I generate a gate signal of 100Hz.
I hardwired the output from GPCTR0 to the gates of GPCTR1 and 2.

With this code snippet I can generate the 100Hz gatesignal but I don't measure anything

checkInstErr(GPCTR_Control(iDevice, ND_COUNTER_0, ND_RESET),NI6602);
checkInstErr(GPCTR_Set_Application(iDevice, ND_COUNTER_0,ND_PULSE_TRAIN_GNR),NI6602);
checkInstErr(GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_SOURCE,ND_INTERNAL_100_KHZ),NI6602);
checkInstErr(GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_COUNT_1,ulLOWcount),NI6602);
checkInstErr(GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_COUNT_2,ulHIGHcount),NI6602);
checkInstErr(Select_Sign
al(iDevice, ND_GPCTR0_OUTPUT, ND_GPCTR0_OUTPUT,ND_LOW_TO_HIGH),NI6602);
checkInstErr(GPCTR_Control(iDevice, ND_COUNTER_0, ND_PROGRAM),NI6602);

printf(" Frequency squarewave generation started...\n");


checkInstErr(GPCTR_Control(iDevice, ND_COUNTER_1, ND_RESET),NI6602);

checkInstErr(GPCTR_Set_Application (iDevice, ND_COUNTER_1, ND_SIMPLE_EVENT_CNT),NI6602);
checkInstErr(GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_SOURCE,ND_PFI_35),NI6602);
checkInstErr(GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_GATE, ND_OTHER_GPCTR_OUTPUT),NI6602);
checkInstErr(GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_INITIAL_COUNT, 0),NI6602);
checkInstErr(GPCTR_Control(iDevice, ND_COUNTER_1, ND_PROGRAM),NI6602);

do {
checkInstErr(GPCTR_Watch(iDevice, ND_COUNTER_1, ND_ARMED,&counter_armed),NI6602);
} while(counter_armed != ND_NO);

checkInstErr(GPCTR_Watch (iDevice, ND_COUNTER_1, ND_COUNT, &counter_value),NI6602);



printf("The counter value is %i.\n",counter_value);

checkInstErr(GPCTR_Control(iDevice, ND_COUNTER_1, ND_RESET),NI6602);

An idea what the problem is ??

Thanks in advance.
0 Kudos
Message 1 of 4
(2,993 Views)
The problem is that in your code you are using the wrong application type. You are using GPCTR_Set_Application (iDevice, ND_COUNTER_1, ND_SIMPLE_EVENT_CNT but you should use GPCTR_Set_Application (iDevice, ND_COUNTER_1, ND_BUFFERED_EVENT_CNT) and therefore you have to add a line which configures the size of the buffer with GPCTR_Config_Buffer (iDevice, ND_COUNTER_1, 0, 1000, buffer_1) which is able to store 1000 values in it's buffer. This makes sure that every time an leading edge occurs at the GATE of counter 1 it transfers the counter value into the buffer. If you setup counter 0 for the 100Hz gating signal you are able to have access to this signal from counter 0 with the function call GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_GATE, ND_OTHER_GPCTR_OUTPUT) but if you want to use this signal as well as Gate input for counter 2 than you have to hardwire the output of counter 0 to the Gate of counter 2 and use the GPCTR_Change_Parameter (iDevice, ND_COUNTER_2, ND_GATE, ND_PFI_30) function to indicate that the Gate signal is applied at the PFI pin.

So your program should look like (when only counter 1 is used):

GPCTR_Control(iDevice, ND_COUNTER_0, ND_RESET);
GPCTR_Set_Application(iDevice, ND_COUNTER_0,ND_PULSE_TRAIN_GNR);
GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_SOURCE,ND_INTERNAL_100_KHZ);
GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_COUNT_1,ulLOWcount);
GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_COUNT_2,ulHIGHcount);
Select_Signal(iDevice, ND_GPCTR0_OUTPUT, ND_GPCTR0_OUTPUT,ND_LOW_TO_HIGH);
GPCTR_Control(iDevice, ND_COUNTER_0, ND_PROGRAM);

printf(" Frequency squarewave generation started...\n");

GPCTR_Control(iDevice, ND_COUNTER_1, ND_RESET);

/*GPCTR_Set_Application (iDevice, ND_COUNTER_1, ND_SIMPLE_EVENT_CNT); must be changed to */
GPCTR_Set_Application (iDevice, ND_COUNTER_1, ND_BUFFERED_EVENT_CNT);

/* must be added to configure the buffer which stores the values */
GPCTR_Config_Buffer (iDevice, ND_COUNTER_1, 0, 1000, buffer_1);

GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_SOURCE,ND_PFI_35);
GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_GATE, ND_OTHER_GPCTR_OUTPUT);
GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_INITIAL_COUNT, 0);
GPCTR_Control(iDevice, ND_COUNTER_1, ND_PROGRAM);

do {
GPCTR_Watch(iDevice, ND_COUNTER_1, ND_ARMED,&counter_armed);
} while(counter_armed != ND_NO);

GPCTR_Watch (iDevice, ND_COUNTER_1, ND_COUNT, &counter_value);

printf("The counter value is %i.\n",counter_value);

GPCTR_Control(iDevice, ND_COUNTER_0, ND_RESET);
GPCTR_Control(iDevice, ND_COUNTER_1, ND_RESET);

Regards,
Heinrich Illig
National Instruments
0 Kudos
Message 2 of 4
(2,993 Views)
Hello Heinrich

My program is running fine now.
First I had an dataLossError on the function Watch.
After I added
checkInstErr(GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_BUFFER_MODE, ND_SINGLE),NI6602);
the problem was solved.
Is this because the buffer is now filled just ones, ore is there an other reason ?

Thanks for your help.
0 Kudos
Message 3 of 4
(2,993 Views)
I do not exactly know why you had a dataLossError, maybe because you had some other traffic on the PCI bus as well, but anyway using GPCTR_Change_Parameter with ND_BUFFER_MODE set to ND_SINGLE is a good solution because you are aquiring 1 single buffer with the number of values you specified with GPCTR_Config_Buffer.

Regards,
Heinrich Illig
National Instruments
0 Kudos
Message 4 of 4
(2,993 Views)