Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

counter roll over

I wonder what to do when  counter roll over.

Do anyone have some examples what to do?

 

Thanks.

0 Kudos
Message 1 of 5
(9,732 Views)

It depends on what you're doing with the counters.

 

A 32-bit counter will roll over after 232 edges have been counted.  If you're counting the 80 MHz timebase on an M Series for example, this would take about 53.7 seconds (232 / 80 MHz). 

 

When the counter rolls over on an edge count task, the internal output will pulse.  If you wanted to, you could route this to a second available counter, to effectively give you a 64-bit counter.  This two counter setup would take over 7000 years to roll over on 2x 32-bit counters with a 80 MHz timebase.

 

This might not be relevant at all to what you're doing however--could you provide more information about your application?

 

 

 

Best Regards,

John Passiak
0 Kudos
Message 2 of 5
(9,726 Views)

I count (pulses) edges from incremental encoder which measures speed of electrical motor with 32-bits counter.

I get two values through shift register from counter N2 and N1 and I subtract them N2-N1.

 

The pulses move very fast and counter quickly rolls over. 

I want to somehow solve roll over problem that I won't get strange values.

0 Kudos
Message 3 of 5
(9,719 Views)

It looks like you're trying to measure the frequency of your encoder signal using the 6251?  Your software-timed loop (code in your other thread) isn't the best way to go about this since the software timing is non-deterministic.  I think you should follow Stefo's advice in this thread to use a period measurement, which wouldn't give you the rollover problem.  I don't think there's a need for you to use both the A and the B signals, instead just measure the frequency of either A or B using the shipping example.

 

Alternatively, you could generate a sample clock to sample your encoder task deterministically to determine the frequency by subtracting consecutive samples.  You still can't reset the counter, but you can certainly account for the overflow in software.  In fact, if you typecast the data to U32 (you can actually read the data as U32 with the DAQmx API) before the subtraction, the overflow would take care of itself (0 - 4294967295 = 1 if the data is U32).

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 5
(9,710 Views)

Get a cRIO and do the task in FPGA, then you can use as big of a counter as you wish to program.

 

Dave

0 Kudos
Message 5 of 5
(9,651 Views)