1 / 54

Workshop 4 of 7

Welcome!. Workshop 4 of 7. Today's Topics. Review of Workshop 3 Sequence Structure Timing State Machine . Review Question 1. How many times must a For Loop iterate? A While Loop? 0,0 1,0 0,1 1,1. Review Question 1. How many times must a For Loop iterate? A While Loop? 0,0 1,0

hayes
Download Presentation

Workshop 4 of 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome! Workshop 4 of 7

  2. Today's Topics • Review of Workshop 3 • Sequence Structure • Timing • State Machine

  3. Review Question 1 • How many times must a For Loop iterate? A While Loop? • 0,0 • 1,0 • 0,1 • 1,1

  4. Review Question 1 • How many times must a For Loop iterate? A While Loop? • 0,0 • 1,0 • 0,1 • 1,1

  5. Review Question 2 • True or False? • The value passed to the case selector terminal determines which case will execute.

  6. Review Question 2 • True or False? • The value passed to the case selector terminal determines which case will execute. • TRUE

  7. Review Question 3 • A “hollow” output tunnel will appear on the edge of a case structure because…? • the wrong data type is wired to it • there is not a wire leading away from it • one or more cases do not have a wire leading to it

  8. Review Question 3 • A “hollow” output tunnel will appear on the edge of a case structure because…? • the wrong data type is wired to it • there is not a wire leading away from it • one or more cases do not have a wire leading to it

  9. Review Question 4 • Which of the following statements about Auto-indexing are true? (multiple answers possible) • When auto-indexing is enabled on an output tunnel, only one element can be passed out of the tunnel. • When auto-indexing is enabled on an input tunnel, only one element can be passed out of the tunnel • When auto-indexing is enabled on an output tunnel, the entire array is passed out of the tunnel • When auto-indexing is enabled on an input tunnel, the entire array is passed out of the tunnel

  10. Review Question 4 • Which of the following statements about Auto-indexing are true? (multiple answers possible) • When auto-indexing is enabled on an output tunnel, only one element can be passed out of the tunnel. • When auto-indexing is enabled on an input tunnel, only one element can be passed out of the tunnel • When auto-indexing is enabled on an output tunnel, the entire array is passed out of the tunnel • When auto-indexing is enabled on an input tunnel, the entire array is passed out of the tunnel

  11. Review Question 5 • The value of Result when the VI below finishes will be: • 15 • 18 • 22 • 28

  12. Review Question 5 • The value of Result when the VI below finishes will be: • 15 • 18 • 22 • 28

  13. Review Question 1 • True or False? • You must have at least one case in a Disable Diagram that is enabled.

  14. Review Question 1 • True or False? • You must have at least one case in a Disable Diagram that is enabled. • TRUE

  15. Review Question 2 • attached to the inside left border of each event case; identifies the data LabVIEW provides when an event occurs. • attached to the inside right border of filter event cases; identifies the subset of data available that the event case can modify • an indication that a user action has already occurred, such as when the user has changed the value of a control • inform you that the user has performed an action before LabVIEW processes it, which allows you to customize how the program responds to interactions with the user interface • Match the following: • Event Filter Node • Notify Event • Filter Event • Event Data Node

  16. Review Question 2 • attached to the inside left border of each event case; identifies the data LabVIEW provides when an event occurs. • attached to the inside right border of filter event cases; identifies the subset of data available that the event case can modify • an indication that a user action has already occurred, such as when the user has changed the value of a control • Informs you that the user has performed an action before LabVIEW processes it, which allows you to customize how the program responds to interactions with the user interface • Match the following: • Event Filter Node • Notify Event • Filter Event • Event Data Node

  17. Review Question 3 • Which of the following is true about the Event Structure? • An event structure will sleep while waiting for an event to occur • An even structure can process multiple events simultaneously • It is a good idea multiple event structures within a block diagram • Event structures are often used within a while loop

  18. Review Question 3 • Which of the following is true about the Event Structure? • An event structure will sleep while waiting for an event to occur TRUE • An even structure can process multiple events simultaneously FALSE • It is a good idea multiple event structures within a block diagram FALSE • Event structures are often used within a while loop TRUE

  19. Flat Sequence Structure • Executes each frame beginning with the left-most frame and ending with the right-most frame • The previous frame must complete before the next frame executes • Data can be passed out of or between frames using tunnels • Once the sequence begins, it cannot be stopped 1st 2nd 3rd

  20. Stacked Sequence Structure • Stacks each frame so you see only one frame at a time • Executes frame 0, then frame 1, etc. until the last frame executes • Returns data only after the last frame executes • To transfer data from frame to frame, a Sequence Local must be created (right-click » Add Sequence Local) • Once the sequence begins, it cannot be stopped Sequence Local

  21. Timing Functions • Control or measure the frequency at which a loop executes • Provide the processor with time to complete other tasks, such as processing the user interface • Uses the operating system millisecond clock

  22. Wait Function • Waits the specified number of milliseconds. • If 0 is wired to it, the current thread is forced to yield control of the CPU • Uses the operating system millisecond clock

  23. Wait Function- example cases • Loop would go to next iteration after 10 ms or more depending on amount of time the subVI takes. • If subVI takes >10 ms, loop goes as soon as subVI is done • If subVI takes <10 ms , loop goes at 10 ms mark. • Loop would go on to next iteration after 10 ms, because the only thing that happens in each iteration is wait 10 ms Moment next loop iteration can begin Wait Other code (running in parallel with Wait VI) 10 ms 20 ms 30 ms

  24. Wait Until Next Millisecond Multiple Function • Waits until a multiple of the millisecond value wired in • Provide the processor with time to complete other tasks, such as processing the user interface • Uses the operating system millisecond clock

  25. Wait Until Next Millisecond Multiple Function • Loop would go to next iteration after 10 , 20, 30, or a greater multiple of 10 ms depending on amount of time the subVI takes. • If subVI takes <10 ms , loop goes at 10 ms mark. • If subVI takes 16 ms, then the loop goes at 20 ms. • If subVI takes 22 ms, then the subVI goes at 30 ms. • Loop would go on to next iteration after 10 ms, because the only thing that happens in each iteration is wait 10 ms and 10ms is the first multiple of 10 Wait Other code (subVI) 10 ms 20 ms 30 ms

  26. Comparison of Timing Functions Red represents times when Wait functions are NOT restricting Moment next loop iteration can begin Other code (running in parallel with waits) 10 ms 20 ms 30 ms

  27. Demonstration: Comparing the Timing Functions

  28. VI Timing Types • Execution Timing • Provides the design pattern with a function that specifically allows the processor time to complete other tasks • In some cases, a Wait function is not necessary • Use of Timeout inputs can provide execution timing • Software Control Timing • Timing (pauses, waits, time checks) you put in place to make the code execute after a certain amount of time. • Example: • If you must acquire data for 5 minutes, you could remain in the acquisition state until the 5 minutes elapses. However, during that time you cannot process any user interface actions such as stopping the VI. To process user interface actions, you must implement timing (checking if 5 min has passed since the start of acquisition) so that the VI continually executes for the specified time

  29. VI Timing Execution Timing Software Control Timing

  30. State Machine Intro: Scenario • Want to create a program that does the following: • Reads a voltage • Tells user to turn on power supply • Read the voltage again now that power is on • Tell the user to turn off the power.

  31. Programming Designs: Sequential

  32. Sequential Programming

  33. Sequential Programming

  34. Sequential Programming

  35. Sequential Programming • What if you need to change the order of the sequence? • What if you need to repeat one item in the sequence more often than the other items? • What if some items in the sequence execute only when certain conditions are met? • What if you need to stop the program immediately, rather than waiting until the end of the sequence?

  36. State Machines • Implements a state diagram. • Programmatically determine which state is next • Different action if a quarter was inserted compared to return change requested

  37. State Machine • A state machine consists of a set of states and a transition function that maps to the next state • Each state can lead to one or multiple states or end the process flow While Loop Enum Case Structure Shift Register

  38. State Machine: Transition Code • State Functionality Code: • this state was entered to perform what function? • Transition Code: • which state is next?

  39. Demonstration: Execution of a State Machine

  40. Design Patterns: Single Loop • General VI • Three phases: Start-up, Main Application, and Shut-down

  41. Single Loop Design Pattern: in LabVIEW • General VI

  42. Single Loop Design Pattern • State Machine • Usually has a start-up and shut-down state, but also contains other states

  43. Single Loop Design Pattern • State Machine

  44. Parallelism • Parallelism: executing multiple tasks at the same time • Use case: • Need to acquire data very quickly, process it and save it to file. • If you do each step in a linear fashion and try to acquire all the data before processing, then you may run out of memory before processing begins. • If you do “sets” of steps (acquire, process, save, repeat), then you are missing the data points when the processing and saving are going on. • If only you could acquire, process, and save in parallel….good news, you can!

  45. Multiple Loop Design Pattern • Parallel Loop

  46. Multiple Loop Design Pattern • Producer/Consumer

  47. Multiple Loop Design Pattern • Master/Slave: a type of Producer/Consumer • uses notifiers to allow loops to run at different rates

  48. Notifiers • Pros: • Both loops are synchronized to the master loop—the slave loop only executes when the master loop sends a notification • You can use notifiers to create globally available data, making it possible to send data with a notification • Using notifiers creates efficient code—there is no need to poll to determine when data is available from the master loop • Cons: • Notifiers do not buffer data. • If the master loop sends another piece of data before the first piece of data has been read by the slave loops, that data is overwritten and lost.

  49. Queues • Queues are similar to notifiers, except that a queue can store multiple pieces of data • By default, queues work in a FIFO (first in, first out) manner • Use a queue when you want to process all data placed in the queue • Use a notifier if you only want to process the current data • Use the Queue Operations functions to create a queue for communicating data between sections of a block diagram or from another VI.

  50. Producer/Consumer with Queues Data type here determines the data type that can be placed in the queue

More Related