Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

analog input/sync problem

Solved!
Go to solution

hello all,

I am using USB-6363 CVI 2013 with patches, and being trying to solve this problem for days. But just can't find out what the problem is.

Basically I have an analog outputing finite periods of sine wave ( which works fine) , then I would like to receive it ( or other stuff) at an analog input port for testing purpose.

The thing is I can't get anything from the AI port, straight zeros in that array. I tried to set DAQmxCfgAnlgEdgeStartTrig on the AI0 port but still no results. and at this moment

I don't have the ability to test whether APFI0 method will work or not. So right now I am on a internal trigger.

 

Here is what I got so far, no errors. But all I see on the resulting array sinearrayfin is zeroes. sinearrayf is the input and tested to have data in it.

 

            sinearrayf = (float64 *)malloc(800*arraysize4* sizeof(float64));
            for (int f=0;f<800*arraysize4;f++)
                {
                    sinearrayf[f] = (float64) sinearray[f];
                }
            sinearrayfin = (float64 *)malloc(800*arraysize4* sizeof(float64));
            for (int f=0;f<800*arraysize4;f++)
                {
                    sinearrayfin[f] = 0;
                }

    int            error=0;
    char        errBuff[2048]={'\0'};
    char        trigName[256];
    int32       written=0;

 

 

    DAQmxErrChk (DAQmxCreateTask("",&AItaskHandle));
    DAQmxErrChk (DAQmxCreateAIVoltageChan(AItaskHandle,"/Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));                         
    DAQmxErrChk (DAQmxCfgSampClkTiming(AItaskHandle,"",800000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,800*arraysize4));                                  
    DAQmxErrChk (GetTerminalNameWithDevPrefix(AItaskHandle,"ai/StartTrigger",trigName));

  
    
    DAQmxErrChk (DAQmxCreateTask("",&AOtaskHandle));
    DAQmxErrChk (DAQmxCreateAOVoltageChan(AOtaskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxCfgSampClkTiming(AOtaskHandle,"",800000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,800*arraysize4));
    DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(AOtaskHandle,trigName,DAQmx_Val_Rising));

    DAQmxErrChk (DAQmxWriteAnalogF64(AOtaskHandle,800*arraysize4,0,10.0,DAQmx_Val_GroupByChannel,sinearrayf,&written,NULL));
    DAQmxErrChk (DAQmxRegisterDoneEvent(AOtaskHandle,0,DoneCallback,NULL));
    

    DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(AItaskHandle,DAQmx_Val_Acquired_Into_Buffer,10000,0,EveryNCallback,NULL));

    /*********************************************/
    // DAQmx Start Code
    /*********************************************/

    DAQmxErrChk (DAQmxStartTask(AOtaskHandle));
    DAQmxErrChk (DAQmxStartTask(AItaskHandle));
      
    Error:
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
    if( AItaskHandle!=0 ) {
        /*********************************************/
        // DAQmx Stop Code
        /*********************************************/
        DAQmxStopTask(AItaskHandle);
        DAQmxClearTask(AItaskHandle);
        
    }
    if( AOtaskHandle!=0 ) {
        /*********************************************/
        // DAQmx Stop Code
        /*********************************************/
        DAQmxStopTask(AOtaskHandle);
        DAQmxClearTask(AOtaskHandle);
        
    }
    
    
    if( DAQmxFailed(error) )
        printf("DAQmx Error: %s\n",errBuff);

.......


int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
    int32       error=0;
    char        errBuff[2048]={'\0'};
    static int  totalAI=0;
    int32       readAI;

    DAQmxErrChk (DAQmxReadAnalogF64(AItaskHandle,-1,10.0,DAQmx_Val_GroupByChannel,sinearrayfin,800*arraysize4,&readAI,NULL));

    fflush(stdout);

    return 0;
}

 

0 Kudos
Message 1 of 5
(2,667 Views)

Have you tried just testing a single task (AO or AI) before using both of them to possibly find the problem task? What troubleshooting have you already done?

Aaron L.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 5
(2,620 Views)

I ran the NI_MAX, test the individual ports, the hardware is in working condition.

The outputs are good, I hooked up to a scope to comfirm my results.

The problem seems to be Analog Input won't go to the callNsample routine, ie the trigger is not set right. But I copied and compared the sample program and made sure everything is correct. Trigger...Trigger...thing is killing me on this ,,,

 

0 Kudos
Message 3 of 5
(2,606 Views)
Solution
Accepted by topic author modulation

What I can see from a cursory glance over the code you've included, it looks like you are stopping the tasks without giving time for 10,000 sample to accumulate at the buffer.  This section of code here: does the following:

    /*********************************************/
    // DAQmx Start Code
    /*********************************************/
    DAQmxErrChk (DAQmxStartTask(AOtaskHandle));               // Start AO Task
    DAQmxErrChk (DAQmxStartTask(AItaskHandle));               // Start AI Task
       
                                                              // There's no wait or anything here that would
// stop the error section from being executed immediatly
Error: if( DAQmxFailed(error) ) // There is no error so this section does not execute DAQmxGetExtendedErrorInfo(errBuff,2048); if( AItaskHandle!=0 ) { // There is an AI task so this section does /*********************************************/ // DAQmx Stop Code /*********************************************/ DAQmxStopTask(AItaskHandle); // AI Task is stopped and cleared DAQmxClearTask(AItaskHandle); } if( AOtaskHandle!=0 ) { // There is an AO task so this section executes as well /*********************************************/ // DAQmx Stop Code /*********************************************/ DAQmxStopTask(AOtaskHandle); // AO Task is stopped and cleared DAQmxClearTask(AOtaskHandle); } // Both tasks are stopped and cleared before samples
// are allowed to accumulate at the buffer and call
// the callback to perform the DAQmx read.

If you look at the "ContAck-IntClk.c" example, it has a getchar(); function between the start task and the error block.  This effectively waits for you to press a key before stopping and clearing the tasks.

-Jim B
Applications Engineer, National Instruments
CLD, CTD
Message 4 of 5
(2,537 Views)
 Thank you! never thought the AI taskHandle would be my problem. I spent most of the time on the AI/AO setup command but never look beyong the Error part.

 

0 Kudos
Message 5 of 5
(2,526 Views)