Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Result is not defined in function

Status
Not open for further replies.

Cüneyt Ta

Newbie level 5
Joined
Apr 18, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
82
Friends;
I'm new in C I tried to comply a project but I take this message .Can some help?

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// LCD module bağlantıları
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;
 
sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// Değişken Atamaları
unsigned int Tpos,pozisyon,proportional,last_proportional,integral,derivative,power_differance;
unsigned char duty;
char volti,volty;
unsigned int IIO,IYO;
float Kp=2,Ki=0.2,Kd=1;
float II,IY;
char *text="000";
char *IIYAZ="000";
char *IYYAZ="000";
// Genel Ayarlar
init(){
       ADCON1=0b10001101;
       ADCON0=0X85;
       Trisa=0xff;
       Trisc=0x00;
       Trisd=0x00;
       Pwm1_Init(1000);
       lcd_Init();
       Delay_ms(100);
       Lcd_Cmd(_LCD_CLEAR);
       Lcd_Cmd(_LCD_CURSOR_OFF);
       }
// ADC Okuma, PID Hesaplama
oku(){
      IIO=Adc_Read(0);
      delay_ms(5);
      IYO=Adc_Read(1);
      delay_ms(5);
 
      II=(long)IIO*5000;
      II=II/1022;
      volti=II/100;
      IY=(long)IYO*5000;
      IY=IY/1022;
      volty=IY/100;
 
      if(volti>=volty){
                      Tpos=volti;
                      pozisyon=volty;
                      proportional=Tpos-pozisyon;
                      derivative=proportional-last_proportional;
                      integral=integral+proportional;
                      last_proportional=proportional;
                      power_differance=proportional*Kp+derivative*Kd+integral*Ki;
                      if(duty>240) power_differance=128;
                      duty=power_differance+127;
                      }
      if(volti<volty) {
                       Tpos=volti;
                       pozisyon=volty;
                       proportional=Tpos-pozisyon;
                       derivative=proportional-last_proportional;
                       integral=integral+proportional;
                       last_proportional=proportional;
                       power_differance=proportional*Kp+derivative*Kd+integral*Ki;
                       if(duty<10) power_differance=127;
                       duty=power_differance-127;
                       }
      }
pwm(){
      PWM1_Set_duty(duty);
      PWM1_start();
      }
LCD(){
      text[0]=(duty/100)+48;
      text[1]=(duty/10)%10+48;
      text[2]=duty%10+48;
      Lcd_Out(1,13,text);
      IIYAZ[0]=(volti/100)+48;
      IIYAZ[1]=(volti/10)%10+48;
      IIYAZ[2]=volti%10+48;
      IYYAZ[0]=(volty/100)+48;
      IYYAZ[1]=(volty/10)%10+48;
      IYYAZ[2]=volty%10+48;
      Lcd_Out(1,1,"INV:");
      Lcd_Out(1,5,IIYAZ);
      Lcd_Out(2,1,"YUK:");
      Lcd_Out(2,5,IYYAZ);
      Lcd_Out(1,9,"DTY:");
      }
 
void main() {
            init();
            while(1){
                     LCD();
                     oku();
                     pwm();
 
                     }
            }



Thanks in advance
 
Last edited by a moderator:

You need to declare your functions as void type. With your current code, the compiler expects your functions to return an int. So:

Change init() to void init()
Change oku() to void oku()
Etc...
 
Hi
Can anyone say if the start value of PID variables are reasonable or not ?
 

Can anyone say if the start value of PID variables are reasonable or not ?
I guess you are talking about Kp, Ki, Kd, because there are no other initialized variables in your code?

Probably they are not, but we can't know without a description of the control system, the "plant". A reasonable approach is to use Ziegler-Nichols tuning method to derive the parameters. Please notice that the actually implemented Ti and Td parameters depend on the software cycle time which isn't well defined in your code.

As another point, your PID code misses any means against integrator windup.
 

Yes I see. I will investigate the Ziegler -Nichols tuning method The software cycle time is also considerable.I ve said that I'm new in C but a little knowledge about picbasic. I have to read about this Ti, Td parameters. Would you please say me how would it be defined software cycle time in C ? I use 8Mhz crystal .I have now another failure. I corrected the variable types as void... but now whether in preteus or real circuit the LCD shows any worth also I see nothing in LCD . I see the worths in LCD only I make the variables again oku(); lcd(); init(); Thanks in advance
 

Please zip and post your complete mikroC project files and Proteus file. I will see why LCD is not displaying.
 

The project :
There are two currents “ unsignt int IIO,IYO ; ” to compare via current sensors. The condition must be “ IIO > = IIY “ . if IIO < IIY then PWM works and gates a Mosfet to draw the over current over an external load. The current sensors are the same sort. They have 2,5 volts referens voltages at zero Amp . At max current 30 Amp they have 4,8 Volts .For each Amper they add 0,066 V to the referens voltage 2,5 Volts .When I draw 15 Amps my sensor has 0.066 x 15 = 0,990V , 2,5V + 0,99 = 3,49 Volts. For PID I defined two other variables ; float II,IY ; for PWM pulses I took 1000 Hz . ( These worths I chose for my self I dont know if they are reasonable or not. I have not any experience about this only elektronic).I send you the proteus and MicroC files .If you correct the program codes and perhaps the worths or say with which worths I have to start I will be very appreciated..These files work because I changed the codes again as only ‘ init,lcd,oku .. ‘ Regards.
 

Attachments

  • Current regulation.rar
    76.2 KB · Views: 71

For PWM Frequecy I had choosen 1000 because of Proteus . In real circuit I have choosen 10 000 Hz. In MicroC I coudnt see any Timer ,I think the libraries count the cycle times but how I dont know .For that reason in Function oku(); the values of variables II ,IY can not be reasonable .Espacially here I need help .If this program works without failure I want to put its wiring circuit and pictures here in forum. If anyone will this current limiting method can take it and improve. I had searched for a long time fora scheme like this but I coudnt find any similar circuit used PWM and PID together. Afterwards I decided to built one on myself In my proteus file there are some circuit parts their codes are not yet included in program, so like controlling the Accu (AKU) voltage. After I solved this issue (PWM and PID ) I will add this codes to the main program. Thanks for all helpers
 

@ FvM
Hallo!
At code Line 60 I had calculate the PID value but I think I used it wrong How can I give this value to the PWM ? bzw.to the duty? What did you mean with “Ti and Td parameters depend on the software cycle time which isn't well defined in your code.” ? what would I do to correct them ? and “ your PID code misses any means against integrator windup.” How can I add or change my code? My condition is “ IIO > = IIY “ . if IIO < IIY then PWM works and gates a Mosfet to draw the over current over an external load. If I can not solve this problem I quit this all project and try to find a way via pure electronic not with MCU I would be very appriciated for your help.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top