2017-12-30 04:21 AM
Hi, everyone!
I am trying to implement PID controller from arm_math library. I use this code as kind of example for this
https://stm32f4-discovery.net/2014/11/project-03-stm32f4xx-pid-controller/
I am getting error - Undefined reference to `arm_pid_init_q31',
There is nothing much regarding PID in my code, I copied only lines regarding PID.
&sharpinclude <arm_math.h>
&sharpdefine PID_PARAM_KP 10 /* Proporcional */
&sharpdefine PID_PARAM_KI 10 /* Integral */&sharpdefine PID_PARAM_KD 10 /* Derivative */uint32_t PID_ERROR;
arm_pid_instance_q31 PID;
PID.Kp = PID_PARAM_KP; /* Proporcional */ PID.Ki = PID_PARAM_KI; /* Integral */ PID.Kd = PID_PARAM_KD; /* Derivative */ arm_pid_init_q31(&PID, 1);while(1)
{
output_voltage_mv = (3300*VOUT * 21) / 4096;
PID_ERROR = Vreg - output_voltage_mv; duty_cycle = arm_pid_q31(&PID, PID_ERROR);}
Can any help please?
#pid #arm_math2017-12-30 06:25 AM
Error suggests you need to add the library file to your project, or add in the source files from the library.
2018-01-02 02:17 AM
If using keil, you may need to enable your CMSIS-DSP pack.
Good luck!
Zt.
2018-01-03 04:51 AM
But I have included arm_math.h and this arm_pid_init_q31 is defined in arm_math.h....
I do not understand why shouldn't it work. If arm_math would not be accessable for project I would get error about that.
2018-01-03 05:12 AM
karlis77 wrote:
But I have included arm_math.h and thisarm_pid_init_q31 is defined (sic?) in arm_math.h....
Are you sure it's actually defined there ...?
2018-01-03 05:43 AM
I think I am. When I click Go to Definition it opens arm_math.h and shows me this.
2018-01-03 05:58 AM
Ha - that's Keil being sloppy with their terminology!
>:(
That is just a function prototype - it is not a definition - it is just a declaration.
See: C-FAQ
http://c-faq.com/decl/decldef.html
So, as in the previously-linked forum thread, you need to also include the .c source file which provides the actual definition (ie, the implementation) of that function ...
EDIT
To be fair, I think that Eclipse is equally sloppy with this.
2018-01-03 06:09 AM
Ok, thank you!
I searched for .c file and found that there is \STM32H7xxxx\CMSIS_HAL\DSP\Source\ControllerFunction\
arm_pid_init_q31.c
So I included it in my code and now I can build it.
I do not know much about this stuff, but I was wondering why it wasn't included in arm_math.h
2018-01-03 06:12 AM
karlis77 wrote:
I do not know much about this stuff, but I was wondering why it wasn't included in arm_math.h
As noted in the other thread, it is standard 'C' programming stuff - not specific to Keil or ST or even embedded.
It is explained in the linked FAQ.