LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simultaneously inputting into local variable of a Numeric control whilst maintaining control.

Solved!
Go to solution

Hi Everyone,

 

I'm quite new to Labview so please bear with my lack of using techincal terms. I would also like to apologize in advance if this topic has already been discussed somewhere in the forum.

 

I'll try to be as brief as possible - I will be using Labview to control the speed of a DC Motor via PWM and would like to simultaenously have 1.) control of a knob that allows me to vary PWM (0-255) and 2.) be able to "set" the value of said control using indexed preset values.

 

To help better illustrate this please view the attached VI. When running the code all I can do is change the value of the control using the indexed preset values. So going back to my question - what changes do I have to make to the code in order to have the choice of using 1.) and 2.) simultaneously?

 

Any help would be greatly appreciated!

0 Kudos
Message 1 of 13
(3,471 Views)

It's a Data Flow "problem".  Follow the wire -- every time through the loop, you take whatever value is in Speed Selection and set it into Motor Speed.  If you were running really slowly (like once every 2-3 seconds), you could set the Motor Speed, see the dial where you left it, then watch it "snap" to the Speed Selection value as this part of the code executes.  Since you are running really very fast, you never see the dial move (because as fast as you try to move it, the Speed Selection is resetting it).

 

One way to do this is to have an Event Loop (do you know about these?) that looks at any changes in Speed Selection.  If it sees one, it sets Motor Speed as you've shown here, otherwise it simply waits, letting the dial work.

 

BS

Message 2 of 13
(3,451 Views)

Thanks for the reply Bob. 

 

Yes I thought I might have to use an event structure (I executed in highlighting mode and saw what you mean by the constant resetting of the PWM knob). 

 

I've been playing around with event structure for a while now but still to no avail. Should I be adding a timeout to help change this "resetting" feature? In the attached VI I tried doing this with a timeout of 100ms, but for some reason execution highlight mode is still demonstrating that the PWM knob is being resetted. In fact when I tried normally running the code, the knob no longer automatically changes via the selection of a desired speed value, and instead the knob needs to be manually moved before it actually inputs the desired amount. 

 

Do you think this could also have something to do with the fact that my knob operates in Integers and my array of values are in DBL format?

 

 

0 Kudos
Message 3 of 13
(3,425 Views)
Solution
Accepted by topic author 1cecream

After doing extensive research on event structures and property nodes, I finally found a solution.

 

Attached is the working version of a knob control that can be additionally maniuplated by a secondary control, yet still maintain it's own control capabilities (i.e no overriding or line-flow errors) 

 

I hope someone in the future will find this useful! 

0 Kudos
Message 4 of 13
(3,407 Views)

1cecream wrote:

I hope someone in the future will find this useful! 


Your VI is way to convoluted for such a simple task!

 

  • Mind your representations! (the output should be U8, but you mix U8, DBL, etc.).
  • Try to connect your terminals to the code. Reading and writing via local variables and signaling value property nodes is convoluted.
  • Try to stick with left-to-right wires. There is no need here to go right-left!

Here's a quick rewrite that corrects some of the deficiencies mentioned. There are may other ways to do this.

 

(You should also add another item to the radio control named e.g. "other". Now change the code such that if the manual control is changed to match any of the preset, the radio control should display that preset. For any other values, it should say "other". Try it! :D)

Message 5 of 13
(3,394 Views)

@altenbach wrote:

(You should also add another item to the radio control named e.g. "other". Now change the code such that if the manual control is changed to match any of the preset, the radio control should display that preset. For any other values, it should say "other". Try it! :D)

Here's a quick attempt. I allow "no selection" on the radio and whenever the speed does not match any of the presets, nothing shows as selected. Modify as needed. Let me know if anything is not clear.

Message 6 of 13
(3,356 Views)

Hi Altenbach,

 

I was wondering how I could make the event structure portion of your code into a SubVI. Attached is the culmination of numerous attempts trying to figure out dynamic event registration (.... so far I can say for sure that the "speed selection" event card won't work because "New Value" & "Old Value" are now referring to the refnum and not the control (how can I work around this)). However the Motor Speed PWM event card should work (when the knob matches one of the array values, the speed selected will also report to the "speed selection" control). Am I doing something wrong here? 

 

I came up with the attached solution using this document: http://digital.ni.com/public.nsf/allkb/A882E27D1D7A949386256E0D0066B91A

Download All
0 Kudos
Message 7 of 13
(3,294 Views)

Hi 1cecream, 

 

Could you describe a bit more about what you would like your application to do?  I'm not yet clear on why you want to put the event structure in a sub VI.  You are on the right track, using control references, but I'm guessing that some of the dataflow has been severed from the way it worked in Altenbach's posted example.  

0 Kudos
Message 8 of 13
(3,264 Views)

Hi WishKebab,

 

I want to put the event structure portion of Altenbach's original "MotorControlSpeed(with_event)MOD2" VI into a SubVI - I attempted this with my attached "SpeedMenuSubVI" and am seeing two major problems: A.) the "Speed Selection" card no longer works because part of the code uses "New Value & Old Value", and instead of referring to "Control - Speed Selection" the code is now programmed to refer to the refnum, so that part of the original code no longer works, B.) As you had mentioned I'm quite certain there is some kind of data flow problem as my top-level VI is unresponsive to the event structure outputs in my SubVI.

 

I have made some changes in hopes of working around these two issues but so far to no avail:

1.) Change the Event Timeout format

2.) Add a stand-alone Timeout event card

3.) Changed timeout to 100ms

4.) Add a new Event Structure card in hopes of fixing A.)

Download All
0 Kudos
Message 9 of 13
(3,256 Views)

To answer your question why I want to put the event structure portion into a SubVI - I am trying to make the code more compact as I intend to use a lot of the SpeedMenuSubVI control in a later project,

 

I thought I might warn you that Altenbach's original "MotorControlSpeed(with_event)MOD2" also has some kind of error that I didn't quite understand. What I found was that if I press OFF on the speed selection control, a value of (1/4)64 is inputted into the knob, and if I press 1/4, a value of (1/2)128 is inputted into the knob (i.e the two are out of sync by 1 increment). Not necessarily solving the issue, I was able to put a quick fix to this by manually rearranging the buttons in the speed selection cluster control (I am using this solution for my top-level and SubVI compilation). I still have no idea why this was occurring in Altenbach's original VI, because the initial arrangement of the clutser controls (0-OFF, 1-1/4, 2-1/2, 3-/3/4, 4-FULL) was right.

0 Kudos
Message 10 of 13
(3,247 Views)