From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machines and Shift Registers

Solved!
Go to solution

I am trying to create a VI that controls a power supply, a switch system, and a nanovoltmeter so that I can measure the Seebeck effect of different materials. Having browsed through these forums, it seemed that the overwhelming opinion was that the state machine is much better than stack structures, which was what i was initially going to use. However, I am having trouble. To control my sourcemeter, I have the user input the number of steps (times the machine increases voltage), a final voltage, and an initial voltage. From these I get the increment value. However, within my state machine only the first step is being transferred into the case structure. I have used probes to see how the information is moving, and it seems that the voltage value is incrementing properly but the actual VI for the power supply is only recieving the initial value. I am simply wondering how to pass the updated values into the case structure on each iteration.

 

I have included the vi. It is far from finished as I am sure you will see, but my current problem lies in the "volt change" case. That said, if anything pops out and you feel needs immediate attention, feel free to say so, as I am learning and accept all input.

0 Kudos
Message 1 of 8
(3,389 Views)

You should store the current voltage in a shift register as well and only increment it during the appropriate steps.

 

Right now, your voltage is a function of how many times the overall state machine as run since it is directly a function of the i termina of the while loop.

0 Kudos
Message 2 of 8
(3,355 Views)

I'm not completely sure that I understand. This is my first attempt at using a state machine, so I am not very familiar with how it works, but don't I want it to increment along with the while loop? The way that I understand is that for x number of increments, everything within the while loop will run x number of times, including everything within the case structure. This way, I can ensure that for each step up in voltage, the same measurements will be taken and will be added to the same file so that I can have both the resulting measurements (resistivity, Seebeck) and the raw data.

0 Kudos
Message 3 of 8
(3,346 Views)

You do not want to increment it along with the while loop.  The while loop is iterating on every state change -- you want to increment on every voltage change.  Example: by the time you run through the while loop once (at the save state) your i terminal is already at 6.  Is this then the terminal you want to use to set the next voltage?  This is also the reason your loop is stopping prematurely.

0 Kudos
Message 4 of 8
(3,325 Views)
Solution
Accepted by topic author gbaby

I recommend running your VI with Highlight Execution turned on.  That will help you understand what is happening better.

 

Just to reiterate, only 1 case in the case structure can run per iteration.  If you have a TRUE/FALSE case structure in the middle of a VI would you expect it to run both cases?  Of course not.  Same thing here.

 

So keep your current set voltage in a shift register and increment it only when you are in the set case.  Stop your state machine when your voltage has exceeded the stop voltage (have a state just to check this to make things easier on you).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 8
(3,318 Views)

Okay I think I understand now. I had been under the impression that the entire case structure ran through every iteration. This changes things but should allow me to move forward from where I am now.

 

Thank you all for commenting.

0 Kudos
Message 6 of 8
(3,314 Views)

Couple of suggestions:

 

- Initialisation is something you should only do once at the beginning, hence initial. You initialise your current source, output something, initialise measurement channel one, make a measurement, initialise measurement channel two, make a measurement, initialise channel three, make a measurement, do some calculations, save and then head back to initialising the current source again. You should be able to initialise most things outside the loop and then just update the scan/outputs at will within the state machine.

 

- Your state machine will run as follows thanks to the while loop (note i starts at 0 before you compare it with anything)

 

Iteration 0 - Init

Iteration 1 - Volt Change

Iteration 2 - Meas 1

Iteration 3 - Meas 2

Iteration 4 - Meas 3

Iteration 5 - Calc

Iteration 6 - Save

Iteration 7 - Init

Iteration 8 - etc...

 

So you can see that if your number of steps is, say, 7, you'll only get a single set of measurements done.

 

Edit - teach me to answer the phone whilst typing a post! 🙂

---
CLA
Message 7 of 8
(3,313 Views)

... and if keeping track of some administrative data in a shift register, you'll just have 1 Meas state used 3 times. 🙂

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 8
(3,292 Views)