Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to re-assign digital pulse train to an arbitrary pin on USB-6259

I'm new to DAQmx (and NI) and have been trying to 'google' for examples to solve my problem. I'm using a NI USB-6259 M-series. I want to generate a difital pulse train of specified frequency and duty cycle and have it routed to a specified pin. I have the example code "Retrigg_Pulse_Train_Gen" that I'm running in Visual C++.  The modified code snippet is below. Without the #if/#endif the code generates the prescribed pulse on "Dev1/ctr0". I want to direct the output to another pin, such as "/Dev1/pfi1".  I get the error listed at the end. Can I accomplish what I need with the USB-6259?

 

 .. chan is defined as “/Dev1/ctr0” and the triggerSource is 80MhzTimeBase

-------------------------------------------

      DAQmxErrChk (DAQmxCreateTask("",taskHandle));      DAQmxErrChk (DAQmxCreateCOPulseChanFreq(*taskHandle,chan,"",DAQmx_Val_Hz,idle,initDelay,freq,duty));#if 1      // re-assign pin    DAQmxSetCICountEdgesTerm(taskHandle, chan, "/Dev1/pfi1") ;      //#endif      DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(*taskHandle,triggerSource,edge));      DAQmxErrChk (DAQmxCfgImplicitTiming(*taskHandle,DAQmx_Val_FiniteSamps ,numSamples));      DAQmxErrChk (DAQmxSetStartTrigRetriggerable(*taskHandle, 1)); ----------------------------

  

Error Message:

DAQmx Error: Specified route cannot be satisfied, because it requires resources
that are currently in use by another route.
Property: DAQmx_CO_CtrTimebaseActiveEdge
Source Device: Dev1
Source Terminal: 80MHzTimebase
Destination Device: Dev1
Destination Terminal: Ctr1Source

Required Resources in Use by
Source Device: Dev1
Source Terminal: PFI13
Destination Device: Dev1
Destination Terminal: PFI0

 

Thanks for any and all help,

Brian 

 

 

 

0 Kudos
Message 1 of 10
(7,910 Views)

Hi Brian,

 

From your description I interpret that you are trying to generate a pulse train to be output on the PFI line of your choosing.  In the code you are calling the DAQmxSetCICountEdgesTerm function which specifies the input terminal of a signal to be counted. Try using the DAQmxSetCOPulseTerm instead which specifies the output terminal to generate pulses on.

 

Regards,

Barron
Applications Engineering
National Instruments
0 Kudos
Message 2 of 10
(7,892 Views)

I can not find DAQmxSetCOPulseTerm in either the NiDAQmx Help or NiDAQmx C-Reference guide. Also a file search of the NiDAQmx examples doesn't find the use of this API. When I try it in the code it prompts for a 3rd argument const char * data. Where can I find a definition of this API?

 

Thanks!

 

Brian

0 Kudos
Message 3 of 10
(7,888 Views)

Ok. I'm happy. I used :

 

DAQmxSetCOPulseTerm(*taskHandle,"/Dev1/ctr0", "/Dev1/pfi1")

 

and that works. I'd still like to know where I can find documentation on these functions. I noted in the NIDAQmx.h file there is also a  

DAQmxResetCOPulseTerm(). Do I need to call this when I kill the task to clear the assignment?

 

Thanks,

Brian

0 Kudos
Message 4 of 10
(7,885 Views)

Hi Brian,

 

The NI-DAQmx C Reference Help is a good source to find information about the available functions.  When looking for a specific functionality for a device I often start with the "Supported Properties by Device" section under the Contents tab.  This is where I looked to find the DAQmxSetCOPulseTerm function.  It was located under Counter Output >> Pulse >> Output Terminal link.  

 

Regards,

Message Edited by Barron S on 03-18-2010 08:46 AM
Barron
Applications Engineering
National Instruments
0 Kudos
Message 5 of 10
(7,875 Views)

For the life of me I can't find DAQmxSetCOPulseTerm in the Help files. I found it in the .h file and went from there. I've got one pulse gen working but now am trying to run a 2nd simultaneous pulse gen. I can get either one to run but not both. The setup is use ctr0 with 80MHzTimeBase trigger and output on pfi4 for one pulse gen and the other uses ctr1 with 80MHzTimeBase trigger and output on pfi3. Is there any limitation in the USB-6259 preventing this? Here is the code:

 

//---------------------------------------------------------
int CniDAQ::NiDaqSetPulseGen(TaskHandle *taskHandle, char * chnl,
            char * ctr, float64 freq, float64  duty,
            uInt32 initDelay, uInt32 edge, const char triggerSource[])
{
    int32   error=0;
    int numSamples=5;

    DAQmxErrChk (DAQmxCreateTask("", taskHandle));
    DAQmxErrChk (DAQmxCreateCOPulseChanFreq(*taskHandle, ctr,"",
            DAQmx_Val_Hz,DAQmx_Val_Low,0,freq,duty));

    // re-assign pin   
    DAQmxSetCOPulseTerm(*taskHandle, ctr, chnl) ;         

    DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(*taskHandle,triggerSource,edge));
    DAQmxErrChk (DAQmxCfgImplicitTiming(*taskHandle,DAQmx_Val_FiniteSamps ,numSamples));
    DAQmxErrChk (DAQmxSetStartTrigRetriggerable(*taskHandle, 1));

    DAQmxStartTask(*taskHandle);

Error:
    return error;
}
//----------------------------------------------------------

 

It gets called twice with different taskHandle, ctr and chnl

1. ctr= /Dev1/ctr0 chnl= /Dev1/pfi4, taskHandle= taskHandle1

2. ctr= /Dev1/ctr1 chnl= /Dev1/pfi3, taskHandle= taskHandle2

 

   Thanks for your help,

   Brian

 

 

 

0 Kudos
Message 6 of 10
(7,864 Views)

Are you getting an error? If either works by themselves then you may be attempting to use a resource already in using in your second task. Any error you get may tell us more about what going wrong.

Matt
Applications Engineer
National Instruments
0 Kudos
Message 7 of 10
(7,853 Views)

Hi

Some settings of frequency and PWM resolution may require both counters to be used as a cascade.

Maybe that's what happens here.

Michael

0 Kudos
Message 8 of 10
(7,807 Views)

On M Series, finite pulse trains (of more than one pulse) require two counters - one to generate the pulses and one to gate it. Check out the M Series User manual in the "Finite Pulse Train" section for the timing diagrams.

 

Can you just set the timing to continuous in DAQmxCfgImplicitTiming instead of using retriggerable? Continuous pulse trains only take up one counter. You may also be able to use Freq Out depending on your frequency.

 

Cheers,

Andrew S

Message Edited by stilly32 on 03-26-2010 11:58 AM
0 Kudos
Message 9 of 10
(7,803 Views)

I did end up using DAQmx_Val_ContSamps and that worked instead of retriggerable.

 

Thanks all

 

Brian

0 Kudos
Message 10 of 10
(7,766 Views)