LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure - stepper motor not controlled by variable

Solved!
Go to solution

I have a state machine which includes some event structures. These event structures are used to control stepper motors using an Arduino Mega micro-controller. I am using labview 2012.

The input to one of the events is the "pour input" variable. I want to use this to control the motor speed and direction.

 

If I control the motor as shown in the attached image Working.jpg, then the motor functions correctly. If I attach the motor to the # steps variable then the motor moves at the defined speed in the appropriate direction according to whether the "Pour Input" is positive or negative.

 

However, I want to control the motor speed, not the number of steps, with the variable "Pour Input". I have checked that the values read by the INPUT_VALUE indicator in the image not working are in the same range as the values specified, which work, using the input "Set Speed". When I connect the Input value to the stepper speed pin of the Arduino (not_working.jpg) icon the motor turns, seemingly indefinitely at maximum speed. I do not understand why there is a difference in motor behaviour between the value supplied to the motor speed input by these two methods. I'm confused by this and don't know where to go from here.

 

Does the event structure somehow behave differently when taking a value from outside the structure to that given inside? or is there something going on with the initiation of the structure on its first loop through?

 

I have also attached my whole vi, although it may not be the easiest to follow and requires an arduino Mega to run.

 

 

 

0 Kudos
Message 1 of 5
(3,147 Views)

@Carlr wrote:

I have a state machine which includes some event structures. These event structures are used to control stepper motors using an Arduino Mega micro-controller. I am using labview 2012.

The input to one of the events is the "pour input" variable. I want to use this to control the motor speed and direction.

 

If I control the motor as shown in the attached image Working.jpg, then the motor functions correctly. If I attach the motor to the # steps variable then the motor moves at the defined speed in the appropriate direction according to whether the "Pour Input" is positive or negative.

 

However, I want to control the motor speed, not the number of steps, with the variable "Pour Input". I have checked that the values read by the INPUT_VALUE indicator in the image not working are in the same range as the values specified, which work, using the input "Set Speed". When I connect the Input value to the stepper speed pin of the Arduino (not_working.jpg) icon the motor turns, seemingly indefinitely at maximum speed. I do not understand why there is a difference in motor behaviour between the value supplied to the motor speed input by these two methods. I'm confused by this and don't know where to go from here.

 

Does the event structure somehow behave differently when taking a value from outside the structure to that given inside? or is there something going on with the initiation of the structure on its first loop through?

 

I have also attached my whole vi, although it may not be the easiest to follow and requires an arduino Mega to run.

 

 

 


I would recommend reading the help for event structures, especially the Caveats and Recommendations when Using Events in LabVIEW before continuing.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 5
(3,138 Views)
Solution
Accepted by topic author Carlr

@Carlr wrote:

I have a state machine which includes some event structures. These event structures are used to control stepper motors using an Arduino Mega micro-controller. I am using labview 2012.

The input to one of the events is the "pour input" variable. I want to use this to control the motor speed and direction.

 

If I control the motor as shown in the attached image Working.jpg, then the motor functions correctly. If I attach the motor to the # steps variable then the motor moves at the defined speed in the appropriate direction according to whether the "Pour Input" is positive or negative.

 

However, I want to control the motor speed, not the number of steps, with the variable "Pour Input". I have checked that the values read by the INPUT_VALUE indicator in the image not working are in the same range as the values specified, which work, using the input "Set Speed". When I connect the Input value to the stepper speed pin of the Arduino (not_working.jpg) icon the motor turns, seemingly indefinitely at maximum speed. I do not understand why there is a difference in motor behaviour between the value supplied to the motor speed input by these two methods. I'm confused by this and don't know where to go from here.

 

Does the event structure somehow behave differently when taking a value from outside the structure to that given inside? or is there something going on with the initiation of the structure on its first loop through?

 

I have also attached my whole vi, although it may not be the easiest to follow and requires an arduino Mega to run.

 

 

 



You have a very inappropriate "state-machine" design - even though you don't have same event in more than one of your event structures (besides for timeout), seems like you're not letting some of your processing to go forward until you receive a very specific event (and during which none of your other user-events are being processed).

 

I would strongly suggest that you first fix state-machine design - perhaps follow Producer/Consumer Design Pattern (Events) rather than having everything in one loop the way you have it.  If you must keep everything in one loop, you should consider redesigning so that you at least allow events to process instead of sitting in a loop for indefinite time!

 

In any case, in the case that is working, you're feeding "Set Speed (Steps per Second)" variable to stepper write vi.  But in the other case you're feeding value of "Pour input" - are they both the same? And so you know, you're only sending stepper write command when the value of Pour Input changes.

 

That's a big mess!  To start, look at the attached image, get rid of your event structure that has "Pour input" and replace it with what I have showed in the image. (In fact, all of your event structures can/should be replaced with similar logic. Doesn't seem like you need event structure in any of this, you're just making it more complicated than it needs to be!

 

-DP

 

Untitled.png

--------------------------------------------------------

New Controls & Indicators made using vector graphics & animations? Click below for Pebbles UI


0 Kudos
Message 3 of 5
(3,120 Views)

DP,

 

Thanks for your input. Could you please tell me what the icon between the I16 and not equals to icons is, I cant seem to find it in any of my menus, and therfore can't recreate the code you gave to test it.

 

 

0 Kudos
Message 4 of 5
(3,102 Views)

It is a "Feedback node", right click on your block diagram and you'll find it under "structures" (usually the top submenu).

 

-DP

--------------------------------------------------------

New Controls & Indicators made using vector graphics & animations? Click below for Pebbles UI


0 Kudos
Message 5 of 5
(3,094 Views)