Jump to content
  • 0

PID controller on Nexys3


shrestha

Question

6 answers to this question

Recommended Posts

Hello,

 

If you want a controller for a motor then you can use a PI controller (derivative component is not very important in this case). You can start using a very simple PI controller. 

 

The PI controller is running in a loop like on the following C code (see also the link https://batchloaf.wordpress.com/2013/06/11/simple-pi-control-using-the-dspic30f4011/):

 
double setpoint, measured_value, error, output;
double previous_error = 0, integral = 0;
const double dt = 0.00005, Kp = 0.001, Ki = 0.001;

 

While(1)

{

        if(Time_interrupt == 1)

        { 

             Time_interrupt = 0;

             setpoint = read_set_point();

             measured_value = read_measured_value();
             error = setpoint - measured_value;
             integral = integral + error*dt;
             output = Kp*error + Ki*integral;
             previous_error = error;
        }
}

 

You can modify the constants and also the timer. Time_interrupt becomes 1 on each 0.00005 seconds and this is the reason that dt constant is 0.00005 - in seconds. 

 

Regards,

Cristian

Link to comment
Share on other sites

The link was gone like you said when I started writing this reply, but it appears to be back up now... hopefully it stays there.

 

But PID control can quickly become a very involved topic, especially if you're not super familiar with some of the math and theory involved behind it, and unfortunately there doesn't seem to be a lot of material out there that explains PID from the ground up. This project goes beyond the scope of what Digilent does as a company, and it's been awhile since I took a process control class, so I will be of limited help. 

 

However, I would recommend checking out these three links that get progressively more in depth on PID here, here, and here. There is also an (apparently) semi-famous article on PID for people with PhD's here that does a decent job on explaining the purpose of the three main parts of PID (proportional, integral, and derivative).

 

Thanks,

JColvin

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...