NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
carlox
Posts: 34
0 Kudos
Accepted Solution

USB-6212: problem in software timed analog input task

[ Edited ]

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 s.r.l.
Member
carlox
Posts: 34
0 Kudos

USB-6212: problem when stopping a running task

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 s.r.l.
Member
carlox
Posts: 34
0 Kudos

Rif.: USB-6212: problem when stopping a running task

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 s.r.l.
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page