Professional Documents
Culture Documents
Zad 14
Zad 14
Scenario
Complete the course project using a state machine and the state flow chart
developed earlier in the course.
Design
You have already completed the design stage for this project. The inputs and
outputs and flowchart are repeated here.
Initialize
Acquisition
Time Elapsed=TRUE
and
Stop=False
Warning=TRUE
Analysis
Datalog
Time Elapsed=FALSE
and
Stop=FALSE
Time Check
Warning=FALSE
Stop=TRUE
Implementation
In the following steps, you set up the state machine in the Weather Station
UI VI.
q Right-click the Case structure and select Add Case for Every
Value from the shortcut menu.
5. Place a Wait function in the loop so that the processor can handle other
tasks when needed.
q Place a Wait (ms) function inside the While Loop, outside the
Case structure.
6. Pass the temperature cluster into the state machine so that it can be
accessed from any state.
Acquisition State
Hardware
q Place the DAQ Assistant in the Acquisition state.
q Skip to step 3.
No Hardware
q Select the Temperature Simulator VI in the Project Explorer
window and drag it into the Acquisition state. In future steps, you
wire the inputs and outputs of the Temperature Simulator VI instead of
the DAQ Assistant.
q Wire the data output of the DAQ Assistant to the Temperature History
terminal. Notice that the waveform graph data type automatically
changes to match the incoming data.
4. Update the temperature cluster with the current temperature, upper limit,
and lower limit.
q Move the Upper Limit and Lower Limit terminals into the
Acquisition state.
q Wire the Upper Limit terminal to the T Upper Limit element of the
Unbundle by Name function.
q Wire the Lower Limit terminal to the T Lower Limit element of the
Unbundle by Name function.
q Wire the enumerated type constant to the output state shift register.
Analysis State
In previous exercises, you wrote a subVI that performs the analysis required
for this state machine: Determine Warnings VI. This VI is already added to
the project file, but needs to be placed in the main VI.
q Wire the enumerated type control to the output state shift register.
q Wire the enumerated type constant to the tunnel of the Case structure.
4. Pass the error cluster and file refnum into the state machine so that it can
be used by all states.
q Place the Write To Text File function in the Data Log state.
q Wire the output of the Format Into String function to the text input of
the Write To Text File function.
q Wire the error clusters to and from the Write To Text File function.
q Wire the file refnum to and from the Write To Text File function.
q Place the Close File function to the right of the state machine.
q Wire the error cluster and the file refnum to the Close File function.
q Place a Simple Error Handler to the right of the Close File function.
q Wire the error out terminal from the Close File function to the
Simple Error Handler.
8. Place a copy of the Weather Station State enumerated type control inside
the Data Log state.
3. Determine when half a second has passed since the last data acquisition.
q Place the Elapsed Time Express VI on the block diagram inside the
While Loop, but outside the Case structure.
q Wire the Time has Elapsed terminal from the Elapsed Time
Express VI to the case selector.
q Place a copy of the Weather Station State constant inside the True
case.
5. Navigate to the Time Check state if the time has not elapsed.
q Place a copy of the Weather Station State constant inside the False
case.
2. Determine when to stop the state machine. Stop when an error occurs or
the user has clicked the stop button, but only after a full sequence has
occurred (Acquisition, Analysis, Data Log).
q Wire the status element of the error cluster to the top input of the Or
function.
q From the Time Check state, wire the Stop button to the bottom input
of the Or function.
3. Set the Elapsed Time Express VI to start counting when the VI begins.
q Place a True constant outside the While Loop, to the left of the
Elapsed Time Express VI.
q Wire the constant to the Reset terminal of the Elapsed Time Express
VI.
Testing
1. Run the VI.
5. Modify the Lower Limit until it is higher than the current temperature
reading.
8. Modify the Upper Limit until it is lower than the current temperature
reading.
11. The Upper Limit < Lower Limit Warning should appear.