LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

can I reduce a timer value down to just 10s

I am trying to utilze the tick count function as a counter that resets every 1 second.  Is there a way to break it down into just tenth's of seconds? 

 

Basically, can I break the string down into just the last 2 or 3 digits?

 

I have tried the elapsed time function but it isn't as fluid as I am looking for. 

0 Kudos
Message 1 of 11
(2,869 Views)

Use the Quotient & Remainder.  Use the remainder of the tick count divided by 1000 to get the milliseconds.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 11
(2,863 Views)

@ajsp wrote:

I am trying to utilze the tick count function as a counter that resets every 1 second.  Is there a way to break it down into just tenth's of seconds? 

 

Basically, can I break the string down into just the last 2 or 3 digits?

 

I have tried the elapsed time function but it isn't as fluid as I am looking for. 


You talk about tick count, counter, string, and elapsed time, and there is very little in common between these. Obviously you are not telling us the entire story. Tick count gives you relative ms, which is a u32 that rolls over when it reaches the top.

The number of displayed digits is a function of the display format. Are you displaying in seconds or milliseconds? Can you show us some code? What is your definition of "fluid"?

 

Tick **bleep** cannot really be used as a "counter", because it is a passive function. What else is in your code? What determines the polling interval?

0 Kudos
Message 3 of 11
(2,849 Views)

 


@crossrulz wrote:

Use the Quotient & Remainder.  Use the remainder of the tick count divided by 1000 to get the milliseconds.



Since the range of u32 is not a multiple of 1000, this code will have short intervals occasionally. Not good!

 

0 Kudos
Message 4 of 11
(2,841 Views)

@altenbach wrote:

Since the range of u32 is not a multiple of 1000, this code will have short intervals occasionally. Not good!


True.  I was hoping the OP would be subtracting the tick counts before performing this Remainder logic.  I guess I could have made my example a little better.  I was just trying to show off the math though.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 11
(2,838 Views)

The quotient & Remainder worked like a charm.  At the end of the day I am trying to get a running 1 second count that I can use for a % of a second that a digital ouput is on. 

 

Attached is a set of code similar to what I am doing, but I am doing it in a much larger program.

0 Kudos
Message 6 of 11
(2,825 Views)

You are still incorrect, because the current code will have a 295ms period once in a while. The range of U32 is 4294967295, which is not a multiple of 1000. Whenever you are rolling over, you will be short.

 

Here's what you could do instead.

 

0 Kudos
Message 7 of 11
(2,818 Views)

@altenbach wrote:

You are still incorrect, because the current code will have a 295ms period once in a while. The range of U32 is 4294967295, which is not a multiple of 1000. Whenever you are rolling over, you will be short.

 

Here's what you could do instead.

 


Sorry, but I'm not seeing how that simple of code fixes the issue.  You will still have the error, you are just moving at what point the error happens.  The clearest way to see it is if the initial tick count was 0.  TC-0=TC.  Right back to your rollover issue.

 

I think the only way to fix it is to keep a TC in a shift register.  Subtract the saved TC from the current TC.  If there's a "reset" (went over 1 second), then store the new TC in the shift register.

NOTE:  Yes, this is a greedy loop.  Please add waits as necessary.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 11
(2,810 Views)

@crossrulz wrote:
Sorry, but I'm not seeing how that simple of code fixes the issue.  You will still have the error, you are just moving at what point the error happens.  The clearest way to see it is if the initial tick count was 0.  TC-0=TC.  Right back to your rollover issue.

True. However, the subtraction guarantees that the rollover problem does not occur for the first ~50 days or so. WIthout the subtraction, it could occur at the first iteration. 🙂

 

There is probably a better solution to this entire problem.

0 Kudos
Message 9 of 11
(2,791 Views)

How about using the High resolution relative seconds (I agree it is limited depending on the system). I just gave a try please comment if improvements required.

 

 1sec reset.png  1sec reset 1.png

-----

The best solution is the one you find it by yourself
0 Kudos
Message 10 of 11
(2,785 Views)