Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Implement a timer on a PXIe-6361

Solved!
Go to solution

I need to implement a timer using one of the Counter/Timers on a PXIe-6361 Multifunction DAQ module. I find no help on the NI web sight for implementing timers.  I assume from studying the X Series User Manual that I would use the Single Pulse Generation with Start Trigger Function.  I would need to assign an on-board clock as the SOURCE, assign a PFI input as the GATE (Start Trigger), define the value of the pulse delay for my timing, define the pulse width and assign a PFI as the OUT terminal.  However, I find no information as to what nidaqmx functions I would use to accomplish this action.

 

Can anyone address this operation?

0 Kudos
Message 1 of 10
(8,620 Views)

There's a shipping example named "Counter - Single Pulse Output.vi" that will illustrate most of what you're asking about.  The only thing to add is to explicitly wire up the 'initial delay' input in first daqmx task config call.   Note that there's a similar example for continuous output and that there's a subtle distinction between the "low time" and "initial delay" inputs.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 2 of 10
(8,601 Views)

Thanks, Kevin 

 

    I will check those out Monday.  It is quiting time here now.  I will let you know of my success.

 

Wayne

0 Kudos
Message 3 of 10
(8,595 Views)

Kevin,

 

I replied too fast Friday.  After reading your note more closly, I noticed the .vi file extension and the reference to "wiring".  I assume this is a LabVIew application.  I failed to mention in my note that I am working in CVI-2013 and need the C function calls required to implement this action.

 

Thanks for your response.

 

Wayne

 

0 Kudos
Message 4 of 10
(8,571 Views)

Yeah, sorry, I can't really help with CVI.  I wouldn't be surprised if there are very analogous shipping examples for the functionality I described, but that's just an educated guess, and I don't know what they'd be named.

 

FWIW, I'm still confident that the capability is there with your hardware and DAQmx, but someone else will need to help with CVI examples / syntax.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 5 of 10
(8,565 Views)

Thanks again Kevin.  There is an X series user manual which describes exactly what I need, but there are no examples to show me how to do it.  I have an active service request to get help, but the NI guy can't find anything either.  I will make it work eventually!!!!!!!

 

Wayne

 

0 Kudos
Message 6 of 10
(8,556 Views)

I don't have CVI installed myself, but the examples should be here:

C:\Users\Public\Documents\National Instruments\CVI\Samples\DAQmx

 

The generic C examples (which I do have installed) would be here:

C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C

 

 

Either set of examples should contain some "Generate Digital Pulse" variant using a counter.  

 

 

You can specify the output pulse / delay in terms of seconds, in which case the hardware will select the internal timebase as the counter source.

 

If you want the counter to output a pulse some time after a hardware signal is received, you would need to configure a start trigger (and possibly make it retriggerable if you want to pulse more than once).  You would need to call the following functions before starting your task:

DAQmxCfgDigEdgeStartTrig

DAQmxSetStartTrigRetriggerable

 

 

If you want the counter to output a pulse after you issue the start command in software, then no trigger would be necessary.

 

You might not want to call the blocking "DAQmxWaitUntilTaskDone" as shown in the example but rather poll the non-blocking "DAQmxIsTaskDone" (especially if you intend to make the output retriggerable).

 

 

Documentation on the C functions can be found in the NI-DAQmx C Reference Help (which should also be installed locally on your PC).

 

 

That should help you get started at least.

 

 

Best Regards,

John Passiak
0 Kudos
Message 7 of 10
(8,545 Views)

Hi John,

 

Sorry for taking so long to reply, I was out of town Tuesday and Wednesday. All of the NI examples are for Counter Input tasks. Everyone says to use the Count Digital Event example which needs to be modified to make it work. However, the X Series User Manual clearly shows a Counter Output application titled "Single Pulse Generation with Start Trigger", on pages 7-27 and 7-28, which describes exactly what I want. I have dug through a lot of information and think I have found how to make it happen. Below is a copy of my code with comments before each function call describing what I expect it to do. The EchoDelay passed to the function is the time I want from when the PFI4 trigger occurs to when the timer generates the PFI3 output pulse. This time will be expressed in the number of 20MHz ticks it takes to create the desired time delay. For example, if I want a 500uSec delay, I would pass the number 10,000 to the function. It compiles fine, but I have to make some hardware changes before I can test its operation.

 

Thanks for your input.

 

Wayne

 

 

 

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

void ConfigureEchoTimer(int EchoDelay)

{

  TaskHandle EchoTaskHandle;

  int error = 0;

  int lowTicks = 1000;                                            // with 20MHz clock, these #s

  int highTicks = 1000;                                          //   represent 50uSec

  int idleState = DAQmx_Val_Low;

  int initialDelay = EchoDelay;                             // desired time from the Start Trigger to the

                                                                                //      Output Pulse, expressed in clock ticks.

  char errBuff[2048] = {'\0'};

  char chan[30];

 

  {

    DAQmxErrChk (DAQmxCreateTask("",  &EchoTaskHandle));

    sprintf (chan, "PXI1Slot3/ctr1");               // Use Counter #1

// Create a Counter Output channel using Counter #1, running with the 20MHz internal reference clock.

//   The initial state is low and the output event is created after an initial delay specified by the

//   calling function. The output event is high for 1000 ticks and then low for 1000 ticks (which is actually

//   meaningless).  It will remain low until triggered again.

    DAQmxErrChk (DAQmxCreateCOPulseChanTicks(EchoTaskHandle, chan, "", "/PXI1Slot3/20MHzRefClock",

                                                                                                                   idleState, initialDelay, lowTicks, highTicks));

// After the trigger occurs and the initial delay has elapsed, the output event described above will be

//    routed to PXI1Slot3/PFI3.

    DAQmxErrChk (DAQmxExportSignal(EchoTaskHandle,

                                                                                            DAQmx_Val_CounterOutputEvent, "/PXI1Slot3/PFI3"));

// The initial delay timing will start when the signal connected to PXI1Slot3/PFI4 goes from a low to high state.

    DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(EchoTaskHandle, "/PXI1Slot3/PFI4", DAQmx_Val_Rising));

    DAQmxErrChk (DAQmxStartTask(EchoTaskHandle));

  }

 

Error:

  if(DAQmxFailed(error))

  {

    DAQmxGetExtendedErrorInfo(errBuff, 2048);

    MessagePopup("DAQmx Error", errBuff);

  }

  return;

}

 

// When (or why) would the following function call be used when the output has already been

//    defined in the DAQmxCreateCOPulseChanTicks()   function call.

//

//  DAQmxErrChk (DAQmxSetExportedSignalAttribute (taskHandleDist,

//                                                                    DAQmx_Exported_CtrOutEvent_OutputBehavior, DAQmx_Val_Pulse));

0 Kudos
Message 8 of 10
(8,505 Views)
Solution
Accepted by topic author wkesling3

@wkesling3 wrote:

All of the NI examples are for Counter Input tasks. Everyone says to use the Count Digital Event example which needs to be modified to make it work. 

 


That's odd, is there some sort of filtering option in CVI?  I have the ANSI C counter output examples at:


C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Generate Pulse

 

 

I pulled out the DAQmx calls from the code you wrote so they are easier to see on the forum:

 

DAQmxCreateCOPulseChanTicks(EchoTaskHandle, chan, "","/PXI1Slot3/20MHzRefClock",idleState, initialDelay, lowTicks, highTicks);                                                                                                       
DAQmxExportSignal(EchoTaskHandle,DAQmx_Val_CounterOutputEvent, "/PXI1Slot3/PFI3");
DAQmxCfgDigEdgeStartTrig(EchoTaskHandle, "/PXI1Slot3/PFI4", DAQmx_Val_Rising);
DAQmxStartTask(EchoTaskHandle);

I only see a few small changes to make:

 

20MHzRefClock isn't a valid terminal, you probably want to use 20MHzTimebase.

 

Instead of DAQmxExportSignal I would use DAQmxSetCOPulseTerm.  The output is already on one of the PFI lines by default (depending  on the counter) and setting the output to an explicit PFI line will change the output terminal.  Exporting the counter output event I believe will send the output to a second terminal (I'm not positive though offhand... the two calls might actually be equivalent but DAQmxSetCOPulseTerm is the more commonly used).

 

You should set the task to be retriggerable if you intend to trigger the output multiple times (DAQmxSetStartTrigRetriggerable).  You could alternatively restart the task after every trigger in software, but this is inefficient and you will have several ms of downtime compared to the retriggerable task which will be immediately re-armed after the output has finished (within 10s of ns anyway).

 


@wkesling3 wrote:

Hi John,

 

// When (or why) would the following function call be used when the output has already been
//    defined in the DAQmxCreateCOPulseChanTicks()   function call.
//
//  DAQmxErrChk (DAQmxSetExportedSignalAttribute (taskHandleDist,
//                                                                    DAQmx_Exported_CtrOutEvent_OutputBehavior, DAQmx_Val_Pulse));

The counter actually has two different modes.

 

 "Toggle" is the default for counter output tasks, wherein the counter's output will toggle to the opposite value when it reaches terminal count (at which point a new value is loaded into the count register and the counter begins to count down).  So in your case, "Initial Delay" will be loaded first, then when the counter reaches TC the output will switch to high and "High Ticks" is then loaded into the register.  When the counter reaches TC again the output will toggle low (and in your single pulse example, the output will stop--in a multiple pulse generation "Low Ticks" would then be loaded).

 

In "Pulse" mode the counter only issues a short pulse (I believe 2 timebase ticks long) when it reaches TC.  It is used by default on counter input tasks (e.g.  the counter output can be used as an event to detect rollover conditions for input tasks).  Output tasks can be configured to "Pulse" too but in this case the names "high ticks" and "low ticks" are misnomers since the output signal is only high for a very short time (they would be more suitably named "interval 1" and "interval 2" or something like that).

 

Most people just use the default behavior and do not explicitly set the output behavior unless they have a reason to change it from the default (which is pretty rare).

 

 

Best Regards,

John Passiak
Message 9 of 10
(8,498 Views)

Hi John,

 

Thanks for all the input.  The response from a NI service request was "you think you have found out the way to make this work, I am very glad about it and hope this is the solution." 

 

I saw the example you listed, but I wanted to trigger the task from hardware, not with StartTask.  I had to find the Ticks version in the DAQmx header file.

You are correct about the 20MHzTimebase.  I entered what I had seen in another document.

I am aware of the default PFI connections for the timers, but the hardware in my system is already connected to other lines.  I plan to modify my hardware

in its next version to use the default terminals.  I wasn't aware of the DAQmxSetCOPulseTerm() function and will look into its use.  I will try both versions

to see if the DAQmxExportSignal() actually sends the pulse two places.  A different NI Application Engineer said he thought I needed to use the ExportSignal

function to route the signal.

 

I am aware of the retriggerable feature and may use it in the future, but not initially.  This system is new and in its infancy.

 

With your input, I am going to consider this issue solved.  This forum has given much better information than NI Application Engineering.  Keep up the good work.

 

Wayne

 

0 Kudos
Message 10 of 10
(8,482 Views)