Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Reset Counter using DAQmx?

Hi There,

Fairly simple question. How do I reset a counter back to 0 in DAQmx? Am I stuck doing a Stop Task and Start Task again? Seems like a fairly simple thing to want to be able to do. Maybe a property node control somewhere?

Thanks,
Chris
0 Kudos
Message 1 of 8
(9,581 Views)

Hi Chris-

The only way to reset a counter to zero (or other initial count you specify for a task/channel) is to stop and restart the task.  There isn't a property or method for setting or resetting the count value when a task is running.

Thanks-

Tom W
National Instruments
0 Kudos
Message 2 of 8
(9,569 Views)
How about this idea - if the counter is a 2-pulse encoder (count up on A, count down on B), could it be programmed to be reset via the Z input?  And then furthermore, could you configure an M-series multifunction card (e.g. a 6229) to internally route a digital output to that Z-input?  Then maybe you could write to that output to clear the counter?
Just a thought...
 
 
0 Kudos
Message 3 of 8
(9,506 Views)
Hi Chris,

That is a great idea and it should probably work.  However, there are some restrictions that you might run in to.  The Z input will only reset the counter if it is active when A and B are in a certain state.  The Z index does not asynchronously reset the counter, it depends on the state of the other two input lines (A and B) and how you have the Z index configured in MAX (Measurement and Automation Explorer).  You also cannot internally route a digital output to the Z-input.  You would have to connect it externally.  You can look at all the possible internal device routes by going into MAX, selecting your device, and then clicking on the Device Routes tab at the bottom.
Eric
DE For Life!
0 Kudos
Message 4 of 8
(9,475 Views)

Does that mean that the reset function would only work if there happened to be incoming pulses at the exact instant when the Z input was asserted?  If that's the case, then are you saying there's really no way of resetting the counter ahead of time, in anticipation of pulses which will come at an arbitrary later time? 

Sometimes, it's necessary to zero out the pulses ahead of time, knowing that when the pulses finally do come in, the count will start  from zero. One application that comes to mind is a fluid displacement meter.  This device generates a given number of pulses for a given amount of fluid flow.  Often times, you want to zero this out before starting the fluid flow.  It would be nice to be able to fire the "clear" output just prior to starting the fluid flow.

0 Kudos
Message 5 of 8
(9,458 Views)
Hello Chris,

It's not necessarily the case that there needs to be an incoming pulse at the exact instance when the Z input is asserted.  For example, you can configure an encoder task to reset the count value when the phase is "A High B High".  This means that the measurement will only be reset if line A is in a logic high state AND line B is in a logic high state when the Z line is asserted.  You can configure the phase to be "A High B Low", "A Low B High", or "A Low B Low" (all of this is documented in MAX in the help text when configuring the task).  If you need to reset the counter ahead of time in anticipation of future pulses, you just have to make sure that A, B, and Z will be in known states before the pulses.

If this isn't possible, you can always try to adjust the measurement value in software.  Even though the actual count value is X when you need to start your measurement, you can just subtract X from all your future readings to zero it out.
Eric
DE For Life!
0 Kudos
Message 6 of 8
(9,444 Views)

Thanks - that's a good suggestion.  And I think it will work well in 2-pulse mode (separate up and down pulses).  I can imagine that it may be a bit more problematic if we're hooked up to a quadrature encoder, because it might be hard to know the exact states of A and B when Z is asserted.  And yes, you certainly can zero out the counter in software (which is what we do now!). 

Thanks for your time and help!

 

0 Kudos
Message 7 of 8
(9,438 Views)

can you explain it to me in detail? As in what would i need to do if i want to generate say a trigger after every 2000 counts from a counter?

0 Kudos
Message 8 of 8
(5,263 Views)