Problem mit PID-Regler Code example dsPIC

Gast #635464
Lesenswert?

hi,
i tried to implement the code Example for PID-control (CE019_PID) into 
my Project.
I wrote the following code:
(the most is copy pasted from the example code)
#include "dsp.h"
#include "p30f5015.h"
tPID dc150PID;
fractional abcCoefficient[3] _attribute_ ((section (".xbss, bss, 
xmemory")));
fractional controlHistory[3] _attribute_ ((section (".ybss, bss, 
ymemory")));
fractional kCoeffs[] = {0,0,0};  //definition {kp,ki,kd}

void setupPID (void)
{
       dc150PID.abcCoefficients = &abcCoefficient[0];    /*Set up 
pointer to derived coefficients */
       dc150PID.controlHistory = &controlHistory[0];     /*Set up 
pointer to controller history samples */
       PIDInit(&dc150PID);                               /*Clear the 
controler history and the controller output */
kCoeffs[0] = Q15(0.7);  //kp
kCoeffs[1] = Q15(0.2);  //ki
kCoeffs[2] = Q15(0.07); //kd
       PIDCoeffCalc(&kCoeffs[0], &dc150PID);             /*Derive the 
a,b, & c coefficients from the Kp, Ki & Kd */



}
int calcPID (int act_value,int des_value)
{
dc150PID.controlReference = des_value ;           /*Set the Reference 
Input for your controller */
       dc150PID.measuredOutput = act_value ;            /*Typically the 
measuredOutput variable is a plant response*/
PID(&dc150PID);
return dc150PID.controlOutput;

}

after building the project i got following error messages:

...\PID.o(.text+0xc): In function `setupPID':
...\PID.c:16: undefined reference to `PIDInit'
...\PID.o(.text+0x1e):...\PID.c:20: undefined reference to 
`PIDCoeffCalc'
...\PID.o(.text+0x34): In function `calcPID':
...\PID.c:31: undefined reference to `PID'
Link step failed.

after that i tried to add the pid.s to my source files and got the 
following errors:

pid.s: Assembler messages:
pid.s:29: Error: can't open dspcommon.inc for reading
pid.s:116: Error: Invalid mnemonic: 'fractsetup'
pid.s:240: Error: Invalid mnemonic: 'fractsetup'

so i copied the dspcommon.inc into my project folder and get this error 
messages:

...\pid.o(.libdsp+0x0):.../pid.s: multiple definition of `PID'
...\PID.o(.libdsp+0x0):.../pid.s: first defined here
...\pid.o(.libdsp+0x38):.../pid.s: multiple definition of `PIDInit'
...\PID.o(.libdsp+0x38):.../pid.s: first defined here
...\pid.o(.libdsp+0x4e):.../pid.s: multiple definition of `PIDCoeffCalc'
...\PID.o(.libdsp+0x4e):.../pid.s: first defined here
c:\pic30_tools\bin\pic30-coff-ld.exe: Link terminated due to previous 
error(s).

what am i doing wrong?
i also tried to add the linkerscript.gld from the code example same 
success.
Gast #636323
Lesenswert?

Danke das hat funktioniert .

Trozdem noch ne Frage ich hab ein bisschen rumprobiert und habe das 
Beispiel so wie in meinem projekt umprogrammiert, bei dem codeexample 
muss ich allerdings gar keine pid.s einbinden und es funktioniert 
trozdem obwohl mein funktionen in PID.c sind also wieder ein gleiches 
objektfile entsteht?
Das hätte ich auch gerne so in meinem Projekt(ist aber nicht zwingend 
notwendig). Im Zipfile ist die geänderte CE019_PID
Angehängte Dateien:
Gast #829944
Lesenswert?

Hi,

To run this PID on a p33FJ256GP710 you need to change:

fractional controlHistory[3] _attribute_ ((section(".ybss, bss, 
ymemory")));

to

fractional controlHistory[3] _attribute_ ((far, section(".ybss, bss, 
ymemory")));


My topic is a little bit out of the contex, but I am sur it will help 
somebody.

regards, PL

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren