LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple VI that Alternates Values

Hi, I have an extremely easy question but since I am a LV novice, I don't know the best method of doing this.  I have a much bigger problem but if I understand this concept, I think it will help me out in the long run.

 

Basically, I want to have two numeric input fields, and one numeric display.  There will also be an input for time.  I want to be able to input two different numbers (example: 2, and 4), and a time value (let's say 1 second).  Then I want to click a start button and have the numerical display alternate between the two numbers every 1 second.

 

If you can answer this for me, that would be great.  However the bigger picture is that I am wanting to program a linear actuator controller to alternate between two postions, with a pause inbetween each movement.  Hopefully I'll get to that point, but for now I need to know the basics.  

 

Thanks for the help!

 

Mac

Message 1 of 14
(2,886 Views)

Below is a simple example.

 

There were many ways of implementing a solution. I did it this way to demonstrate that you can have a simple solution, yet scalable.  Scalable in the sense that if you add more elements to the array, it will cycle through each element.

 

The downside of this example is that when you click on the stop button, it may take up to the delta-time to respond.  However, I am overlooking that fact for this example.

 

 

 

Message 2 of 14
(2,879 Views)

I didn't like the first example..

It did not start by clicking on a START button as you indicated in your post.

 

This is a slightly improved version.  Not to my liking, but done in a very short time...

It will give you some idea on how to implement your solution.

 

 

 Another caveat of this example is that the timing between the indicator change may not be reliable nor accurate depending on the order of execution of the code that may vary from iteration to iteration.  If I get a chance, I will post another improvement.

 

In the meantime, start implementing your solution and ask additional questions.

Message 3 of 14
(2,869 Views)

@MacSoCal wrote:

[...] However the bigger picture is that I am wanting to program a linear actuator controller to alternate between two postions, with a pause inbetween each movement.  [...] 

Thanks for the help!

 

Mac



Does the linear actuator have a feedback signal? If so, use it, to determine when the actuation is complete. Or make your own endstops with limit switches and read digitally. Whatever you do, I don't recommend ever just using a time delay and assuming a movement has been completed and is in position.

Richard






Message 4 of 14
(2,862 Views)

Agreed!

 

There was hesitation to post the examples.. I sneak in & out of the forum today between system resets..  Not proud of the code I posted, but just wanted to help 😞

 

Maybe I should delete the posts and go away...

Message 5 of 14
(2,858 Views)

Hey, thanks guys for your feedback.  Yes, the controller has a feedback signal and I plan on using that in the program once I learn how to tap into it.

 

Ray, thanks so much for devoting your time to help me out.  This is actually much more complicated that I assumed it would be so it might take me a while to go through your VI and look up some of the functions you used in the help.  Like I said, I'm somewhat new to LV.

 

Thanks agian guys!

 

Mac

Message 6 of 14
(2,843 Views)

Hey Ray, quick question.  What is this function?  I can't seem to find it in my 8.2 version.  Thanks

 

Status.JPG

Message 7 of 14
(2,826 Views)

That is an Unbundle by Name function found in the Cluster/Class/Variant functions palette.  In this case, it is unbundling the error cluster.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Message 8 of 14
(2,822 Views)

The reason for using the status from the error cluster is to stop the bottom loop in case it is still running after the top one has exited and closed the reference to the notifier.

 

The code is not as complicated as you may think.  I kept it simple without all the bells & wistles just as a basic example.  Later we can change the considerations and build up from it.  You can copy the image directly into LabVIEW so that you do not have to re-write what I posted.

 

Hope it helps.

Message 9 of 14
(2,802 Views)

I'd simplify it by removing the User event and perform the switch in the timeout case. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 10 of 14
(2,773 Views)