DOC PREVIEW
PSU EE 200 - Lab_19_EE200_s14

This preview shows page 1-2-3-4-5-6-41-42-43-44-45-46-83-84-85-86-87-88 out of 88 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 88 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ColorGrayscaleEE 200 Spring 2014Lab 19.EE 200Design ToolsLaboratory 19Professor Jeffrey SchianoDepartment of Electrical Engineering1EE 200 Spring 2014Lab 19.Laboratory 19 Topics• LabVIEW Programming– Race Conditions– Synchronization Tools– Properties for Front Panel Objects– Control References– Implicitly and Explicitly Linked Property Nodes2EE 200 Spring 2014Lab 19.Race Conditions: What Are they?• Race Condition - A situation where the timing of events or the scheduling of tasks may unintentionally affect an output or data value• Race conditions are a common problem for programs that execute multiple tasks in parallel and share data between the tasks3EE 200 Spring 2014Lab 19.Exercise 1 Demo• Demonstrate race condition using two VIs4EE 200 Spring 2014Lab 19.Exercise 1 Demo• Start Counter 1.vi and press the stop button after several seconds– Verify that Count 1 = Loop 1 Iterations• Restart Counter 1.vi, then start Counter 2.vi. Press the stop button on the front panel of Counter 1.vi– Do both VIs stop executing?– Does Count 2 = Loop 2 Iterations? Why not?– Does Loop 1 Iterations + Loop 2 Iterations = Total Count?– Why is Loop 1 Iterations + Loop 2 Iterations > Total Count?5EE 200 Spring 2014Lab 19.Exercise 1 Solution• Why is Loop 1 Iterations + Loop 2 Iterations > Total Count?• Consider the following race condition: – Suppose Count = 3– VI 1 reads Count = 3– Before VI 1 increments Count, VI 2 increments Count so that Count = 4– VI 1 increments and saves Count = 4, instead of Count = 5 – VI 1 misses the fact that VI 2 incremented the Count• Eliminate the race condition by insuring that VI 2 cannot increment Count after VI 1 reads, and before it updates, Count6EE 200 Spring 2014Lab 19.Eliminating Race Conditions• A critical section of code is code that may behave inconsistently if some shared resource is altered while it is running, for example, in Exercise 1• If one loop interrupts another loop while it is executing critical code, then a race condition can occur• Eliminate race conditions by identifying and protecting critical code with:– Functional Global Variables– Synchronization Tools 7EE 200 Spring 2014Lab 19.Exercise 1• Shared resource: global variable count8• Critical codeEE 200 Spring 2014Lab 19.Protecting Critical Code with a FGV• Place the critical code section within a FGV• Because the FGV is a non-reentrant VI, only one instance of the FGV can run at a time• What are non-reentrant VIs?9EE 200 Spring 2014Lab 19.Non-Reentrant and Reentrant VIs• Non-Reentrant VIs (default)– When LabVIEW calls the same subVI from multiple locations within either the same VI or different VIs, only one instance of that subVI can run at a time– This limitation occurs because the subVI reserves only a single space in memory to store its data, so all instances of the subVI must take turns using that data space• Reentrant VIs– Separate data space allocated for each instance of the VI– Multiple instances of reentrant VIs can execute in parallel without interfering with each other VIs• All FGV VIs must be non-reentrant10EE 200 Spring 2014Lab 19.Exercise 2• Eliminate the race condition in Exercise 1 by replacing the Global Variable Count with a functional global variable• The functional global variable should have three actions– CLEAR: Set Count = 0– INCREMENT: Set Count = Count +1 – READ: Get the value of Count• In the Exercise 2 directory, open and complete the case structure in FGV count.vi11EE 200 Spring 2014Lab 19.Exercise 2• First create a FGV count.vi – Use an enumerated type FGV action that has three items: CLEAR, INCREMENT and READ12EE 200 Spring 2014Lab 19.Exercise 2• Verify FGV count.vi is a non-reentrant VI– File >> VI Properties >> Category = Execution13EE 200 Spring 2014Lab 19.Exercise 214• Complete Counter 1.vi and Counter 2.vi as shown belowEE 200 Spring 2014Lab 19.Exercise 2• Start Counter 1.vi, then start Counter 2.vi• After several seconds press the stop button on the front panel of Counter 1.vi– Does Loop 1 Iterations + Loop 2 Iterations = Total Count?15EE 200 Spring 2014Lab 19.Protecting Critical Code with Synchronization Tools• LabVIEW uses data flow to manage code execution sequencing • Dataflow programming allows multitasking, for example, running multiple loop structures in parallel• Lab 19 exercise 1 reveals that a race condition results when two loops simultaneously access a shared resource such as a local or global variable• Synchronization tools allow the user to coordinate the parallel execution of code16EE 200 Spring 2014Lab 19.Synchronization Tools• LabVIEW synchronization tools available in the Programming >> Synchronization palette– Semaphores– Notifiers– Queues– Rendezvous– Occurrences– First Call?17EE 200 Spring 2014Lab 19.Synchronization using Semaphores• A semaphore is a tool for limiting the number of tasks that can simultaneously operate on a shared (protected) resource• A protected resource or critical section of code might include writing to global variables or communicating with external instruments18EE 200 Spring 2014Lab 19.Semaphore Operation• Use a semaphore to protect two or more critical sections of code that should not be called concurrently• Before entering a critical section, the executing code must acquire a semaphore• If the critical section is not already executing– The critical section is executed– Other portions of the code are blocked from using the critical section until the current execution is complete19EE 200 Spring 2014Lab 19.Programming a Semaphore• Create a semaphore• Place the Acquire Semaphore and Release Semaphore VIs at the beginning and end, respectively, of each critical section• Each VI using the critical section can obtain and release the semaphore one at a time to assure proper data control• Terminate use of the semaphore using the Release Semaphore Reference VI20EE 200 Spring 2014Lab 19.Semaphore Palette21EE 200 Spring 2014Lab 19.Exercise 3• Eliminate the race condition in Exercise 1 by protecting the critical code sections in Counter 1.vi and Counter 2.vi using a semaphore• Name the semaphore Protect Count22EE 200 Spring 2014Lab 19.Exercise 323EE 200 Spring 2014Lab 19.Exercise 3• In the Exercise 3 directory, complete Counter 1.vi as below• Observe how the error cluster directs program flow24EE 200 Spring 2014Lab 19.Exercise 3• In the Exercise 3 directory,


View Full Document

PSU EE 200 - Lab_19_EE200_s14

Download Lab_19_EE200_s14
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab_19_EE200_s14 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab_19_EE200_s14 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?