# Discusiones sobre Productos NI

cancel
Showing results for
Did you mean:

Solved!
Go to solution
Highlighted

Que tal a todos, me gustaría generar un código donde al presionar un botón de arranque, se active un ciclo donde haya como un "contador" de 0-5 con dos digitos... sería algo como:

INICIO

0,0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.10,... y así hasta llegar a 5

Message 1 of 12
(335 Views)
Highlighted

Sí, en tu while Loop necesitas un shift register y en cada iteración sumar "0.01" a el numero.

Message 2 of 12
(332 Views)
Highlighted

Since you can calculate the number of iterations needed before the loop starts, a FOR loop is more appropriate than a WHILE loop. You don't even need a shift register. Just multiple [i] with 0.01.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 3 of 12
(291 Views)
Highlighted

Ok, but in a for loop I would need to make it very long, with the shift register it works for me perfectly. Your answer has given me more ideas, thank you very much.

Message 4 of 12
(257 Views)
Highlighted

Esta perfecto! Lo he puesto en práctica pero ahora lo quiero hacer que cuando llegue a 5, sea inverso.

Me podrías dar una idea?

Message 5 of 12
(253 Views)
Highlighted

Have you actually tested your VI?

You cannot do equal comparisons with DBLs. There is a very high chance that your loop will never stop. The value 0.1 cannot be represented in DBL (you would need an infinite amount of mantissa bits!), so continually adding such a value is not guaranteed to be exactly 5.0, ever (the closest you get is 4.99999999999993783).

The following code will NEVER stop, but go on to infinity (given enough time) because the value is never exactly five!!

That's why I said you need to count iteration, because you can calculate exactly how many iterations are needed!

Also, exclusive OR is probably not the correct boolean operation. (Try a plain OR). Look at the truth table! Your VI will not stop if both conditions are true.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 6 of 12
(249 Views)
Highlighted

I have been reviewing your method and it sure does not stop. With the for loop, is it possible to counter up and then down? I mean from 0 to 5 (+0.01) and from 5 to 0 (-0.01).

What do you think?

Message 7 of 12
(234 Views)
Highlighted
Solution
Accepted by topic author DavidOrtega

@DavidOrtega wrote:

Esta perfecto! Lo he puesto en práctica pero ahora lo quiero hacer que cuando llegue a 5, sea inverso.

Try something like the following:

(Make sure you fully understand the reason for each part of the code!)

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 8 of 12
(229 Views)
Highlighted

@DavidOrtega wrote:

I have been reviewing your method and it sure does not stop. With the for loop, is it possible to counter up and then down? I mean from 0 to 5 (+0.01) and from 5 to 0 (-0.01).

What do you think?

See my example right above. If you want exactly one up and one down trace, you can again calculate from first principles how many iterations you need, then use a FOR loop with the correct N, based on y-max, dy, and number of desired periods. Simple math!

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 9 of 12
(225 Views)
Highlighted