Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I configure a counter to generate pulses using DAQmx?

How do I configure a counter to generate pulses using DAQmx?
 
Is says in the DAQmx C reference help
 
"CtrnInternalOutput—The signal at this internal terminal is where the pulsed or toggled output of the counter appears. The output of a counter pulses or toggles when the counter reaches terminal count. When counting down, the counter reaches terminal count when the count reaches zero. When counting up, the counter reaches terminal count when the counter rolls over. To configure the counter to toggle or generate pulses, use the Export Signal function/VI with Counter Output Event as the signal name."
 
I've tried this but can't get it to work, I may have the parameters wrong or something. The DAQmxExportSignal() function is very unintuitive to me. Here is my counter config code...
 
//////////////////////////////////////////////////////////////////////

int ret = 0;

ret = DAQmxCreateTask("",&task_);

errorMsg(ret);

if (ret != 0)

throw ret;

// Configure the counter

ret = DAQmxCreateCOPulseChanTicks( task_,

"Dev1/ctr0", "", "/Dev1/PFI8", DAQmx_Val_Low, 0, divider, divider );

errorMsg(ret);

ret = DAQmxCfgImplicitTiming( task_, DAQmx_Val_ContSamps,

1000 );

errorMsg(ret);

// Change to pulse mode

ret = DAQmxExportSignal( task_, DAQmx_Val_CounterOutputEvent,

"/Dev1/Ctr0InternalOutput" );

errorMsg(ret);

// Start the counter

ret = DAQmxStartTask(task_);

errorMsg(ret);

/////////////////////////////////////////////////////////////////////////////////////////

The above code works fine, in toggle mode, if I just comment out the DAQmxExportSignal() part.

HELP!!!

Stefan

 

Message 1 of 5
(4,603 Views)
Hello Stefan019,
Is there a particular reason you don't want to use toggle mode?  And you said that pulse mode doesn't work.  What happens, do you get an error?
-Alan A.
0 Kudos
Message 2 of 5
(4,589 Views)
The problem is due to the DAQmxExportSignal call.  By default, when you create a counter output pulse train task, the driver will automatically set the output of the counter to toggle when the count for each high ticks and low ticks expire.  The driver also automatically routes the signal present at Ctr0InternalOutput terminal (the output of the counter internal to the device) to the Ctr0Out terminal (the I/O pin available externally).  Using the line
 
 ret = DAQmxExportSignal( task_, DAQmx_Val_CounterOutputEvent, "/Dev1/Ctr0InternalOutput" );
 
will tell the driver to tristate the Ctr0Out terminal and not output the signal to the external I/O pin.  Using the DAQmxExportSignal function is generally only useful if you want to route the signal to some other terminal internal to the board without having the output show up on the external connector, route the signal to some other external pin other than the default pin, or if you want to have the output show up at multiple locations. 
 
If you want to change the output behavior from toggle to pulse, you need to use the DAQmxSetExportedCtrOutEventOutputBehavior function.  However, this is generally only useful if all you care about are edges (not the duty cycle of the pulse train), and you want to generate higher frequency signals.  For example, with a 20 MHz timebase as the source of your counter, you can only generate a 5 MHz pulse train by default.  This is because the minimum value for the low and high ticks parameter is 2 (20 MHz / 4 = 5 MHz).  By changing the output behavior form toggle to pulse, you can generate a pulse train at 10 MHz since the output is now pulsing instead of toggling.  However, the width of each pulse is not programmable so you will no longer have a 50% duty cycle signal.  I don't remember exactly what the width of each pulse is, but I believe it's in the neighborhood of 50 - 100 nanoseconds in width.  I hope this information helps.
0 Kudos
Message 3 of 5
(4,572 Views)
Hi Guys,
 
Thank you very much. The suggestion reddog had was right on the mark. The only reason that I wanted to change from toggle to pulse mode is to get a higher frequency output, and as you point out I only care about the edges.
 
I actually discovered this solution late last week, I should have posted but didn't have time. I should point out that the only way that I could get it to work is to make the calls to DAQmxExportSignal() and DAQmxSetExportedCtrOutEventOutputBehavior() in sequence.
 
 
 
ret = DAQmxExportSignal( task_, DAQmx_Val_CounterOutputEvent, "/Dev1/Ctr0InternalOutput" );

ret = DAQmxSetExportedCtrOutEventOutputBehavior( task_, DAQmx_Val_Pulse );

Then when I start the counter it will be in pulse mode.

My only question (and it's really a gripe) is where in the documentation is this golden nugget of wisdom contained. I searched far and wide and the only piece of information in the documentation that linked those DAQmx calls is the fact that they both have the word "Export" in their name.

Thanks for the posts guys.

Stefan

0 Kudos
Message 4 of 5
(4,562 Views)
I agree that the documentation on this isn't perfect, but if you search for "toggle" in the NI-DAQmx C Reference Help, you can find the function that you need (DAQmxSetExportedCtrOutEventOutputBehavior).  Also, I agree that there should be a note about needing to also use the ExportSignal function in conjunction.  I've submitted a product suggestion for better documentation on the issue.  Perhaps It'll be better with future releases of NI-DAQmx.  Thanks for your feedback.
-Alan A.
0 Kudos
Message 5 of 5
(4,537 Views)