PID for MikroC

General discussion on Libstock website & codes posted on this website.
Post Reply
Author
Message
r.duke
Posts: 84
Joined: 26 Aug 2014 12:27

PID for MikroC

#1 Post by r.duke » 06 Mar 2015 15:07

Hey guys, i am trying to implement some PID control and have downloaded the header and source file form lib-stock for PID in MikroC.

I am a little confused as to how to implement the functions.
What is the purpose of the header and source file?

I can see the header- file has descriptions of the functions, and defines a few variables.
The source file appears to be an implementation of these functions with some commenting to provide context.

Am I correct in assuming that i simply include both files in my code, then call the functions as if they were normal library functions?
using the init function to tune the PID loop and the calculate function to input my process variable and my set-point?
Attachments
1320082633_pid_library_mikroc_pic.zip
(1.51 KiB) Downloaded 299 times

r.duke
Posts: 84
Joined: 26 Aug 2014 12:27

Re: PID for MikroC

#2 Post by r.duke » 08 Mar 2015 19:43

I am a little confused with the code also.

Code: Select all

void Init_PID(float Kp, float Ki, float Kd, float MinOutput, float MaxOutput);
// Initialises the PID engine
// Kp = the "proportional" error multiplier
// Ki = the "integrated value" error multiplier
// Kd = the "derivative" error multiplier
// MinOutput = the minimal value the output value can have (should be < 0)
// MaxOutput = the maximal value the output can have (should be > 0)
It states that the minimal value of the output should be < 0.

I am confused as to how this will work with a PWM variable whose value is between 0 and 1023

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: PID for MikroC

#3 Post by darko.minic » 09 Mar 2015 14:22

Hi,

You should contact Author of library, he can give you best explanation for your problem.

Regards,
Darko

r.duke
Posts: 84
Joined: 26 Aug 2014 12:27

Re: PID for MikroC

#4 Post by r.duke » 09 Mar 2015 20:08

Thanks.
I will need to constrain my duty between 100-1023 anyway to ensure my mosfets wont overheat.

It seems to be working okish totally untuned and with the minimal output at 0.

Post Reply

Return to “Libstock Discussion”