Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to reset a counter on external signal in LabView?

Hallo there!

 

I am using LabView v 8.5 and the NI USB-6211 to acquire signals, among them are the following:

 

1) angular pulses from a rotary encoder

2) a reference pulse for the rotary encoder witch will give a pulse on a specific position of the movement for every rotation

3) value from a pressure sensor

 

What I am trying to do is to create a pressure/volume diagram based on the pressure and volume inside a cylinder of an IC engine. To do this, I will need the angle of the engines crankshaft to calculate the pistons position in the cylinder. This way I can calculate the volume and put it in a xy graph to represent the volume (x-axis) and the pressure(y-axis).

 

I am using clk0 to count the pulses from the angular encoder, and this works great. However I now need the reference pulse to somehow reset the count at the precise time it goes high in order to precisely know the angular position.

 

How can I do this? And how precise will this be? And will I need any kind of synchronization with my pressure measurements? If so, how?

The relevant part of the program I am working on resembles the Count Digital Events with reset.vi 33 KB as found in this thread. However, I don't know how to get the reference pulse to reset as the stop button is. How can I do this?

 

In addition: the fast pulses of the angular encoder = 0-> ~10kHz. I seem to lose information if I use the basic level trigger detection.vi when I put this signal on an analog port.

 

-J

0 Kudos
Message 1 of 5
(8,430 Views)

Hi JRex,

 

Assuming you have a quadrature encoder with A and B signals, you should run an angular encoder task.  The reference pulse is often referred to as the Z index, and it is supported on your USB 6211 for quadrature encoder tasks (see manual). 

 

For synchronization, you will want to use your analog input sample clock as the sample clock source for your counter task.  Start the counter task first so it is armed in time for the first analog sample clock edge.  You'll probably also want to trigger the analog task off of the z index--otherwise you'll have a few samples that are not necessarily synch'ed up with the index pulse.

 

 

Best Regards,

John Passiak
0 Kudos
Message 2 of 5
(8,422 Views)

Hi John,

 

I was reading through this thread since I'm having a very similar issue with my vi.  I'm counting the pulses from the phaseA of an incremental encoder, and outputing a pulse at "tick#N" (N=some arbitrary positive integer), since I'm only concerned with unidirectional increments I do not use phaseB.  Although regarding the phaseZ, I would like to reset my counter output by using the z-channel of the encoder, is this possible?  Or do you know where I could find out how the channed property node for CI.zindex.enable works?  basically i want to implement a reset in the counter output so that I dont always consecutively count...

 

 

I want this:   1,2,3,4,5,6,7,8,9,10,(reset),1,2,3,4,5,6,7,8,9,10,(reset),1,2...

this is what I have: 1,2,3,4,5,6,1,2,3,4,5,6,1,2....

(might have this):  1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,...   (where 9 is the maximum count for the counter, therefore it resets).

 

6 is the tick# at wich my counter outputs a pulse, but then it resets automatically, I would rather trigger the reset.

Any advice would be great,

Nick

 

0 Kudos
Message 3 of 5
(8,209 Views)

Hi Nick,

 

If you have an X Series or 2nd Generation cDAQ chassis (basically any cDAQ chassis except for the 9172 or 916x sleeves) then you can implement:

 

1,2,3,4,5,6,7,8,9,10,(reset),1,2,3,4,5,6,7,8,9,10,(reset),1,2...

 

You would have to configure an Edge Count Task, set the initial value to 232 - 6 (such that the 6th count causes the counter to rollover, which generates a pulse on the counter output), and enable the count reset using your external signal:

 

2011-11-04_130122.png

 

 

The count reset isn't currently available for other DAQ devices, but I believe it should be available on M Series (62xx) and TIO (660x, 6624) with a future driver release (some time in 2012).

 

 

 

 

If you don't have an X Series (or gen II cDAQ), don't despair.  On other hardware, you can get close to the previous behavior with a counter output task, with the exception that the "reset" signal would only be detected after the 2nd tick after your pulse is output.  Also, the reset signal would have to occur at the beginning to arm the counter the first time.

 

 

CO N Pulses with Reset.png

 

 

 

 

Or, you can get the 3rd behavior that you asked for by doing a continuous counter output task with the external signal as the source of the timebase ticks.  For example:

 

1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9

 

In toggle mode (default):

6 ticks of initial delay, 2 ticks high, 7 ticks low, 2 ticks high, 7 ticks low, ... etc.

 

In pulse mode:

6 ticks of initial delay, 9 ticks high, 9 ticks low, 9 ticks high, 9 ticks low, ... etc.

 

 

See here for an overview of the difference of the two modes.  Basically, pulse mode will emit a short pulse when TC is reached, and toggle mode will toggle the state of the counter.  You can't have less than 2 ticks as a high time, low time, or initial delay.

 

 

Best Regards,

John Passiak
Message 4 of 5
(8,200 Views)

Great info!   thank you very much, its detailed, consice, to the point, now hopefully it works for my hardware.  I have the cDaq-NI9178, equipped with a 9401 and two 9201's, I will try the first method since it's exactly what I need, if not I will then try the second method (I'm fairly confident I'm currently implementing the third method right now).  

 

Cheers,

Nick

 

 

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