Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing a given number of digital signals?

Hi,

 

I want to construct a program for my NI USB 6009 (using Visual Studios C++, 6.0) for programming a program which:

 

1. Receive a trigger signal, a TTL-signal. This on one digital channel, is "Dev1/ctr0" ok?

2. When received one trigger signal starts to write a number of digital signals on another digital output for example "Dev1/port0/line7".

3. After writting the signals receive an analog value on for example "Dev1/ai0".

 

The problem is that I cannot control the number of "peaks" or "1" that I write with my write function (DAQmxWriteDigitalU8).

I want to be able to write for example 80 "peaks" or "1". I have given "samples to be written"=aver_num=80, but I do not see 80 "peaks" or "1" on my oscillioscope. I have tried with different digital chars to write= with the dig_char_writ ={1},with the dig_char_writ ={0,1,0,1,0,1,0,1} but this do not seem to effect the number of "peaks" or "1" that I see on my oscilloscope?

Instead of 100, I see 11 and so on, always much less. It seems random for me how many I see..

 

I am new in the area and excuse if I have done some fatal errors. I would be glad for some tips help!

 

This is my program:

___________________________________________________________________________________________________________________ 

//ADC-program

// Defenitions

#include "stdafx.h"
#include "NIDAQmx.h"
#include <stdio.h>
#include <cstdio>
#include <iostream>

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

using namespace std;

int main(void)
{
    int32       error=0;
    char        errBuff[2048]={'\0'};
    TaskHandle  taskHandle_1=0;
    TaskHandle  taskHandle_2=0;
    TaskHandle  taskHandle_3=0;


    uInt32                 data=0;                          

    int32                   aver_num=80;                

    const uInt8         dig_char_writ ={1};        

    int32                   skrivna=0;                       


 
    DAQmxErrChk (DAQmxCreateTask("DICount",&taskHandle_1));
    DAQmxErrChk (DAQmxCreateTask("DOWrite",&taskHandle_2));
    DAQmxErrChk (DAQmxCreateTask("AIRead",&taskHandle_3));


    DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle_1,"Dev1/ctr0","",DAQmx_Val_Falling,0,DAQmx_Val_CountUp));
    DAQmxErrChk (DAQmxCreateDOChan(taskHandle_2,"Dev1/port0/line7","",DAQmx_Val_ChanPerLine));
    DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle_3,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
    
    DAQmxErrChk (DAQmxStartTask(taskHandle_1));

    for( data; data<1; data++ ) 

   {
    DAQmxErrChk (DAQmxReadCounterScalarU32(taskHandle_1,0,&data,NULL));
    }

    DAQmxStopTask(taskHandle_1); //Then stop this task
    DAQmxClearTask(taskHandle_1);

    cout << "Trigger signals from laser received: " << data << endl;
    
    DAQmxErrChk (DAQmxStartTask(taskHandle_2));

    DAQmxErrChk (DAQmxWriteDigitalU8(taskHandle_2,aver_num, 1, 10.0, DAQmx_Val_GroupByChannel,&dig_char_writ,&skrivna,NULL));

    DAQmxStopTask(taskHandle_2); //Then stop this task
    DAQmxClearTask(taskHandle_2);

    cout << "Number of digital samples written: " << skrivna << endl;

Error:
    puts("");
    if( DAQmxFailed(error) )
    DAQmxGetExtendedErrorInfo(errBuff,2048);

    //if( taskHandle_1!=0 )
    //{
    //DAQmxStopTask(taskHandle_1);
    //DAQmxClearTask(taskHandle_1);
    //}

    //if( taskHandle_2!=0 )
    //{
    //DAQmxStopTask(taskHandle_2);
    //DAQmxClearTask(taskHandle_2);
    //}

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

_______________________________________________________________________________________________________________ 

 

I would like to know why I do not see 80 "peaks" or "1"on my oscilloscope and how I can solve this? I know that there can be other ways to write this program, which I may not have realized, if there is any one who see/know an obviouse much better way I am glad for tips and help!

 

Kind Regards, Hanna  

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