Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Retriggable analog trigger for AI on USB-6152 mass terminal

Hi,

 

I whant to configure a retriggable analog trigger for AI on USB-6152 mass terminal.

 

I modify the demo programme from NI named ANSI C Example program: Retriggerable_AI_Using_Retriggerable_Counter.c as follow

 

/////Counter task////////////////////////////////////////////////////////////////////////////////////////
/* create a counter output channel named coChannel */
DAQmxErrChk (DAQmxCreateCOPulseChanFreq (counterTask, "/Dev1/ctr0", "coChannel", DAQmx_Val_Hz,DAQmx_Val_Low, 0, rate, 0.5));

/* create the clock for my counter output task*/ //une acquisition par trigger
DAQmxErrChk (DAQmxCfgImplicitTiming (counterTask, DAQmx_Val_FiniteSamps, samples));

/*Configure counter output Trigger*/
//DAQmxCfgDigEdgeStartTrig (counterTask, triggerSource, DAQmx_Val_Rising); // original digital trigger
DAQmxErrChk (DAQmxCfgAnlgEdgeStartTrig(counterTask, "/Dev1/APFI0", DAQmx_Val_RisingSlope, 0.3));  

DAQmxErrChk (DAQmxSetTrigAttribute (counterTask, DAQmx_StartTrig_Retriggerable, TRUE));

 

The DAQmxCfgAnlgEdgeStartTrig command rise an error number -200077 that specify than analog trigger is not an option for this hardware.

The USB-6251 specification mention than Start Trigger, Reference Trigger, Pause Trigger, Sample Clock, Convert Clock, Sample Clock Timebase are supported.

 

What is going rong?

How can configure a retriggable analog triger with this device?

 

In att the full C code.

 

Thanks,

Boris

 

 

 

 

 

 

 

0 Kudos
Message 1 of 4
(3,982 Views)

Boris,

 

Can you check your devices on NI MAX to make sure that you can successfully communicate with your 6251 and that it is in fact Dev1.  If your device is configured correctly in MAX it would be helpful for us to understand what you are trying to do at a higher level with this program. What is the end goal and how is this program supposed to function?

 

It may also be helpful to simply add the .c file to your future forum post.  I opened the example myself, but it would be more helpful for us to see what exactly you are changing in the .c file.

 

Best,

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 4
(3,961 Views)

Hi Jacobson,

 

Yes the USB6152 device work well with nimax and Signal Express, I can make a trigged Analog input, but I cant do retriggable AI via a counter.

 

Here is my code, the attacment did't follow last post.

 

The final goal is to read 8 chanell AI at every analog trigger received (30 to 60 Hz, 350mV peak ) and stop/save readings when trigger stop.

 

Thanks for looking,

Boris

 

/*********************************************************************
*
* ANSI C Example program:
*    Retriggerable_AI_Using_Retriggerable_Counter.c
*
* Example Category:
*    AI
*
* Description:
*	 This program configures a continuous analog input and a retriggerable
*	 counter.  The counter generates a pulse train every time the trigger
*	 is pressed.  This pulse train is used as the sampling clock for the
*	 analog input.  With this setup, the analog input will aquire a specified
*	 number of points each time the trigger is pressed.  Since the counter is
*	 retriggerable, a user can press the trigger multiple times and acquire
*	 more data.  The acquired data will be presented on a graph.
*
* Instructions for Running:
*    1. Select the physical channel to correspond to where your
*       signal is input on the DAQ device.
*    2. Enter the minimum and maximum voltage range.
*    Note: For better accuracy try to match the input range to the
*          expected voltage level of the measured signal.
*    3. Set the rate of the acquisition. Also set the Samples per
*       Channel control. This will determine how many samples are
*       read each time the while loop iterates.
*    Note: The rate should be at least twice as fast as the maximum
*          frequency component of the signal being acquired.
*
* Steps:
*    1. Create an analog input and counter output task.
*    2. Set the rate for the sample clock. Additionally, define the
*       sample mode to be continuous.
*	 3. Configure the counter output task for finite samples.
*	 4. Configure the trigger for the counter output task.
*    4. Call the Start function to start the acquistion.
*    5. Read the data in a loop until the stop button is pressed or
*       an error occurs.
*    6. Call the Clear Task function to clear the task.
*    7. Display an error if any.
*
*Note:
*	 Once the stop key is pressed, the trigger must occur one more time to end current AI Read.
*	 If the trigger is not recieved before the specified time period, a timeout error will
*	 occur.
*
* I/O Connections Overview:
*    Make sure your signal input terminal matches the Physical
*    Channel I/O control. For further connection information, refer
*    to your hardware reference manual.
*
*********************************************************************/

//Includes
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include "NIDAQmx.h"


#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }

int main(int argc, char *argv[])
{
	/*Define Variables*/
	TaskHandle analogTask=0;
	TaskHandle counterTask=0;
	static int taskRunning=0;
	int error;
	long numRead;
	float64     data[1000];
	char        errBuff[2048]={'\0'};
	int32       read=0,totalRead=0;

	/* Input Parameters*/ 
	char physicalchannel[50]="Dev1/ai0";				//Analog Input Channel
	double min=-10;										//Analog Input Minimum 
	double max=10;										//Analog Input Maximum
	char counterSource[50]="/Dev1/PFI0";//"/Dev1/Ctr0InternalOutput";	//AI Sample Clock // horloge genere par conteur
	double rate=100.00;//10000.00;								//Sample Rate
	int samples=1;//1000;									//Samples per Channel
	char counterChannel[50]="/Dev1/ctr0";				//Counter used to Generate Pulses
	char triggerSource[50]="/Dev1/APFI0";//bobo "/Dev1/PFI0";			//Trigger Input
	double timeOut=10;									//Analog Input Time Out

	bool fifoEmpty= true;
              
	DAQmxCreateTask ("analogInTask", &analogTask);  /* Create a task for analog input */  
	DAQmxCreateTask ("couterOutTask", &counterTask); /* Create a task for analog input */ 
	////// AI task ///////////////////////////////////		
	/* create an analog input channel named aiChannel */ 
	DAQmxErrChk (DAQmxCreateAIVoltageChan (analogTask, "Dev1/ai0", "aiChannel", DAQmx_Val_Diff, min, max,
									  DAQmx_Val_Volts,""));
			
	/* create the clock for my analog input task*/
	DAQmxErrChk (DAQmxCfgSampClkTiming (analogTask, "/Dev1/PFI0", 55, DAQmx_Val_Rising, DAQmx_Val_ContSamps, samples+10)); // sample pour buffer size only

	/*Configure analog input buffer*/ //fonction optionnelle
	//DAQmxSetBufferAttribute (analogTask, DAQmx_Buf_Input_BufSize, samples+1000);
	DAQmxErrChk (DAQmxSetBufferAttribute (analogTask, DAQmx_Buf_Input_BufSize, samples+10));

	/////Counter task////////////////////////////////////////////////////////////////////////////////////////
	/* create a counter output channel named coChannel */
	DAQmxErrChk (DAQmxCreateCOPulseChanFreq (counterTask, "/Dev1/ctr0", "coChannel", DAQmx_Val_Hz,
								DAQmx_Val_Low, 0, rate, 0.5));
									
	/* create the clock for my counter output task*/		//une acquisition par trigger
	DAQmxErrChk (DAQmxCfgImplicitTiming (counterTask, DAQmx_Val_FiniteSamps, samples));
    //DAQmxErrChk (DAQmxCfgSampClkTiming (counterTask, triggerSource, 55, DAQmx_Val_RisingSlope, DAQmx_Val_FiniteSamps, 1));// 55fps // 1S
       

    /*Configure counter output Trigger*/
	//DAQmxCfgDigEdgeStartTrig (counterTask, triggerSource, DAQmx_Val_Rising); 
	DAQmxErrChk (DAQmxCfgAnlgEdgeStartTrig(counterTask, "/Dev1/APFI0", DAQmx_Val_RisingSlope, 0.3));
	

	DAQmxErrChk (DAQmxSetTrigAttribute (counterTask, DAQmx_StartTrig_Retriggerable, TRUE));
				 
	/*********************************************/
	/*/ DAQmx Start Code
	/*********************************************/
	
	DAQmxErrChk (DAQmxStartTask(counterTask));
	DAQmxErrChk (DAQmxStartTask(analogTask));
	taskRunning = 1;
	
	/*********************************************/
	/*/ DAQmx Read Code
	/*********************************************/
	printf("Acquiring samples continuously.  Press any key and then trigger to stop.\n");
	while( !_kbhit() )
	{
		DAQmxErrChk (DAQmxReadAnalogF64(analogTask,samples,10.0,DAQmx_Val_GroupByScanNumber,data,samples,&numRead,NULL));

		if( numRead>0 )
		{
			totalRead += numRead;
			printf("Acquired %d Samples.\n", totalRead);

			
			// push reading to fifo
			fifoEmpty= false;
			
		}
		else {
			printf("Acquired ZERO Samples.\n");
		}
	}
	_getch();

	//Stop Tasks
	DAQmxStopTask(analogTask);
	DAQmxClearTask(analogTask);		
	DAQmxStopTask(counterTask);
	DAQmxClearTask(counterTask);
	
	return 0;

Error:
	if (error == -23987 && !fifoEmpty) 
	{
		//	stop task
		// clear task
		// save fifo
		// clear fifo
		// restart task

	}

	if( DAQmxFailed(error) )
		DAQmxGetExtendedErrorInfo(errBuff,2048);
	if( analogTask!=0 ) {
		/*********************************************/
		/*/ DAQmx Stop Code
		/*********************************************/
		DAQmxStopTask(analogTask);
		DAQmxClearTask(analogTask);		
		DAQmxStopTask(counterTask);
		DAQmxClearTask(counterTask);
		}

	
	if( DAQmxFailed(error) )
		printf("DAQmx Error: %s\n",errBuff);
	
	printf("End of program, press Enter key to quit\n");
	getchar();
	return 0;
}

 

0 Kudos
Message 3 of 4
(3,950 Views)

Boris,

 

Our DAQ devices do not allow you to start a counter task using an analog trigger.  On a seperate note, you are using our 6251 device correct?

Matt J | National Instruments | CLA
0 Kudos
Message 4 of 4
(3,916 Views)