LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do use a timer to run a motor based on a variable?

Solved!
Go to solution

Hello, i am very new to Labview and i am trying to use it for a Fuzzy Logic Controller.

The output from the Fuzzy Logic Controller is the duration for a pump to run. How do I set up a timer so that it has the takes the output from the controller and uses this value to time the running of the pump so that the pump turns off once the duration value is met?

 

For context the temperature is measured and only when it is above zero does it move on to analyse the inputs for the fuzzy logic controller. The water level and Blockage % are the two inputs (4-20mA) into the fuzzy controller which then outputs a percentage of rotation and is then calculated to determine a running duration for the pump, (which is only if the percentage of rotation is above 33%) Once the pump has run for the duration it shuts down and the cycle begins again. 

 

Does the program make sense for what i am trying to achieve? Any help would be much appreciated. 

 

0 Kudos
Message 1 of 16
(427 Views)

One mark of someone who is "very new to LabVIEW" is they are probably using the most up-to-date version of LabVIEW (probably installed at school).  Most of the Experienced Developers who help out on these Forums don't update LabVIEW every year, and because of its graphic nature, LabVIEW VIs (and their Block Diagrams) cannot be opened and run in earlier versions of LabVIEW.  Our advice is to "Save for Previous Version" and specify LabVIEW 2019 or 2021 (which appear to be "popular choices" -- I happen to have both installed, but nothing more recent).  Similarly, please don't post "pictures" of your LabVIEW code, particularly if it has "wires running everywhere, with lots of changes in direction".

 

Have you looked at the Timing Functions?  Do you know how a While Loop runs?  Do you understand why those two questions are related to each other and a possible solution to your question?  [Personally, I dislike Express VIs, but some of the ones in the Timing Palette aren't too bad ...].

 

Bob Schor

Message 2 of 16
(416 Views)

Hi Bob, Thanks for the quick response.

 

I saved as a different version and saved as 21.0, is that the version for LabView 2021?

 

I have had a look at timing functions but i dont understand how i can use them to start the timer and the pump at the same time and stop the pump once the timer is done. I'm slightly more familiar with PLCs and ladder logic, so i guess i am looking for the done bit of the timer to de-energise the pump but not sure how to do this with labview. 

I think i need to use a while so that it stops when the timer is done but i'm not sure how this fits into the rest of the program. 

I'm assuming my program is a bit of a mess but i was hoping if i can try to explain it then i can get some guidance to get it to work. 

0 Kudos
Message 3 of 16
(407 Views)
  • First of all, you need to decide on a reasonable code architecture. Two sequential while loops, each with its own stop button is not reasonable.
  • Think state machine with exactly one toplevel loop. One state would be to turn on the pump and another state would be to check time, etc.
  • It is also super confusing if you have controls and indicators with exactly the same label.
  • There are better ways to define a path next to the VI. 
  • altenbach_0-1724273302806.png
  • I am sure your three analog channels are different, so why are they all zero by default? If they should not change during execution, maybe make the diagram constants or place the terminals before the loop,
  • Many of your diagram constants have the wrong representation.
  • Having long waits is not useful, because you cannot functionally interact with the program while it is trapped in the wait. Your loop needs to spin at a reasonable rate.
  • Note that you have a glaring race condition because the DO and the start of the wait occur in parallel. There is nothing that determines execution order. (And no, before you start throwing sequence structures at it, think again "state machine" where things naturally occur in the right order and change state as required.
  • Have a look at my old example here how to set and reset a timer.
Message 4 of 16
(375 Views)

Thanks for the feedback, it was really useful.

I have updated my program to be a state machine with states for the initial temperature check, the fuzzy inference system (FIS), motor on, check time and motor off. Does this meet what you had suggested? 

 

I had a look at your previous program but i am struggling to understand its application. With the state machine, i can change instruct the motor off once the check time state has completed but i am unsure how to set the variable for my timer. I would like the value of duration from the FIS state to be used to determine the length of the timer. How can i get that value to the check time state and how can i then use it to start the timer?


Please ,let me know if i need to correct anything. I dont know how to create that shorter path you previously mentioned for the fuzzy system. Is there a way to group the path or something?

0 Kudos
Message 5 of 16
(291 Views)

Sorry, I won't have access to a computer that can open LabVIEW 2021 for a few more days. Please do a "save for previous", LabVIEW 2020 or below, and attach again. Thanks.

0 Kudos
Message 6 of 16
(272 Views)

Thanks for getting back to me. Please see the file below.

 

 

0 Kudos
Message 7 of 16
(260 Views)

From some research, I think I may need to use a shift register to move the value of the duration from the temperature check state to the check time state. I'm not sure how this can be implemented though. Is this something I should look into further?

I think I am needing something like a 'move' function from a PLC program. I did see there is a move function for LabView but it mentions a file path so I don't think its used for moving variables. 

 

Thought I would just provide an update in case I'm heading in the wrong direction but i will keep investigating to see if I'm on the right track.

0 Kudos
Message 8 of 16
(244 Views)

Sorry, I was away all day, but when you do a "save for previous", you should zip up the entire resulting folder because we are missing lots of things (e.g. the typedefs)

 

Currently, the VI is also broken because of unwired tunnels.

Are zeroes really reasonable default values for most of your controls? Why are some controls hidden? Maybe it would be more reasonable to use diagram constants for values that the user is not supposed to change.

You are currently not doing any timing.

 

What is your "move" function supposed to do? (the on in the file IO palette basically renames a file). You can always right-click any function and call up the help for details.

 

Shift registers are great to maintain data across iterations, basically you read from the left, modify if needed or just wire across, then write the updated value back on the right. Very efficient!

 

I would recommend to leave out all the hardware IO and just simulate data to work out the overall logic. Much easier to debug!

Message 9 of 16
(236 Views)

No need to apologise I appreciate your time. 

 

The VI is incomplete because I am unsure how to set up the timing function. I have now created a shift register to take the value for duration to the check time state. I would like this value to be inputted into a timer and once this is complete the state changes to turn the motor off. Do I use a wait timer for this and one this is greater than or equal to the duration time the output would be true? 

 

For some reason when I converted the file to a previous version it reset all my controls to zero. Can I set the analogue/digital channels to a constant? Is that what you were suggesting?

 

I hid some controls as I repeated the motor controls to turn the motor off but I don't want to the see the control for the digital output again so I hid it. If i changed to a constant though I could get rid of this.

 

A PLC move function take a variable and moves it to another location, so I think this is similar to the shift register for Labview.

 

I have attached my updated version with the shift register and updated values while I make another version with the hardware IOs eliminated. 

 

0 Kudos
Message 10 of 16
(223 Views)