HI!!
I declared 3 global var, i call it inside diferent task and every execution this var should be updates but not to do it. I have a 8051 under evaluation board. Maybe can be a problem of my small micro? What do u think about this?
Thanks
Maybe can be a problem of my small micro?
Most likely not. I would guess it is a problem with the code, but lacking the code it is hard to verify that.
What do u think about this?
I think that given the scarcity of information, any statement about the nature of the problem can be classified as speculation.
What do u think about this? I have no idea what micro (u) think about this, what I think is that you are trying to run before you have even learned to crawl, that is a surefire way of breaking a leg. learn to crawl, THEN learn to walk, THEN learn to run. 1) read "the bible" and the datasheet for your device a couple of times to familiarize yourself with the contents. 2) work through (I did NOT say 'read') the Keil "getting started guide" 3) do some simple projects (start with 'blinky') gradually adding complexity 4) go back to whatever running it is you are trying to do way too early.
Erik
OK, well!! I explain the code:
-I have a global var type struct. -I have 2 task: WRITE task: here create PID task PID task: here call to the funtion that update the those struct.
This is the piece of code:
PID.H typedef int real; typedef struct { real dState; /* Ultima posicion */ real iState; /* Estado del integrador */ real uMax,uMin; /* Saturacion del actuador */ real Kp; /* Ganancia proporcional */ real Ti,Td; /* Cte, tiempo integral y derivativo */ real Ts,Tt; /* Periodo muestreo, Cte. tiempo tracking */ real Kwindup; /* Cte. antireset windup */ } SPid; real UpdatePID (SPid *pid, real SP, real PV, unsigned int AUTO,real Uman) reentrant{ into PID.c .... pid->iState += error; return pid->iState; } MAIN.C //global var SPid iA void Write (void) _task_ WRITE _priority_ 1{ ..... os_create_task(A); os_wait(K_SIG, WAIT_FOREVER,0); os_clear_signal(WRITE); } void PIDa (void) _task_ A _priority_ 1 { ... Ua = UpdatePID (&iA, SPa, PVa, 1, 4); os_send_signal(WRITE); os_delete_task(B); } the iA var never update
real UpdatePID (SPid *pid, real SP, real PV, unsigned int AUTO,real Uman) reentrant { real P,I,D,v,u,Es,error; if (AUTO){ error = SP - PV; P = pid->Kp*error; if (pid->Ti){ I = pid->iState*(pid->Kp*(pid->Ts/pid->Ti)+ pid->Kwindup); pid->iState = pid->iState + error; }else I=0; if (pid->Td){ D = (pid->Kp*(pid->Td/pid->Ts)*(PV - pid->dState)); pid->dState = PV; }else D=0; v = P + I + D; if (v > pid->uMax) u=pid->uMax; /* Antireset windup */ else if (v < pid->uMin) u=pid->uMin; else u=v; Es = u-v; pid->Kwindup = Es/pid->Tt; }else{ /* Modo Manual */ u = Uman; pid->iState = Uman - (pid->Kp*error); /* Bumpless transfer */ } return u; }
are you sure your gains are not 0? if your
iA
is not updates, maybe
if (pid->Ti)
and
if (pid->Td)
are 0? did you try to debug this code?
it is OK because if i do it:
return pid->iState;
First the value is for example 10, after is 4, but should be 14.
but you said that your iA variable is not updated! so it is updated after all, and the problem seems to be a calculation bug of some kind. I suggest you start debugging.
Always Im debugging my code, i trying everythings and im seeing for webs and datasheet. And i dont know where is the problem. Im exasperate!!!
Thanks.
I see some serious problems with your implementation. I think your integrator is totally wrong - you do not even accumulate the error! it should be something like this:
double UpdatePID(SPid * pid, double error, double position) { double pTerm, dTerm, iTerm; pTerm = pid->pGain * error; // calculate the proportional term // calculate the integral state with limiting pid->iState += error; if (pid->iState > pid->iMax) pid->iState = pid->iMax; else if (pid->iState < pid->iMin) { pid->iState = pid->iMin; iTerm = pid->iGain * iState; } dTerm = pid->dGain * (position - pid->dState); pid->dState = position; return pTerm + iTerm - dTerm; }
If your "real" is "(signed) int" I'm in doubt if you thought about scaling, underflow and overflow of our variables.
sorry, you do accumulate the error but I still think your implementation is not correct.
Thanks for your reply. But i think that the problem is not the implementation because is a simple acumulate. I dont understand why this var not acumulate the old value.
The var values in my debugging are 10, 4 ,... im trying change the data type for unisgned int and is the same.
Let me give you simple example with signed int (-32768 to +32767). In mathematical notation:
SP=3000 (setpint) PV=0 (value read from ADC) Kp=12 P=KP*(SP-PV)=12*(3000-0)=36000
This causes an overflow. The result is treated as a negative number.
I understand your example. But in my code i have this:
First iteraction SP=10 (setpint) PV=0 (value read from ADC) Kp=1 P=KP*(SP-PV)=1*(10-0)=10 Second iteraction SP=10 (setpint) PV=6 (value read from ADC) Kp=1 P=KP*(SP-PV)=1*(10-6)=4 but my pid->iState should be 10+4=14, and it is 4
i dont know why dont save the old value in pid->iState
Are There Anybody that help me with my project?? Maybe i can send the code for see it!!!
It is very important for me!! Thanks
You've checked only this part of your code? You have to ensure, that there is no underflow/overflow/division by 0 in the whole code and under all circumstances (for example extreme user input). The "updating problem": It helps a lot if you screw down your code to the interesting core and debug it. If this fails you can show this very short program and all the necessary information to the forum. And don't forget to mention the controller, hardware, RTX. Check the datasheet of the controller and the camera. It seems you didn't.
Sorry. "Camera" belongs to an other thread I read in parallel.
OK! Im working with an emulator (EPM900) and an evaluation board (MCB900), my micro is Philips P89LPC936, under RTX-51.
Independent of my PID, the problem is the var update. For example:
void Write (void) _task_ WRITE _priority_ 1 { int Ub=0; while (1){ Ub+=1; TXRX_putByte(Ub); //send to serial port } void main (void){ os_start_system (WRITE); }
The var Ub always is 1, never update the value ???????
Recently i debugg my code in the simulator of uvision and all var are updated!!! Why dont work in my board?????????
Recently i debugg my code in the simulator of uvision and all var are updated!!! Why dont work in my board????????? DUH, the simulator simulates.
if there is e.g. a baudrate error, the simulating thing will still work, if the internal XRAM in the device is not enabled the simulating thing will still work, ....
if the var you are hunting is in xdata, I'll bet you dollars to doughnuts that you have not modified startup.a51 to enable your XDATA.
BTW this newfangled thing that only few know about called a datasheet will tell you what is needed.
looking at the Keil manual and the startup code will show you why this must be at the start of startup.a51.
java
you be please ignoring sir eracs terrrible sarcasem.
he is be thinking he be funny,,, but he is just crazy yes.
rahib, what happened? where is praise? where is the submission :) :) :) where is the propaganda ?! it is sir erac you are talking about maaaaaaan !!!!
now seriously: your friend did not provide vital data that could have solved his problem earlier and save us time, headache and heartache! instead he offered money. YUK.
HI Eric!! First thanks for your reply.
My code startup is: START900.A51 because i use Philips P89LPC936. It has 512 bytes of xdata.
I have modificated only this:
; <o> XDATASTART: XDATA memory start address <0x0-0xFFFF> ; the absolute start-address of XDATA memory XDATASTART EQU 0x000 ; ; <o> XDATALEN: XDATA memory length <0x0-0xFFFF> ; the length of XDATA memory in bytes. XDATALEN EQU 0x200 ;
i say no!!!!!!
i asking his help and ansewrs and he be ignored me
i think he liking to heat poeple up and spit the bit out yes???
he say lots but not say much for poeple to be using.
now he is not sir but he being something other yes!!!!
why are taking this so seriously? ok, I sometimes also think that I'd rather jump into a swimming pool filled with Pirenia fish rather than being bashes by Erik, but (un)fortunately he often knows what he is talking about (like this one!). so relax and enjoy the bottomless well of knowledge (gee, I'm poetic!)
IF i enable Use On-Chip XRAM i cant compile the aplication because :"ADRESS SPACE OVERFLOW".
tamik
you be wanting downuts you be must be talking by erac
you be wanting sarchastem you be must talking by erac
you be wanting anwser by simple problum you must be talking by erac
you be wanting to know goood ansewr by diffucult problam you be must be talkin gnot by erac
OK!!! A simple questions:
Have i configurate START900.A51 for use On-Chip XRAM??? Is It necessary??
you do this ardours task of reading the datasheet and find that e.g. this is an example, not supposedly correct ORL AUXR1,#0x40 will enable the internal xram. Then right after the STARTUP: label (the one branched to from 0) you insert the proper instruction based on what you found in the datasheet.
View all questions in Keil forum