background image

 

 

 

 

 

 

 

 

 

 

 

 

 

Warszawa, 2003

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Tradycyjne NI-DAQ
Określone VI do 
obsługi:
• wejść analogowych
• wyjść analogowych
• we/wy cyfrowych
• liczników

NI-DAQmx
Następna generacja
driverów: 
• VI do wykonywania 
zadań
• Jeden zestaw VI do 
wszytkich typów 
pomiarów

Akwizycja danych w LabVIEW

 

The Data Acquisition palette in LabVIEW contains a palette for traditional NI-DAQ and one for 

NI-DAQmx. 

Traditional VIs are divided by the type of measurement; DAQmx VIs are divided by the type of 

task. 

 

You must complete several steps before you can use the Data Acquisition VIs. The devices should 

be configured for the computers in this class. 

 

NI-DAQ software must be installed on the computer 

You must have installed an E-series DAQ board and configured it using Measurement & 

Automation Explorer (MAX). 

 

For more information on installing and configuring National Instruments hardware, consult the 

DAQ Quick Start Guide: 

http://digital.ni.com/manuals.nsf/websearch/E502277FE33ED60686256B3B0056AEDF?OpenDocu

ment&node=132100_US 

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Tradycyjny NI-DAQ - woltomierz

 

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Tradycyjny NI-DAQ – symulowany 

woltomierz

All Functions>Time&Dialog>Tick Count

 

Ponieważ nie dysponujemy czujnikiem temperatury i kartą DAQ, stwórzmy symulator próbkowania 

jednego kanału.   

Wykorzystaj funkcję Tick Count z palety All Functions/Time&Dialog. 

Stwórz ikonę kopiując wzór z AI Sample Channel 

Nie zapomnij o konektorze  

Zapisz jako AI Sample Channel Demo.vi i zastąp nim AI Sample Channel w przyrządzie 

WoltomierzTradycyjny.vi, zapisz jako WoltomierzTradycyjnySym.vi 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

„Ekspresowe” VI z DAQ Assistant

 

You can launch the DAQ Assistant in several ways. Complete the following steps to launch the 

DAQ Assistant from a LabVIEW block diagram. 

1. Open LabVIEW and create a New VI. Switch to the block diagram (Ctrl+E). 

2. The DAQ Assistant Express VI is located in the Input subpalette of the Functions palette. Place 

the DAQ Assistant on the block diagram by dragging and dropping it from the Functions palette. 

The Assistant should automatically launch when you drop the VI on the diagram.  

When you place this Express VI on the block diagram, the DAQ Assistant launches to create a new 

task. After you create a task, you can double click the DAQ Assistant Express VI in order to edit 

that task. For continuous measurement or generation, place a while loop around the DAQ Assistant 

Express VI.  

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

DAQ Assistant - konfiguracja

 

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

DAQ Assistant – możliwe opcje

 

 

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

DAQ Assistant – konfiguracja, cd.

 

In this example, we will configure a simple voltage analog input measurement. For other 

measurement and signal generation types, you would follow similar steps.  

1.       On the first screen, select Analog Input for your Measurement Type.  

2.       Next, select Voltage.  

3.       The next screen lets you select the physical channel (or channels) for which you are creating 

this task. All supported data acquisition hardware devices should appear in the tree control, and you 

can expand them to view a list of the physical channels that you can select for your task. To select 

more than one channel, hold down the Ctrl button while clicking on the channel names. 

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Konfigurowanie zadania

1. Określ zakres sygnału mierzonego. 

Jeśli go nie znasz, możesz 
wykorzystać domyślne max 5 V, 

min -5 V.

2. Wybierz konfigrację podłączenia 

sygnału. 

3. W zakładce

Task Timing

wybierz 

liczbę próbek (1, określona ich 
liczba lub próbkowanie ciągłe).

4. Określ częstotliwość 

próbkowania.

5. Możesz także określić tryb 

wyzwalania i skalowanie.

 

After you create a task, you can configure channel-specific settings such as scaling, input limits, and 

terminal configuration. You also can configure task-specific settings such as timing and triggering.  

In this task, you do not need to use scaling or triggering. To configure the voltage measurement 

task, complete the following steps.  

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Pomiary napięcia z wykorzystaniem DAQ 

Assistant

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Symulacja z wykorzystaniem Express VI

1

Zaznacz AI Sample Channel 
Demo.vi 
wraz z wejściami i 

skasuj

2

Wybierz z palety Functions>Input funkcję
Simulate Signal i nanieś na schemat blokowy w 

opróżnione miejsce

 

Zamiast DAQ Assistant zastosujemy Simulate Signal Express VI 

Wykorzystajmy stworzony już WoltomierzTradycyjnySym.vi 

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Konfiguracja Symulatora Sygnałów

3

Skonfiguruj jak 

na rysunku obok

 

 

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Konfiguracja Symulatora i konwersja 

danych

4

5

 

4. Do wejścia Phase podłącz funkcję Tick Count z palety All Functions/Time&Dialog dzieląc 

sygnał ms przez 17.5 (tu faza jest w stopniach, więc wynik będzie podobny do dzielenia przez 1000 

gdy kąt był w radianach 

5. Symulator sygnałów generuje tzw. Dynamic Data. Zamienimy je na pojedynczą wartość 

(średnią). W tym celu weź z palety Functions/Signal Manipulation Express VI Form DDT i 

wybierz „Single Scalar” jako „Resulting data type” 

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Symulowany Woltomierz (Express VI)

Dokończ połączenia i zapisz jako WoltomierzExpressSym.vi

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Pętle (Loops)

• For Loop— wykonuje podprogram 

zadaną liczbę razy

• While Loop—wykonuje podprogram spełnienia warunku końca

 

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Pętla While

Ma terminal licznika iteracji

Zawsze jest wykonywana 

przynajmniej raz

Jest wykonywana do 

spełnienia warunku końca

 

While Loops 

Similar to a Do Loop or a Repeat-Until Loop in text-based programming languages, a While Loop, 

shown at the top right, executes a subdiagram until a condition is met. The While Loop executes the 

sub diagram until the conditional terminal, an input terminal, receives a specific Boolean value. The 

default behavior and appearance of the conditional terminal is Continue If True, shown at left. 

When a conditional terminal is Continue If True, the While Loop executes its subdiagram until the 

conditional terminal receives a FALSE value. The iteration terminal (an output terminal), shown at 

left, contains the number of completed iterations. The iteration count always starts at zero. During 

the first iteration, the iteration terminal returns 0. 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

1. Wybierz pętlę While

(Functions>All Functions>While Loop)

Pętla While cd.

3. Puść klawisz myszy.

2. Obrysuj kod, który ma być powtarzany

4.   Dodaj funkcję lub 

zadajnik kończący 

powtarzanie

 

While Loops execute a sequence of events while a condition is True  (analogous to a “Do...While” 

statement). 

Place loops in your diagram by selecting them from the Structures palette of the Functions palette 

(demonstrate): 

When selected, the mouse cursor becomes a special pointer that you use to enclose the section of 

code you want to repeat. 

Click the mouse button to define the top-left corner, click the mouse button again at the bottom-

right corner, and the While Loop boundary is created around the selected code. 

Drag or drop additional nodes in the While Loop if needed. 

While Loop functionality: 

A While Loop executes the code contained inside it until a Boolean False is passed to the 

conditional terminal.  Thus, it always executes at least once. 

The iteration terminal contains the number of executions (zero-indexed). 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Pętla While Express

1. Wybierz While Loop

2. Obrysuj kod, który ma być powtarzany

3. Puść klawisz myszy. 

Boolean control
utworzy się 
samoczynnie

 

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Unikanie nieskończonej pętli

ŹLE!

DOBRZE

 

If you place the terminal of the Boolean control outside the While Loop, as shown in left Figure, 

and the control is set to FALSE if the conditional terminal is Stop if True when the loop starts, you 

cause an infinite loop. You also cause an infinite loop if the control outside the loop is set to TRUE 

and the conditional terminal is Continue if True. value is only read once, before the loop starts. To 

stop an infinite loop, you must abort the VI by clicking the Abort button on the toolbar. 

background image

 

Common questions: 

Why isn’t the number of iterations updated each time through the loop?  Because the While 

Loop passes out its values only after it terminates.  To update at each iteration, place the terminal 

inside the loop. 

Why do I need to increment the iterations by one?  Because the iteration terminal is zero-

indexed. 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

• Dostępne na lewej lub prawej krawędzi struktury pętli
• Kliknij prawym klawiszem na krawędzi i wybierz Add 

Shift Register 

• Prawy terminal przechowuje wynik na koniec iteracji
• Lewy terminal dostarcza wynik z poprzedniej iteracji

Pierwsza

iteracja

Druga 

iteracja

Ostatnia

iteracja

Initial Value

Value 1

Value 1

Value 2

Value 2

Value 3

wynik

a

Rejestry przesuwne

Shift Registers

a+5

a+5

a+10

a+n*5

 

Use shift registers when you want to pass values from previous iterations through the loop. A shift 

register appears as a pair of terminals, shown at left, directly opposite each other on the vertical 

sides of the loop border. The right terminal contains an up arrow and stores data on the completion 

of an iteration. LabVIEW transfers the data connected to the right side of the register to the next 

iteration. Create a shift register by right-clicking the left or right border of a loop and selecting Add 

Shift Register from the shortcut menu. 

 

A shift register transfers any data type and automatically changes to the data type of the first object 

wired to the shift register. The data you wire to the terminals of each shift register must be the same 

type. 

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Inicjalizacja wartości rejestrów przesuwnych

przebieg 1

Wartość 

początkowa = 5

Zainicjowane

Niezainicjowane

Wartość 

początkowa = 5

Wartość 

początkowa = 0

Wartość 

początkowa = 8

przebieg 2

 

Initialize a shift register by wiring a control or constant to the shift register terminal on the left side 

of the loop. Initializing a shift register resets the value the shift register passes the first time the loop 

executes when the VI runs. If you do not initialize the register, the loop uses the value written to the 

register when the loop last executed or the default value for the data type if the loop has never 

executed. 

Use a loop with an uninitialized shift register to run a VI repeatedly so that each time the VI runs, 

the initial output of the shift register is the last value from the previous execution. Use an 

uninitialized shift register to preserve state information between subsequent executions of a VI. 

After the loop executes, the last value stored in the shift register is output from the right terminal. 

Left column - 

Initialize the shift register with a 5 so every time the VI is run, the shift register starts out with a 

value of 5. 

Right column- 

No initialization, so the first time the VI is run, the shift register has a value of 0.  The next time it is 

run, however, it contains the value at the last iteration of the previous run (in this example, a 8).  

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

“Prawy klik” 

na terminalu

i dodanie 

elementu

Dodatkowe elementy rejestrów 

przesuwnych

Z poprzedniej iteracji
Dwie iteracje temu
Trzy iteracje temu

wartości poprzednie są 

dostępne w terminalach 

po lewej stronie

Wynik bieżącej iteracji 

przekazywany do 

prawego terminala

 

 

You can add more than one shift register to a loop. If you have multiple operations that use previous 

iteration values within your loop, use multiple shift registers to store the data values from those 

different processes in the structure. 

 

You can configure the shift register to remember values from several previous iterations. 

Right click on the left terminal and choose Add Element to create additional terminals. 

The shift register allows you to access values from the past three iterations if you have three 

terminals. 

This method is different from using separate shift registers: 

One shift register with added terminals is storing multiple previous values of one variable. 

Multiple shift registers maintain a single previous value of multiple variables.  

Demonstrate the difference between adding a shift register vs. adding an element to a shift register. 

 

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Ćwiczenie: Ruchoma średnia.vi

Opracuj program losujący co 0,1 s liczby (0-1), 

wyświetlający je oraz obliczający i wyświetlający 

średnią z trzech ostatnich do odwo

ł

ania. W pętli 

dodaj opóźnienie.

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Funkcje opóźniające

 

 

Time Delay  

Inserts a time delay in the Express VI.  

 

Wait (ms) 

Waits the specified number of milliseconds and returns the value of the millisecond timer. This 

function makes asynchronous system calls, but the nodes themselves function synchronously. 

Therefore, it does not complete execution until the specified time has elapsed 

 

Wait Until Next ms Multiple 

Waits until the value of the millisecond timer becomes a multiple of the specified millisecond 

multiple. Use this function to synchronize activities. You can call this function in a loop to control 

the loop execution rate. However, it is possible that the first loop period might be short. This 

function makes asynchronous system calls, but the nodes themselves function synchronously. 

Therefore, it does not complete execution until the specified time has elapsed. 

 

background image

Politechnika Warszawska, Wydział Inżynierii Produkcji, Instytut Technologii Maszyn

Działanie przełączników boolean

Switch When Pressed

—Zmienia wartość zadajnika przy każdym razem jego 

przełączeniu (kliknięciu). Działanie podobne do wyłącznika światła na ścianie. 

Switch When Released

— Zmienia  wartość zadajnika dopiero po zwolnieniu 

klawisza myszy w trakcie klikania w jego obrębie. 

Switch Until Released

— Zmienia  wartość zadajnika gdy klikniesz w jego obrębie, 

jednakże zmieniona wartość trwa do chwili gdy zwolnisz klawisz myszy, po czym 

wraca do pierwotnej wartości. Działanie podobne do dzwonka przy drzwiach. 

Latch When Pressed

— Zmienia  wartość zadajnika gdy go klikniesz. Zmieniona 

wartość trwa do chwili, gdy VI odczyta ją raz, po czym wraca do domyślnego 

stanu. 

Latch When Released

—Zmienia wartość zadajnika po zwolnieniu klawisza 

myszy po kliknięciu. Zmieniona wartość trwa do chwili, gdy VI odczyta ją raz, 

po czym wraca do domyślnego stanu. 

Latch Until Released

— Zmienia  wartość zadajnika gdy go klikniesz i utrzymuje 

zmienioną wartość do chwili gdy zwolnisz klawisz myszy lub gdy VI odczyta tę 

wartość  – zależnie od tego, co nastąpi później.

 

Switch When Pressed—Zmienia wartość zadajnika przy każdym razem jego przełączeniu 

(kliknięciu). Działanie podobne do wyłącznika światła na ścianie. Odczytywanie wartości zadajnika 

przez VI nie wpływa ja jego działanie. 

Switch When Released— Zmienia wartość zadajnika dopiero po zwolnieniu klawisza myszy w 

trakcie klikania w jego obrębie. Odczytywanie wartości zadajnika przez VI nie wpływa ja jego 

działanie. 

Switch Until Released— Zmienia wartość zadajnika gdy klikniesz w jego obrębie, jednakże 

zmieniona wartość trwa do chwili gdy zwolnisz klawisz myszy, po czym wraca do pierwotnej 

wartości. Działanie podobne do dzwonka przy drzwiach. Odczytywanie wartości zadajnika przez 

VI nie wpływa ja jego działanie. 

Latch When Pressed— Zmienia wartość zadajnika gdy go klikniesz. Zmieniona wartość trwa do 

chwili, gdy VI odczyta ją raz, po czym wraca do domyślnego stanu. Działanie to nie zależy do tego 

czy  trzymasz klawisz myszy wciśnięty czy nie. Bardzo przydatne do zatrzymywania pętli While, 

lub innych zadań, w których VI ma wykonać coś raz za każdym razem gdy klikniesz zadajnik. 

Latch When Released—Zmienia wartość zadajnika po zwolnieniu klawisza myszy po kliknięciu. 

Zmieniona wartość trwa do chwili, gdy VI odczyta ją raz, po czym wraca do domyślnego stanu. 

Takie działanie gwarantuje przynajmniej jedno odczytanie zadajnika.  

Latch Until Released— Zmienia wartość zadajnika gdy go klikniesz i utrzymuje zmienioną 

wartość do chwili gdy zwolnisz klawisz myszy lub gdy VI odczyta tę wartość – zależnie od tego, co 

nastąpi później.