Vous êtes sur la page 1sur 40

Ti liu hng dn thc hnh Labview Lu hnh ni b

TI LIU HNG DN THC HNH LABVIEW

PHN 1: HNG DN CI T
1. Ci t phn mm Labview.

Bc 1. a a CD cha phn mm ci t Labview 8.5 hoc cc phin bn


mi hn vo a CD ca my tnh. Chn file labVIEW.exe. Sau chn Next
nh hnh v sau.

Hnh 1.1. Hng dn ci t LabVIEW


Bc 2. in thng tin tn v ni lm vic ca bn. Chn ci dng th.

GV: Trnh V Bo Khoa CNKT in TH

Page 1

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.2. Hng dn ci t LabVIEW


Bc 3. Ci theo cu hnh.

Hnh 1.3. Hng dn ci t LabVIEW


GV: Trnh V Bo Khoa CNKT in TH

Page 2

Ti liu hng dn thc hnh Labview Lu hnh ni b

Bc 4. n nt Next nh hnh di y.

Hnh 1.4. Hng dn ci t LabVIEW


Bc 5. n Next ta c.

GV: Trnh V Bo Khoa CNKT in TH

Page 3

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.5. Hng dn ci t LabVIEW


Bc 6.

Hnh 1.6. Hng dn ci t LabVIEW


Bc 7.

Hnh 1.7. Hng dn ci t LabVIEW


GV: Trnh V Bo Khoa CNKT in TH

Page 4

Ti liu hng dn thc hnh Labview Lu hnh ni b

Bc 8.

Hnh 1.8. Hng dn ci t LabVIEW


Chn Later v my hi ci Driver.

GV: Trnh V Bo Khoa CNKT in TH

Page 5

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.9. Hng dn ci t LabVIEW


Khi ny chng ta hon thnh vic ci t phn mm LabVIEW v bt u c th
s dng n.
PHN 2: THC HNH LUYN TP
Bi 1: Thc hnh s dng vng lp
1. Xy dng bi ton gim st nhit .

Mc ch:
- Xy dng VI v s dng cu trc vng lp While Loop v hin th d liu
ln biu sng di dng thi gian thc.
- Xy dng mt VI o nhit v hin th gi tr nhit ln biu
sng s dng VI nhit k nh l mt subVI,
1.1. Xy dng s khi.
S khi c dng nh sau:
GV: Trnh V Bo Khoa CNKT in TH

Page 6

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.68. S khi hin th bi ton o nhit di dng sng


1. Chn Window Show Diagram hin th s khi
2. Vy quanh 2 thit b u cui vo bn trong vng lp
3. Chn vng lp While Loop t Function Structures
4. Kch v ko chut sao cho vng lp ny bao quanh 2 terminal.
5. S dng cng c Positioning tool ko mt gc ca vng lp rng ra.

6.

Chn Functions Select a VI sau theo ng dn n VI

Thermometer m bn xy dng trong bi tp 3.2v t n vo trong s khi.


VI ny s tr v gi tr o nhit t cm bin nhit .
7. Ni dy cc i tng trong s khi.
8. Lu li VI di tn Temperature Monitor.vi
9. Hin th front panel bng vic kch n trc tip hoc bng vic chn
Window Show Panel.
GV: Trnh V Bo Khoa CNKT in TH

Page 7

Ti liu hng dn thc hnh Labview Lu hnh ni b

10. S dng cng c Operating Tool kch vo chuyn mch v bt n v v


tr ON.
11. Chy VI
12. Vng lp While Loop l mt vng lp hu hn v ph thuc vo iu kin
kim tra ca vng lp. Trong v d ny khi chuyn mch v v tr ON (TRUE) VI
nhit k s tr v mt gi tr o nhit mi v hin th n ln trn gin sng.
13. Kch vo chuyn mch v v tr OFF (FASLE) dng vic thu nhn tn
hiu t cm bin v kt thc vng lp.
14. Vic cu hnh t l xch cho trc X v Y ca gin sng c thc hin
nh sau:
15. Kch chut phi vo gin v chn Y Scale Formating t menu. Hp
thoi sau s xut hin.

Hnh 1.69. Thay i t l xch th sng


GV: Trnh V Bo Khoa CNKT in TH

Page 8

Ti liu hng dn thc hnh Labview Lu hnh ni b

16.

Bn chn cc thng s t l xch cho cc trc c dng ging nh trn

hnh v.
17. Kch chut phi vo gin sng v chn Data Operation Clear Chat
t menu xa b m hin th v reset gin sng. Nu VI ang chy chn
Clear Chart t menu.
1.2. Cc tc ng c kh ca cc chuyn mch.
Bn cn phi ch ti mi thi im chy VI, bn cn phi bt chuyn mch v
ri sau mi n nt Run. Vi Labview bn c th thay i hot ng ca chuyn
mch. Vic la chn tc ng ca chuyn mch bao gm: Chuyn mch khi n
(Switch when Pressed), chuyn mch khi gii phng (Switch when Released),
chuyn mch cho n khi gii phng ht (Switch Until Released), gi khi n
(Latch When Pressed), gi khi gii phng ht (Latch When Realeased), gi cho
n khi gii phng ht (Latch Until Released).
V d chng ta xem xt cc chuyn mch sau:
Gi tr mc nh ca chuyn mch l OFF (FASLE):

Switch When Pressed.


Thay i gi tr iu khin ti thi im bn kch iu khin bng cng c
Operating tool.

Switch When Released.


GV: Trnh V Bo Khoa CNKT in TH

Page 9

Ti liu hng dn thc hnh Labview Lu hnh ni b

Thay i gi tr iu khin ch sau khi bn gii phng chut ra ngoi vng gii
hn ca iu khin.

Switch Until Released.


Thay i gi tr iu khin khi bn kch iu khin v gi nguyn gi tr mi
cho n khi bn gii phng chut, gi tr thi im sau s quay v gi tr
gc.

Latch When Pressed.


Thay i gi tr iu khin khi bn kch vo iu khin v gi gi tr mi cho
n khi VI c tip gi tr ln sau.

Latch When Released


Thay i gi tr iu khin ch sau khi bn gii phng chut

Latch Until Released


Thay i gi tr iu khin khi bn kch iu khin v gi gi tr cho n khi VI
c gi tr tip theo hoc cho n khi bn gii phng chut
18. Thay i chuyn mch khi nhit c v trn th nhng thi im
m bn chy VI.
-

Dng VI nu n ang chy.

S dng Operating tool kch vo chuyn mch v bt n v v tr ON.

GV: Trnh V Bo Khoa CNKT in TH

Page 10

Ti liu hng dn thc hnh Labview Lu hnh ni b

Kch chut phi vo chuyn mch v chn Data Operation Make


Current Value Default t menu. iu ny nhm mc ch thit lp trng
thi mc nh l ON.

Kch chut phi vo chuyn mch v chn Mechanical Action Latch


When Pressed t menu.

Chy VI.

S dng Operationing Tool kch vo chuyn mch dng vic thu nhn
d liu v ngc li t v tr OFF sang v tr ON.

1.3. Thm chc nng thi gian (Timing).


Khi VI chy, hot ng ca vng lp While Loop din ra rt nhanh. Tuy nhin,
i lc bn mun ly d liu trong mt khong thi gian no v d nh sau mi
mt giy hoc sau mi mt pht.
iu khin vic lp ny theo thi gian bng cch bn s dng chc nng Wait
Until Next ms Multiple c ly t Functions Time & Dialog. Hm ny m
bo chc chn rng vng lp s khng thc hin nu n nh hn thi gian t tnh
theo n v ms.

GV: Trnh V Bo Khoa CNKT in TH

Page 11

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.70. Giao din s khi


-

Thay i VI thc hin o sau 0.5 giy mi ln.

Hm Wait Until next ms Multiple nm trong Function Time &

Dialog c chc nng nh b Timer, sau 0.5 giy vng lp thc hin lp mt
ln.
-

Hng s 500 nm Functions Numeric. Khi ni ti hm Wait Until


next ms Multiple hng s thi gian i l 500ms (na giy).

Lu VI.

Chy VI v thay i vi cc gi tr thi gian lp khc nhau.

2. Lm vic vi thanh ghi dch.


Mc ch.

GV: Trnh V Bo Khoa CNKT in TH

Page 12

Ti liu hng dn thc hnh Labview Lu hnh ni b

Xy dng mt VI minh ha cch s dng cc thanh ghi dch truy cp


cc gi tr t cc vng lp trc.
Xy dng front panel.
2.1. M front panel v to nh hnh v di y.

Hnh 1.76. Giao din front panel


Trong X(i) hin th gi tr hin ti.
X(i-1) hin th gi tr sau mt vng lp.
X(i-2) hin th gi tr sau hai vng lp
2.2. Hin th s khi v m bo chc chn rng c hai giao din s
front panel v s khi u c hin th. Nu cn thit ng v di
chuyn Tools v Functions. Ni 0 vi bn tri terminal khi to gi tr
ban u cho thanh ghi dch l 0.
Xy dng s khi.

GV: Trnh V Bo Khoa CNKT in TH

Page 13

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.77. Giao din s khi


1.

Kch vo nt HighLight Execution nh hnh bn tri cho php


hot ng lm sng.

2.

Chy VI v quan st kt qu. Nu kt qu di chuyn qu nhanh th ta


c th n Pause v Step Over nh hnh bn tri lm hot ng chm li.

3. Trong mi mt ln lp ca vng lp While Loop, VI chuyn gi tr trc


sang bn tri terminal ca thanh ghi dch. Mi mt ln lp ca vng lp s
cng 5 vi gi tr hin ti X(i). Gi tr ny c dch sang bn tri terminal,
X(i-1) ti thi im bt u ca vng lp tip theo. Trong v d ny VI gi
3 gi tr cui. gi nhiu gi tr th cn phi thm nhiu phn t sang tri
terminal ca thanh ghi dch.
4. ng VI
Bi tp luyn tp

GV: Trnh V Bo Khoa CNKT in TH

Page 14

Ti liu hng dn thc hnh Labview Lu hnh ni b

1. Xy dng VI o nhit 1 giy/1 ln v hin th nhit trn scope


chart. Nu nhit vt qu ngng trn v nh hn ngng di cho
trc th VI s nhy n bo.
Bi 2: Thc hnh vi biu
1. Xy dng VI tnh gi tr nhit trung bnh.
Mc ch.
s dng cc thanh ghi dch tnh gi tr trung bnh.
iu chnh VI gim st nhit tnh gi tr trung bnh 3 nhit c o
ln cui v biu din gi tr trung bnh ln biu sng.
Xy dng front panel
1.1. M VI gim st nhit trong bi tp o v bin i nhit C sang nhit
F front panel c dng sau.

Hnh 1.78. Giao din front panel


1.2. Chn File Save As v t tn l VI Temperature Running Average.vi
Xy dng s khi
1. Xy dng s khi c dng nh sau.
GV: Trnh V Bo Khoa CNKT in TH

Page 15

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.79. Giao din s khi


2. Kch chut phi vo bn phi hoc bn tri ca ng vin ca vng lp
While Loop v chn Add Shift Resigter t menu to thanh ghi dch.
3. Kch chut phi vo bn tri ca terminal ca thanh ghi dch chn Add
Element t menu thm mt phn t vo thanh ghi dch.
4. iu chnh s khi c dng nh trn.

5.

Chn Functions Select a VI theo ng dn n a ch lu VI


nhit k c to ra trong bi tp 3.2 v t VI vo trong s khi. VI ny
tr kt qu gi tr nhit o t cm bin nhit v c s dng khi
to bn tri thanh ghi dch trc khi vng lp bt u.

GV: Trnh V Bo Khoa CNKT in TH

Page 16

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hm cng s hc nm v tr Functions Numeric cho kt qu tng


ca nhit hin ti v 2 gi tr nhit c trc . t cng c Positioning tool
ti gc ca hm cho n khi con tr thay i hnh dng nh

hnh bn tri .

Kch vo gc v ko b cng cho n khi xut hin 3 u vo.


B chia nm Functions Numeric thc hin php chia ly gi tr
trung bnh ca 3 gi tr nhit c c cui cng.
Trong mi ln lp ca vng lp While Loop, nhit k VI s cho mt kt qu
gi tr nhit o. VI cng gi tr nhit ny vi 2 gi tr nhit o nm bn
tri terminal ca thanh ghi dch. VI ny chia kt qu cho 3 tnh gi tr trung bnh
ca 3 ln o, ln o hin thi cng vi hai ln o trc . VI ny hin th gi tr
trung bnh ln biu dng sng. Ch rng, VI khi to gi tr ban u cho thanh
ghi dch vi b o nhit .
6. Lu li VI
7. Chy VI.
Nhng biu biu din nhiu tn hiu.
-

Cc biu c th biu din nhiu hn mt tn hiu. Bn cn phi gom cc

tn hiu li trong trng hp nhiu tn hiu u vo.


-

iu chnh s khi c th hin th 2 gi tr: gi tr trung bnh v gi tr

nhit hin ti trn cng mt biu dng sng.


-

iu chnh s khi sao cho ging vi s khi di y.

GV: Trnh V Bo Khoa CNKT in TH

Page 17

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.80. Giao din s khi


-

Hm Bundle (hm b) nm v tr Functions Cluster. Hm ny

dng b, nhm gi tr nhit trung bnh v nhit hin ti, phc v cho vic
v ln biu sng.
-

Nt Bundle xut hin nh hnh bn tri khi bn t n vo trong s

khi. Bn c th thm cc phn t b sung bng vic s dng Positioning tool


-

Lu v chy VI. VI ny biu din 2 ng tn hiu ln biu sng. Cc

th ny chng ln nhau.
-

iu chnh trc y.
S dng cng c Labeling Tool kch vo 70 ca t l Y g 75 v n

Enter.
-

S dng cng c Labeling Tool kch s th hai di trc y thay i s

ny ln 77.5 hoc l 80. S ny xc nh gin cch ca trc y.

GV: Trnh V Bo Khoa CNKT in TH

Page 18

Ti liu hng dn thc hnh Labview Lu hnh ni b

V d: nu s trn s 75 l 77.5 c ngha l gin cch trc y l 2.5, cn nu l


thay 77.5 bng 80 th gin cch s l 5.
-

Kch chut phi vo biu sng v chn Visible Items Scale Legend t

menu ch ra li gii thch.

Hnh 1.81. To nhn cho cc trc ta


-

S dng Scale Legend thay i cho mi trc.

G vo trong nhn scale ca li gii thch hoc g trc tip ln nhn ca

biu thay i tn nhn cho trc.


-

Kch vo nt AutoScale i vi trc Y iu chnh cc gi tr nh nht v

ln nht ph hp vi gi tr ca d liu. kha ch Autoscale n vo


chuyn mch Lock Autoscale.
-

Kch vo nt Scale Format thay i nh dng, mc chnh xc, ch

nh x v cc la chn li cho mi trc.


-

S dng cng c Operating tool kch vo Scale Legend xem cch

chng lm.
ch mc nh biu sng biu din ch thch th. Bn c th di
chuyn cc ch thch ny bt k u trn front panel.
GV: Trnh V Bo Khoa CNKT in TH

Page 19

Ti liu hng dn thc hnh Labview Lu hnh ni b

Kch chut phi vo biu dng sng v chn Visible Items Graph
Palette t menu hin th bng mu th. Bng mu th cng c th di
chuyn mi v tr trn front panel. th bao gm cc la chn sau:

Hnh 1.82. Chn cc dng th


S dng nt lnh zoom phng to mt phn hay ton b th. Nt Pan
cho php bn kch v ko thanh cun trong biu . Nt lnh Return to Standard
Mode quay v trng thi ban u.
Lu v chy VI. Trong khi bn chy VI s dng cc nt lnh thay i
trn biu dng sng.
Dng VI v lu li.
Bi tp luyn tp
1. Lp trnh v th ca hm bc hai y = ax2 + bx+ c

GV: Trnh V Bo Khoa CNKT in TH

Page 20

Ti liu hng dn thc hnh Labview Lu hnh ni b

Bi 3 Thc hnh cu trc tun t v cu trc la chn


1. Xy dng mt VI tnh cn bc hai.
Mc ch: S dng cu trc la chn gii bi ton tnh cn bc hai.
Xy dng mt VI kim tra mt s xem nu n l s dng, VI tnh gi tr
cn bc hai ca s , cn ngc li n s a ra mt thng bo.
Ch : Khng chy VI ch Continuously.
Xy dng front panel.
-

M mt VI mi.

Xy dng front panel nh hnh di y.

Hnh 1.154. Giao din s front panel


iu khin s c tn l Number cung cp s u vo. Gi tr cn bc hai
c hin th trn b hin th c tn Square Root Value nu s u vo dng.
Xy dng s khi.

GV: Trnh V Bo Khoa CNKT in TH

Page 21

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.155. Giao din s khi

GV: Trnh V Bo Khoa CNKT in TH

Page 22

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.156. Giao din s khi


-

M s khi

Chn mt cu trc la chn v m rng n trn s khi. ch mc

nh, cu trc la chn kiu Boolean. N s t ng thay i sang dng s nu


bn ni ti n mt iu khin s. Bn cng c th ch hin th mt trng hp
trong mt thi im. thay i cc trng hp, kch vo mi tn ng vin
pha trn ca cu trc la chn (Case Structure).
-

Chn mt s khi khc v ni chng nh hnh trn


Hm so snh ln hn hoc 0. Trong bi tp ny hm ny kim tra s nhp

vo dng. Hm ny tr v kt qu True nu s nhp vo ln hn hoc bng 0.


Hm ly cn bc hai (ly t Functions Numeric) hm ny tr vgi tr
cn bc hai ca gi tr u vo.
GV: Trnh V Bo Khoa CNKT in TH

Page 23

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hng s.

One Button Dialog (Time & Dialog) - hm ny biu din mt hp


thoi cha thng bo Error Negative Number.

Hm String Constant (String) nhp mt dng text vo bn


trong hp thoi vi Operationing tool.
Trong bi tp ny VI hot ng hoc l True hoc Fasle. Nu s ny ln hn
hoc bng 0 VI s hot ng trong trng hp True. Trng hp True ny s tr v
gi tr cn bc hai ca s u vo. Trng hp Fasle, u ra l gi tr -99999.0 v
hin th mt hp thoivi thng bo Error Negative Number.
-

Lu VI vi tn Square Root.vi

Quay tr v front panel v chy VI, th nhp mt s ln hn bng 0 v mt

s nh hn bng 0.
-

ng VI.

2. Xy dng bi ton iu khin nhit .


Mc ch: S dng cu trc la chn.
Bn s thay i Temperature Running Average VI pht hin khi m gi
tr nhit nm ngoi di. Nu nhit vt qua gi tr gii hn LED trn front
panel s sng v mt ting ku Bip.
3. Xy dng Time to Match.vi
Mc ch: Xy dng mt VI thc hnh vi cu trc tun t.
Xy dng mt VI tnh ton thi gian n pht ra mt s ngu nhin sao
cho ph hp vi s bn a ra.
Xy dng s front panel.
GV: Trnh V Bo Khoa CNKT in TH

Page 24

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.159. Giao din s front panel


-

Thay i front panel nh hnh trn. Thay i cc iu khin v hin th

nh c m t.
-

S dng lnh Save as lu VI tn l Time to Match.vi


Xy dng s khi.

GV: Trnh V Bo Khoa CNKT in TH

Page 25

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.160. Giao din s khi


-

M s khi chn cu trc tun t (Sequence Structure) t Functions

Structures v ko mt vng xung quanh cc node.


-

Thm mt Frame vo cu trc tun t bng cch kch chut phi vin ca

Frame v chn Add Frame After.

GV: Trnh V Bo Khoa CNKT in TH

Page 26

Ti liu hng dn thc hnh Labview Lu hnh ni b

m bo vng lp While Loop nm bn trong Frame 0. Quay tr v

Frame cha vng lp While Loop kch chut phi vin Frame v chn Make
This Frame 0.
-

Xy dng s khi nh hnh trn.

Hm Tick Count(ms) (Time & Dialog) hm ny c gi tr hin

ti thi gian ca h iu hnh v tr v gi tr n v ms. u tin hm Tick


Count (ms) c ng h ca h iu hnh v tr gi tr ca n theo n v l ms.
Trong Frame 0 VI hot ng trong vng While Loop min l s c t khng
ph hp vi s m hm ngu nhin tr v. Trong Frame 1 hm Tick Count (ms)
c li thi gian ca h iu hnh ri sau tr gi tr mi vi gi tr ban u v
tr v gi tr thi gian qua tnh theo giy.
-

Lu VI v quay tr v front panel.

Nhp mt s vo bn trong iu khin Number to Match. Chy VI.

Nu Time to Match lun lun c l 0, VI ca bn c th chy qu nhanh.

VI chy chm li, hoc l chy vi vic cho php Execution HighLighting hoc
l tng gi tr trong s khi, gi tr ny nhn vi s ngu nhin vi gi tr ln v
d nh 100.
4. S dng Formula Node tnh ton theo mt biu ton hc c th
(Formula Node Exercise.vi)
Mc ch: Xy dng mt VI s dng Formula Node
Bn xy dng mt VI s dng Formula Node nh gi mt biu thc
phc tp v hin th kt qu ln Graph.
Xy dng front panel

GV: Trnh V Bo Khoa CNKT in TH

Page 27

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.161. Giao din s khi


-

M mt VI mi.

Xy dng front panel nh hnh trn. Graph hin th s biu din th ca

phng trnh y = f(x)3 + f(x) trong f(x) = tanh(x)+ cos(x).


Xy dng s khi

Hnh 1.162. Giao din s khi s dng hm Formula Node


-

Xy dng s khi nh hnh trn

GV: Trnh V Bo Khoa CNKT in TH

Page 28

Ti liu hng dn thc hnh Labview Lu hnh ni b

Formula Node c ly t Functions Structures. Bn nhp trc tip cc

biu thc. to ra u vo X ca terminal kch chut phi vo ng vin v


chn Add Input t menu phm tt. Bn to u ra y bng cch chn Add Output
t menu phm tt. Bn cng cn phi to mt u ra trunggian nh mt u ra.
-

Khi bn to mt u vo v u ra. Bn cn phi t tn cho n


Hng s- trong v d ny n chnh l s vng lp ca vng lp For

Loop.
-

Divide Function trong v d ny thc hin php chia s vng lp cho

Trong mi mt vng lp, VI s chia s vng lp cho gi tr 15. Thng s

15.

ca php chia c ni vo Formula Node, n tnh gi tr ca cc phng trnh.


Sau VI cha kt qu trong mt mng ti bin vng lp For Loop. Sau khi vng
lp For Loop kt thc VI s v mng ny.
-

Lu VI vi tn Formula Node Exercise.vi

Quay tr li front panel chy VI.

ngVI.

Bi tp luyn tp.
1. Xy dng mt VI s dng Formula Node tnh cc phng trnh sau:
y1 = x3 + x2 +5
y2 = m*x +b
GV: Trnh V Bo Khoa CNKT in TH

Page 29

Ti liu hng dn thc hnh Labview Lu hnh ni b

Ch s dng mt Formula Node cho 2 phng trnh. Nh phi t du phy


sau mi phng trnh trong node.
2. Xy dng mt VI c chc nng nh mt my tnh. Trn front panel c cc
b iu khin s nhp 2 s u vo v b hin th s biu din kt qu ca cc
php ton (cng, tr, nhn, chia) thc hin trn hai s.

Bi 4 Thc hnh chui v file I/O


1 Build String.vi
Mc ch:Xy dng mt SubVI s dng cc chc nng Format Into String,
Concatenate String, String Length.
Bn xy dng mt VI c chc nng bin i mt s sang mt chui v ni
chui ny vi mt chui khc thnh mt chui u ra. VI cng xc nh chiu di
ca chui. VI kim tra chui v bin i chui sang dng s.
Xy dng giao din front panel

Hnh 1.196. Giao din front panel.


GV: Trnh V Bo Khoa CNKT in TH

Page 30

Ti liu hng dn thc hnh Labview Lu hnh ni b

M mt VI mi.

Xy dng giao din front panel nh hnh trn. Thay i cc iu khin v


hin th nh miu t di y.
Thc hin chc nng ghp ni u vo t 2 iu khin chui v iu khin

s thnh mt chui u ra v hin th chiu di chui.


VI cng tm kim du hai chm trong iu khin String 2 v bin i chui
sau du hai chm thnh thnh s, gi tr offset past match cng c hin th.
Xy dng s khi.

Hnh 1.197. Giao din s khi


-

Xy dng s khi theo hnh trn vi cc cu trc lnh sau:

Hm Format Into String (String) bin i mt s nhn c t b


iu khin s c tn l Number thnh chui.

GV: Trnh V Bo Khoa CNKT in TH

Page 31

Ti liu hng dn thc hnh Labview Lu hnh ni b

to nh dng chui %.4f, kch chut phi vo hm Format Into String v


chn Edit Format String. T hp thoi Edit Format String to ra nh dng
chui.
-

nh du vo hp thoi Use Specified Precision v g s 4 bin i s

thnh chui vi 4 s sau s thp phn.

Hnh 1.198. Thit lp s sau s thp phn


-

n nt Create String: Hm ny t ng to chui hng v ni n ti u vo

format string.
Hm Concatenate String (String). Trong bi tp ny, hm ny ghp
tt c cc u vo chui thnh mt chui u ra. tng s lng cc u vo,
thay i kch thc ca hm bng vic s dng Positioning tool.
Hm String Length (String) cho bit s cc k t trong chui ghp
ni.

GV: Trnh V Bo Khoa CNKT in TH

Page 32

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hm Match Pattern hm ny tm du hai chm ca chui nhp vo.


To regular expression string bng vic kch chut phi ln u vo terminal v
chn SelectConstant.
Hm Scan from String bin i mt chui sau du hai chm thnh
mt s.
-

Quay v giao din front panel to ra mt biu tng v kt ni nh di

y.

Hnh 1.199. Hm Build String


-

Lu VI vi tn Build String.vi: Nhp mt on vn bn vo trong 3 iu

khin chui v strong iu khin s, chy VI.


2. File Writer.VI
Mc ch: Ghi d liu vo File.
Bn xy dng mt VI c chc nng ghp ni mt chui thng bo, mt s,
mt chui n v v ghi vo file.
Xy dng front panel

GV: Trnh V Bo Khoa CNKT in TH

Page 33

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.200. Giao din s khi.


-

M mt VI mi v xy dng front panel nh hnh trn.


Front panel bao gm 2 chui v mt iu khin dng s. iu khin String

to Write dng nhp mt thng bo ghi vo file. Cc iu khin Number to


Write v iu khin Unit to Write dng nhp cc gi tr ca chng v ghi vo
file. To ra mt ng dn t String and Path. Hin th ny hin th ng dn
file d liu bn to ra.
-

Chuyn vo giao din s khi.


Xy dng s khi.

GV: Trnh V Bo Khoa CNKT in TH

Page 34

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.201. Giao din s khi.


-

Xy dng s khi nh hnh trn. Cc hm c m t nh di y.

VI Build String c ly t Select a VI. VI ny c dng ghp


ni 3 chui u vo thnh mt chui kt hp u ra.

Open/Create/Replace File VI c ly t File I/O. VI ny dng


m mt hp thoi m hoc to mt File.
(Kch chut phi vo Terminal Prompt chn Create
Constant l mt thng bo m hp thoi s hin th tn file nhp vo.
(kch chut phi vo Function VI v chn Create
Constant) cho bit l to ra mt file mi hay thay th mt file c. S dng
Operationing tool thay i gi tr thnh Create hay Replace.

GV: Trnh V Bo Khoa CNKT in TH

Page 35

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hm Write File (ly File I/O). Hm ny dng ghi mt chui


ghp vo mt file.

Hm Close File (ly File I/O). Hm ny dng ng file.

Hm Simple Error Handler (c ly Time & Dialog). VI ny


dng kim tra li v hin th mt hp thoi khi c li xut hin.
-

Lu VI vi tn File Writer.vi

Nhp cc gi tr vo trong cc iu khin giao din front panel v chy


VI. Mt hp thoi c m v hin th mt thong bo Enter Filename
bn nhp mt tn file v d c tn demo.txt vo trong hp thoi v kch vo
nt Save hoc OK.

By gi bn i xy dng mt VI dng m file v c ni dung ca file.

3. File Reader.vi
Mc ch: dng c d liu t file.
Bn xy dng mt VI dng c ni dung file trong bi tp trc v hin
th thong tin c c vo trong mt hin th dng chui nu password ca ngi
s dng ph hp vi password t t VI Build String.
Xy dng giao din front panel.

GV: Trnh V Bo Khoa CNKT in TH

Page 36

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hnh 1.202. Giao din s front panel.


-

M mt VI mi v xy dng giao din front panel nh hnh trn.


Giao din front panel bao gm ng dn hin th v tr ca file text v mt

hin th dng chui, hin th ny hin th thng tin c c t file.


-

Chuyn vo trong s khi.


Xy dng s khi.

Hnh 1.203. Giao din s khi c d liu t File


-

Xy dng s khi c dng nh hnh trn.

GV: Trnh V Bo Khoa CNKT in TH

Page 37

Ti liu hng dn thc hnh Labview Lu hnh ni b

Hm Open/Create/Replace c ly File I/O c chc nng hin


th mt hp thoi dng m hoc to mt file.
(Kch chut phi vo Terminal Prompt chn Create
Constant) l mt thng bo m hp thoi s hin th tn file nhp vo.
(kch chut phi vo Function VI v chn Create
Constant) cho bit l to ra mt file mi hay thay th mt file c.S dng
Operationing tool thay i gi tr thnh Create hay Replace.

Hm Read File c ly File I/O. Hm ny dng c File size


s byte d liu t file bt u ca file.

Hm Close File (ly File I/O). Hm ny dng ng file.

Hm Simple Error Handler (c ly Time & Dialog). VI ny


dng kim tra li v hin th mt hp thoi khi c li xut hin.
-

Lu VI vi tn file l File Reader.vi.

Chy VI v mt hp thoi xut hin, tm file demo.txt v kch vo nt lnh


Open hoc nt OK.Hin th String Read from File s hin th ni dung
File.

Bi tp luyn tp
1. Lm bi tp 6.5 trang 133 sch gio trnh

GV: Trnh V Bo Khoa CNKT in TH

Page 38

Ti liu hng dn thc hnh Labview Lu hnh ni b

Bi 5: ng dng ngn ng lp trnh Labview vo bi ton ghp ni my tnh


vi cng giao tip USB.
MC TIU:
- Sau khi hc xong bi ny hc vin c th: Xy dng cc chng trnh ghp
ni my tnh vi cc thit b ngoi vi (v d nh vi x l Pic16F877A, thu thp d
liu t cm bin nhit , nh sng v khong cch, iu khin ng c DC bng
thut ton PID) qua cng USB.
1. Thu thp d liu t cm bin(o nhit bng LM 35)
- Mc tiu: Thu thp tn hiu t cm bin nhit ln my tnh v v th ca
cm bin ny theo thi gian thc(thi gian o), ghp ni s phn cng vi my
tnh thng qua chng trnh iu khin t labview.
1.1 S iu khin
1.2 Thut ton iu khin
1.3 Kt qu
2. iu khin PID ng c DC
- Mc tiu: Nm c l thuyt iu khin PID, xy dng s khi v s
thut ton iu khin, vit chng trnh iu khin ng c PID, kt ni phn cng
iu khin ng c.
2.1 S iu khin
2.2 Thut ton iu khin
2.3 Kt qu
Bi tp luyn tp
1. Thc hnh o lng cm bin nhit LM35 vo my tnh, v th nhit
2. Thu thp tn hiu t mt encoder vo my tnh

GV: Trnh V Bo Khoa CNKT in TH

Page 39

Ti liu hng dn thc hnh Labview Lu hnh ni b

TI LIU THAM KHO


1. LabVIEW Beginer.
2. LabVIEW Tutorial.
3. LabVIEW User Manual
4. LabVIEW Digital Signal Processing and Digital Communications
5. Nguyn Th Lan Hng- Phm Ngc Yn Nguyn Vit Tng, Labview thit b
o v giao din ngi my.
6. TS Nguyn B Hi, Lp trnh labview
7. www.hocdelam.org, www.ni.com

GV: Trnh V Bo Khoa CNKT in TH

Page 40