LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I control a component and monitor data from a sensor at the same time in LabVIEW?

Solved!
Go to solution

Hi NI community members,

 

I am currently working on a vi that serves 2 functions - to run a PTC heater at a user specified duty cycle and to acquire the data coming from a thermostat (I want to see how the temperature changes with duty cycle). 

I want to be able to run both functions together (and also have the option to run just 1 of them at a given point of time), and have therefore added separate RUN and a STOP buttons for each.

 

I have put 2 case structures inside a big while loop. Each case structure looks at the value of the RUN button for one of the tasks - and runs that part accordingly. The big while loop is so that I can RUN and STOP parts of the program multiple times during one run cycle of the vi.

 

The problem I am facing is that I am unable to run both functions simultaneously. If I am sending a PWM to the heater, I am unable to monitor the thermostat. Pressing the RUN button for data acquisition lines the task up, and it does start to acquire data but only after I have stopped sending a PWM signal to the heater. This also happens the other way around, with the vi not sending out a PWM unless I have stopped data acquisition.

I want to be able to see the temperature changes in real time as I change the duty cycle of the PWM going into the PTC heater. The issue I mentioned earlier completely defeats this purpose. 

I am attaching the vi here. If someone could please help me figure the issue out, I would feel so grateful.

Thank you in advance!


0 Kudos
Message 1 of 7
(1,250 Views)

There are 3 while loops - 2 nested inside the 3rd. The way it is currently set up, once one of the inner loops starts running, the outer loop stops until the inner loop is stopped. The only way to have both running at the same time is to have both case structure Booleans set to true when initially starting the main (outer) loop.

 

Keep in mind that a loop will only "loop" if the functions inside that loop have completed. In you vi both inner loops do not stop/complete until you hit the stop for that inner loop therefore you can never start the other inner loop.

 

Robert

0 Kudos
Message 2 of 7
(1,214 Views)
Solution
Accepted by topic author viamotors

I encourage you to investigate a state machine design. Use one state machine for analog input and another for counter output. Each state machine might have states for Initialize, Run, Close, and Idle. The END button would stop both while loops. No other coupling between temperature measurement and heater control state machines would be necessary - you can completely remove the outer loop.

Doug
NI Sound and Vibration
0 Kudos
Message 3 of 7
(1,169 Views)

Note that a key idea in Doug's post is that rather than having the case structure around the loop, you should have the loop around the (each) case structure.

 

As he said, you also won't need an outer loop in this case.

A more detailed description of state machines can be found here: State Machine.

 

A related idea is to use an Event Structure to send messages into your loops to control them. This can make, amongst other things, handling the Stop condition easier for multiple loops.

 

demoCB_snippet.png

cbutcher_0-1622782688455.png

cbutcher_1-1622782705807.png

(snippet with extra images of some other frames).

 

Here I considered using messages for the sensor too, but it wasn't a great fit and just having it run continuously seems more reasonable.

If you need to stop/start it, then you could add messages too. I'd probably suggest a different queue, because you'll need to handle repeatedly acquiring without potentially blocking the queue for the Heater (shouldn't be a problem, but worth considering in that case).

 

 

 


GCentral
Message 4 of 7
(1,161 Views)

Thank you so much for your help. Using state machines resolved this issue.

0 Kudos
Message 5 of 7
(1,067 Views)

Thank you for your assistance and tips! It was of great help.

0 Kudos
Message 6 of 7
(1,066 Views)

Thank you, your input really helped me figure out what the underlying issue was. 

0 Kudos
Message 7 of 7
(1,063 Views)