Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6212: problem in software timed analog input task

Solved!
Go to solution

Hi all

I have an unexpected behaviour using a USB-6212 card.

 

The sample code demonstrates that when I execute in sequence two DAQmx analog input tasks, the first one hardware timed, the second one software timed, it happens that the first data readings are all wrong and have the same value for all channels.

 

The task code is the following:

 

	GetCtrlVal(panelHandle, PANEL_HW, &Switch); 
	
	if (Switch) { 
//
// First Task: read 10 rows of values with hardware timing
//
	    DAQmxCreateTask("", &htAI);
	    DAQmxCreateAIVoltageChan (htAI, MX_DEV_AI, "", DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, "");
	    DAQmxCfgSampClkTiming(htAI,"", SAMPLE_RATE, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000);
	    DAQmxRegisterEveryNSamplesEvent (htAI, DAQmx_Val_Acquired_Into_Buffer, SAMPLE_RATE, 0, RefreshCB, NULL);
	    DAQmxStartTask(htAI);
            Delay(1.0);
	
	    DAQmxStopTask(htAI);
	    DAQmxClearTask(htAI);
	}
//	
// Second Task:read 10 rows of values with software timing
//	
	DAQmxCreateTask("", &htAI);
        DAQmxCreateAIVoltageChan(htAI, MX_DEV_AI, "", DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, "");
        DAQmxStartTask(htAI);
	
	for (i=1; i<=10; i++) {
   		DAQmxReadAnalogF64(htAI, 1.0, 10.0, DAQmx_Val_GroupByChannel, AcqVoltRow, HW_AI_CHANNELS, &read, 0);	
		SetTableCellRangeVals (panelHandle,PANEL_SOFT, MakeRect(i, 1, 1, HW_AI_CHANNELS), AcqVoltRow, VAL_ROW_MAJOR);
		Delay(0.1);
	}		
	DAQmxStopTask(htAI);
	DAQmxClearTask(htAI);

 

An image is better than thousand word: the analog inputs were connected to a resistor network to have known values.

The upper table contains the hardware timed acquisitions, the lower one the software timed readings.... as you can see the first row is all of 0.13 values, totally wrong

 

If the software timed acquistion task is executed without the previous one (in my demo this can be obtained by the switch in upper right corner), readings are correct!

 

sshot-3.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Is there something I'm doing wrong?

I've also tried running the program on  USB-6009, but it seems to works correctly. 

 

[LabWindows/CVI 2010 SP1 - NI-DAQmx driver 9.4 - Windows 7 x64]

 

 

 

Carlo A.
Megaris




0 Kudos
Message 1 of 3
(3,015 Views)

I have further details on the problem, and now I could best describe it as an incorrect state left somewhere (may be in DAQmx, may be on USB-6212 card) when a running analog acquisition task is stopped.

 

If the task is stopped as presented in the previous message code, by calling DAQmxStopTask() or even with DAQmxClearTask(), there is some "leftover" that prevents the first on-demand acquisition of a new task to be successful.

 

If the task is aborted by a call to DAQmxTaskControl (htAI, DAQmx_Val_Task_Abort);  all works as expected.

 

The updated task code is here:

 

 

	if (Switch) { 
//
// First Task: read 10 rows of values with hardware timing
//
	    DAQmxCreateTask("", &htAI);
	    DAQmxCreateAIVoltageChan (htAI, MX_DEV_AI, "", DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, "");
	    DAQmxCfgSampClkTiming(htAI,"", SAMPLE_RATE, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000);
	    DAQmxRegisterEveryNSamplesEvent (htAI, DAQmx_Val_Acquired_Into_Buffer, SAMPLE_RATE, 0, RefreshCB, NULL);
	    DAQmxStartTask(htAI);
            Delay(1.0);
	
	    DAQmxTaskControl (htAI, DAQmx_Val_Task_Abort);  ///// in place of DAQmxStopTask()
	    DAQmxClearTask(htAI);
	}
//	
// Second Task:read 10 rows of values with software timing
//	
	DAQmxCreateTask("", &htAI);
        DAQmxCreateAIVoltageChan(htAI, MX_DEV_AI, "", DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, "");
        DAQmxStartTask(htAI);
	
	for (i=1; i<=10; i++) {
   		DAQmxReadAnalogF64(htAI, 1.0, 10.0, DAQmx_Val_GroupByChannel, AcqVoltRow, HW_AI_CHANNELS, &read, 0);	
		SetTableCellRangeVals (panelHandle,PANEL_SOFT, MakeRect(i, 1, 1, HW_AI_CHANNELS), AcqVoltRow, VAL_ROW_MAJOR);
		Delay(0.1);
	}		
	DAQmxStopTask(htAI);
	DAQmxClearTask(htAI)

 

 

 

Carlo A.
Megaris




0 Kudos
Message 2 of 3
(2,942 Views)
Solution
Accepted by topic author carlox

This problem has been corrected by NI-DAQmx 9.5 

 

324044 NI USB-621x on-demand AI task returns incorrect data after clearing a buffered AI task

Carlo A.
Megaris




0 Kudos
Message 3 of 3
(2,810 Views)