![Page 1: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/1.jpg)
336540Design of Bio-Medical Virtual Instrumentation
Tutorial 2
![Page 2: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/2.jpg)
Outline
• Debugging techniques • Structures: – While loop – For loop
![Page 3: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/3.jpg)
Debugging Techniques
• Broken VI
![Page 4: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/4.jpg)
Debugging Techniques
• Non broken VI– Execution highlighting- generates an animation of the
execution of the block diagram.
– Single stepping
– Breakpoints
– Probe tools – helps checking intermediate values in a VI that produces unexpected results
![Page 5: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/5.jpg)
Exercise 11. What is the problem with the next diagram?
2. Fix the following VI:
![Page 6: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/6.jpg)
Structures
![Page 7: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/7.jpg)
While loop
• Analog to: Repeat (code) ;Until Condition met;End;
code
Condition met ?
end
No?
Yes
![Page 8: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/8.jpg)
• Iteration terminal – contains the number of completed iterations. Starts at zero.
• Continue if true – the while loop executes its subdiagram until the condition teminal recieves a FALSE value.
• Stop if true - the while loop executes its subdiagram until the condition teminal recieves a TRUE value.
While loop always executes at least once!
![Page 9: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/9.jpg)
Structure Tunnels
Tunnels feed data into and out of structures. The tunnel apears as a solid block on the border of the While loop.
• What happens if we run the VI with a Boolean value of False?
![Page 10: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/10.jpg)
For loop
• Analog to: N=100;i=0;Until i=N;
Repeat(code);i=i+1;
End;
N=100
i=N?
end
No?Yes
i=0
Code
i=i+1
![Page 11: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/11.jpg)
• Iteration terminal – contains the number of completed iterations. Starts at zero.
• Count terminal – input terminal whose value indicates how many times to repeat the subdiagram
![Page 12: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/12.jpg)
Conditional terminal to a for loop
• You can add a conditional terminal to configure a For loop to stop when a Boolean condition is met or an error occurs.
• The For loop will execute until the condition occurs OR until the all iterations are complete.
![Page 13: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/13.jpg)
Exercise 2
What will the indicator display after this program has run?
![Page 14: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/14.jpg)
Timing a VI
• Wait until Next ms Multiple – monitors a millisecond counter and waits until the millisecond counter reaches a multiple of the amount you specify.
• Wait (ms)- waits until the millisecond counter counts to an anount equal to the input.
• Time elapsed- the amount of time elapses after the specified start time.
![Page 15: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/15.jpg)
Iterative Data Transfer – Shift Register
Used when wanting to pass values from previous iterations through the loop to the next iterations.
![Page 16: 336540 Design of Bio-Medical Virtual Instrumentation Tutorial 2](https://reader033.vdocuments.site/reader033/viewer/2022052304/56649f3a5503460f94c57d03/html5/thumbnails/16.jpg)
Exercise 3
• Create a VI which raffles a random number (between 0-1) in each iteration and compares it to the number from the last iterations
• If the current random number is smaller than the previous one, stop the loop.
• Returns the number of iterations.