shrestha Posted March 27, 2015 Share Posted March 27, 2015 does anybody know how to code PID controller? help will be appreciated? Link to comment Share on other sites More sharing options...
cristian.ignat Posted April 2, 2015 Share Posted April 2, 2015 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 More sharing options...
zygot Posted March 27, 2015 Share Posted March 27, 2015 This can be quite a complex topic, but I'm assuming that you want something useful but not too didactic. I suggest that you check out the excellent material provided here: http://brettbeauregard.com. You will find an answer that is both practical and easy to understand. Link to comment Share on other sites More sharing options...
JColvin Posted March 30, 2015 Share Posted March 30, 2015 Here's a slightly more direct link to the material zygot is referring to: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ I'll echo zygot in the fact that the material is a great place to start for PID control. Link to comment Share on other sites More sharing options...
shrestha Posted April 1, 2015 Author Share Posted April 1, 2015 thats link does not work anymore. Do you have other reference? Link to comment Share on other sites More sharing options...
JColvin Posted April 1, 2015 Share Posted April 1, 2015 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 More sharing options...
shrestha Posted April 3, 2015 Author Share Posted April 3, 2015 thanks Jcolvin, cristain.. I will give a shot. Link to comment Share on other sites More sharing options...
Question
shrestha
does anybody know how to code PID controller? help will be appreciated?
Link to comment
Share on other sites
6 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.