ON DINH NHIET DO BANG PID

  • Published on
    04-Aug-2015

  • View
    211

  • Download
    0

Embed Size (px)

Transcript

ng dng Pic16F877A o v n nh nhit bng thut ton PID

TI NHM 5 ng dng Pic16F877A o v n nh nhit bng thut ton PID MC LC Chng I: Tm hiu thit b. Chng II: S nguyn l. Chng III: Lp trnh CCS, kt ni PC v m phng Proteus. Chng IV: M hnh thc t v chy th chng trnh. Chng V: Kt lun.

Thnh vin trong nhm: 1/ Nguyn Anh Tun 08D2 (nhm trng) 2/ Nguyn Duy Lun 08D2 3/ Nguyn Hu Tm 08D2 4/ Nguyn Vn Hiu 08D4

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 1

ng dng Pic16F877A o v n nh nhit bng thut ton PID

Chng I TM HIU THIT B 1/ PIC16F877A:

- y l vi iu khin thuc h PIC16Fxxx vi tp lnh gm 35 lnh c di 14 bt.Mi lnh u c thc thi trong mt chu k xung clock.Tc hot ng ti a cho php l 20MHz vi mt chu k lnh l 200ns.B nh chng trnh 8Kx14 bt, b nh d liu 368x8 byte RAM v b nh d liu EEPROM vi dung lng 256x8 byte.S PORT I/O l 5 vi 33 pin I/O. - Cc c tnh ngoi vi bao gm cc khi chc nng sau: Nguyn Anh Tun - 08D2 Bch Khoa Nng Page 2

ng dng Pic16F877A o v n nh nhit bng thut ton PID + Timer0: b m 8 bt vi b chia tn s 8 bt. + Timer1: b m 16 bt vi b chia tn s, c th thc hin chc nng m da vo xung clock ngoi vi ngay khi vi iu khin hot ng ch sleep. + Timer2: b m 8 bt vi b chia tn s, b postcaler. + Hai b Capture/ so snh/ iu ch rng xung. + Cc chun giao tip ni tip SSP, SPI v I2C. + Chun giao tip ni tip USART vi 9 bt a ch. + Cng giao tip song song PSP vi cc chn iu khin RD, WR, CS bn ngoi. - Cc knh Analog: + 8 knh chuyn i ADC 10 bt.Hai b so snh. - Bn cnh l mt vi c tnh khc ca vi iu khin nh: + B nh flash vi kh nng ghi xa c 100.000 ln. + B nh EEPROM vi kh nng ghi xa c 1.000.000 ln. + D liu b nh EEPROM c th lu tr trn 40 nm. + Kh nng t np chng trnh vi s iu khin ca phn mm. + Watchdog Timer vi b dao ng trong. + Chc nng bo mt m chng trnh. + Ch Sleep. + C th hot ng vi nhiu dng Oscillator khc nhau. 2/ CM BIN NHIT LM35 DZ:

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 3

ng dng Pic16F877A o v n nh nhit bng thut ton PID

- LM35 l mt cm bin nhit analog, nhit c xc nh bng cch o hiu in th ng ra ca LM35: + n v nhit : C. + C mc in p thay i trc tip theo C (10mV/*C). + C hiu nng cao, cng sut tiu th l 60uA + Sn phm khng cn phi canh chnh nhit khi s dng. + chnh xc thc t: 1/4C nhit phng v 3/4C ngoi khong -55C ti 150C. + Chn +Vs l chn cung cp in p cho LM35DZ hot ng (420V). + Chn Vout l chn in p ng ra ca LM35DZ, c a vo chn Analog ca cc b ADC. + Chn GND l chn ni mass,lu cn ni mass chn ny trnh lm hng cm bin cng nh lm gim sai s trong qu trnh o. 3/ OPAM LM358: - Tn hiu t cm bin c a qua opam LM358 khuch i ln trc khi a vo chn analog ca pic v qua nng cao c chnh xc hn.

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 4

ng dng Pic16F877A o v n nh nhit bng thut ton PID

4/ LED 7 ON: - LED 7 on l mt cng c thng dng c dng hin th cc thng s di dng cc s t 0 n 9.Mc d cng c LCD gip ta th hin cc thng s mt cch linh ng hn nhng LED 7 on vn c s dng nhiu trong cng nghip do cc u th ca n nh: t chu nh hng ca nhit , d to s ch v gc nhn rng. - LED 7 on bao gm 7 on LED c nh du l cc k t a, b, c, d, e, f, g v mt du chm thp phn k hiu l dp.Ta c th xem LED 7 on l mt t hp gm 8 LED.8 LEDny c mt u (Anode hoc Cathode) c ni chung v c b tr theo mtqui tc nht nh dng hin th cc ch s thp phn. - C hai loi LED 7 on, l loi Anode chung (cc Anode ca cc LED c ni chung vi nhau) v loi Cathode chung (cc Cathode ca cc LED c ni chung vi nhau). - Ty theo tng loi LED m ta c cc phng php iu khin cc LED trong t hp sng tt mt cch thch hp.i vi loi Anode chung, mt LED s Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 5

ng dng Pic16F877A o v n nh nhit bng thut ton PID c bt sang nu mc logic a vo chn iu khin on LED l mc logic 0.i vi loi Cathode chung, mt LED s c bt sang nu mc logic a vo chn iu khin on LED o l mc logic 1.

5/ TRANZITO PNP (A1015):

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 6

ng dng Pic16F877A o v n nh nhit bng thut ton PID - Bng thng s:

- Chn ngun ca cc led 7 on s c iu khin bi cc chn trn vi iu khin thng qua cc Base ca tranzito PNP. 6/ QUT LM MT: - Tc dng lm mt cho ngun nhit lc cn thit. - Thng s: + Ngun DC 12V. + Dng in: 0.14A. + V bc bng nha. + Kch thc 30mm x 30mm x 10mm.

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 7

ng dng Pic16F877A o v n nh nhit bng thut ton PID 7/ MOSFET IRF 540 + OPTO PC817:

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 8

ng dng Pic16F877A o v n nh nhit bng thut ton PID - Mosfet hay cn gi l tranzitor c cc cch ly, c tc dng nh mt kha K. Vic kch ng hay m kha K ty thuc in p t vo chn G ca mosfet. - y ta a xung PWM t chn RC1 ca Pic vo chn G ca mosfet kch m n, qua iu chnh c in p cung cp cho ng c (qut lm mt), ngha l thay i c tc ca ng c.

- Dng Opto PC817 cch ly quang gia mch ng lc v mch iu khin.

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 9

ng dng Pic16F877A o v n nh nhit bng thut ton PID 8/ CNG COM V IC MAX 232:

a/ Cng COM: - Giao tip gia PIC v PC thng qua cng ni tip hay cn gi l cng COM theo chun giao tip RS232. - Cng COM c 2 dng: u ni DB25 ( 25 chn ) v DB9 ( 9 chn ) c m t nh bng sau:

- Cng ni tip c s dng truyn d liu hai chiu gia my tnh v ngoi vi, n c cc u im sau: + Khong cch truyn xa hn so vi truyn song song.

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 10

ng dng Pic16F877A o v n nh nhit bng thut ton PID + S dy kt ni t. + C th truyn khng dy dng hng ngoi. + C th ghp ni vi VK hay PLC. + Cho php ni mng. + C th tho lp thit b trong lc my tnh ang lm vic. + C th cung cp ngun cho cc mch in n gin. - Cc thit b ghp ni chia lm 2 loi: + DCE: l cc thit b trung gian nh MODEM. + DTE: l cc thit b tip nhn hay truyn d liu nh PC, PLC, VK. + Vic trao i tn hiu thng thng qua 2 chn RDX (nhn) v RTX (gi). - Tn hiu truyn theo chun RS232: + Chun RS232 truyn tn hiu vi cc tc thng dng l: 1200 bps, 4800 bps, 9600 bps, 19200 bps. + nh dng khung truyn chun RS232:

Khi khng truyn d liu, ng truyn s trng thi mark ( in p 10V). Khi bt u truyn, DTE s a ra xung Start ( space :10V ) v sau truyn ln lt t D0 -> D7 v Parity, cui cng l xung Stop ( mark: 10V ) khi phc li trng thi ng truyn.V d truyn k t A:

Cc c tnh k thut ca chun RS232:

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 11

ng dng Pic16F877A o v n nh nhit bng thut ton PID

b/ IC MAX 232:

- IC MAX 232 l IC chuyn dng trong giao tip ni tip vi PC.N c 2 b m v 2 b nhn.ng dn iu khin li vo CTS, iu khin vic xut d liu cng ni tip khi cn thit, c ni vi chn 9.Chn RTS (chn 10) c ni vi ng dn bt tay iu khin vi qu trnh nhn.Thng th cc ng dn bt tay c ni vi cng ni tip qua cc cu ni, khi khng dng n na c th h mch cc cu ny.Cch truyn d liu n gin nht l ch dng 3 chn RTX, RDX v GND.

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 12

ng dng Pic16F877A o v n nh nhit bng thut ton PID 9/ MT S LINH KIN KHC:

in tr

Nt bm

Thch anh 12MHz

T in 33pF

Jack ngun DC

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 13

ng dng Pic16F877A o v n nh nhit bng thut ton PID

Cp ni

Bng in 60W (lm ngun nhit) CHNG II S NGUYN L

Led n

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 14

ng dng Pic16F877A o v n nh nhit bng thut ton PID CHNG III LP TRNH CCS, KT NI PC V M PHNG PROTEUS 1/ O NHIT : - S dng cm bin LM35 vi phn gii l 10 mv/ 0C, di nhit o c t -50 n 150 0C. - c c gi tr ADC ta dng hm read_adc( ); - T gi tr ADC c c ta quy i ngc li nhit : + chn ch ADC 10 bt (ngha l ADC c gi tr t 0 n 1023). + ta c: read_adc( ) =1023 ---------------- ng vi in p 5 (V) read_adc( )=x ---------------- ng vi in p (x*5)/1023 (V) + mt khc: c 10 (mv) ---------------- ng vi 1 0C vy (x*5*10^3)/1023 (mv) ---------------- ng vi (x*5*10^3)/(1023*10) =0.489x 0C + chng nhiu: * lc s: adc_cu=0;anpha=k; Vng lp { x=read_adc( ); adc_moi=anpha*adc_cu+ (1-anpha)*x; adc_cu=adc_moi; } * lc nhiu vi sai: adc_tong=0; Vng lp { adc_tong=adc_tong+read_adc( ); } adc_tb=adc_tong/(s vng lp); 2/ HIN TH RA LED 7 ON: - Dng 4 led 7 on hin th nhit : +led 1 v led 2 hin th nhit hng chc v hng n v (t 0 n 99 0C). +led 3 v led 4 hin th k t 0C. - Dng thut ton qut led: Vng lp { HC=temp/10; HDV=temp%10; Xut d liu [HC]; Nguyn Anh Tun - 08D2 Bch Khoa Nng Page 15

ng dng Pic16F877A o v n nh nhit bng thut ton PID Bt ngun led 1; Delay; Tt ngun led 1; Xut d liu [HDV]; Bt ngun led 2; Delay; Tt ngun led 2; Xut k t ; Bt ngun led 3; Delay; Tt ngun led 3; Xut k t C; Bt ngun led 4; Delay; Tt ngun led 4; } 3/ TNH RNG XUNG BNG THUT TON PID: - Trong min thi gian, b iu khin PID c m t bng m hnh vo ra:

Trong : e(t) l tn hiu ng vo, u(t) l tn hiu ng ra ca b iu khin. Tuy nhin, i vi Vi iu khin ni chung, vic tnh ton cc thnh phn P,I,D ni cch khc l tnh cc tch phn hay o hm trong cng thc trn l khng thc hin c. L do: CPU khng th tnh ton chnh xc ti mc t =0 ngha l khng lin tc. Do , ta ch c th tnh ton gn ng bng cch ta cho t= rt nh nhng ln hn 0. tm h thc PID ri rc ,ta xt th sau y:

- Khi cng thc trn c vit li nh sau:

Nguyn Anh Tun - 08D2 Bch Khoa Nng

Page 16

ng dng Pic16F877A o v n nh nhit bng thut ton PID

- i tng iu khin l ng c DC 12V. - Cc ng vo v ra ca b iu khin PID nh sau: Ng vo: e= nhit t (tem_dat) nhit hin ti (tem_htai). Ng ra: u = %duty cycle. - Thut ton PID: Ki: h s tch phn. Kp: h s t l. Kd: h s vi phn. e2: sai lch nhit hin ti. e1: sai lch nhit qu kh ngay trc . e_sum: tng cc sai lch t lc u n thi im hin ti. e_del: bin thin sai lch nhit . duty: rng xung PWM (theo %). Ta c: { e2=tem_dat tem_htai; e_sum= e2 + e1; e_del= e2 e1; e1=e2; duty=duty + Kp*e2 + Ki*e_sum + Kd*e_del; } Xut xung PWM vi duty va tnh c trn. 4/ PHNG PHP IU XUNG PWM: - Phng php iu ch PWM c tn ting anh l Pulse Width Modulation l phng php iu chnh in p ra ti hay ni cch khc l phng php iu ch da trn s thay i rng ca chui xung vung dn n s thay i in p ra. - Cc PWM khi bin i th c cng 1 tn s v khc nhau v rng ca sn dng hay hoc l sn m. - y l