C

pi kontrol ile dc motor hız kontrolü(geri besleme çalışmıyor)

Başlatan cripple, 18 Mayıs 2013, 17:12:55

cripple

sayac aldığı bilgiyi referans değer ile karşılaştırmıyor
(hata=420 - devir;) şu satırda çıkışta okunan değer ile referans değeri yani 420 karşılaştırıp işlem yapması gerekiyo ama arabanın tekerleğinin yavaşlattığımda hiçbir tepki yok sorun ne olabilir acaba?
//PID kontrol uygulaması #include <16f877a.h>#device adc=10#device *=16#fuses xt,nowrt,nowdt,nodebug,nobrownout,nolvp,nocpd,noput,noprotect#use delay (clock=4M) //4mhz kristal #use fast_io(e)#use fast_io(c)#use fast_io(b)#define LCD_RS_PIN      PIN_B1#define LCD_RW_PIN      PIN_B2#define LCD_ENABLE_PIN  PIN_B3 #define LCD_DATA4       PIN_B4 #define LCD_DATA5       PIN_B5 #define LCD_DATA6       PIN_B6 #define LCD_DATA7       PIN_B7#include <lcd.c>unsigned int16 devir;unsigned int8 cx=0,pop;int1 hesapla_flag=0;int eski_hata = 0; int hata;float PI, P, I; int I_hata = 0; int cikis;#define Kp 0.05#define Ki 0.009#define dt 0.5 #int_timer1void timer1_kesmesi(){   set_timer1(15535);//50ms 4mhz icin   cx++;   if(cx>=2)//50ms   {      cx=0;      pop=get_timer0();      set_timer0(0);      hesapla_flag=1;   }  output_toggle(pin_d0);}void main(){setup_CCP1(CCP_PWM);setup_CCP2(CCP_OFF);setup_timer_0(RTCC_EXT_L_TO_H | RTCC_DIV_1);    setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); setup_timer_2(T2_DIV_BY_16,250,1);    enable_interrupts(INT_TIMER1);   enable_interrupts(GLOBAL);   set_tris_a(0b00010000); lcd_init();     lcd_gotoxy( 1,  1);    lcd_putc("Devir olcer");   delay_ms(50);   set_timer0(0);   set_timer1(0);   set_tris_c(0x00); //c portu çıkışset_tris_e(0xFF); // e portu giriş set_tris_b(0x00); //b portu çıkışoutput_c(0x00); // pinler temizlendiwhile(1){      if(hesapla_flag)   {      hesapla_flag=0;      devir=(unsigned int16)pop*6;        lcd_gotoxy( 1,  1); printf(lcd_putc "Devir:%04lu D/",devir); delay_ms(50);   }       set_timer2(0);hata=420 - devir;P=Kp*hata;I_hata=I_hata + (hata*dt);I=Ki * I_hata; PI = P+I;eski_hata=hata;cikis=200+PI;output_high(pin_c3);output_low(pin_c4);if(PI >125)    {        PI=125;    }    else if(PI < 0)    {        PI= 0;    }set_pwm1_duty(cikis);// pwm doluluk oranı hesabı //mesela setup timer ın içindeki değerin yarısı kadar olursa pwm //doluluk oranı %50 olur{   }}}

fth58

hata, degisken turlerinden kaynaklanabilir .Birde bişey sormak istiyorum basicdeki gibi lcd bacak baglantılarını teker teker tanıtmıssın acaba  o kodlar ccs  c de calısıyormu ?

cripple

cvp icin tesekkur ederim diger danistigim kisilerde ayni noktada uyardi
lcd kodlari bu sekilde sorunsuz calisiyor

Powered by EzPortal