Author Topic: PIDdef, PIDcompute support  (Read 15767 times)

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
PIDdef, PIDcompute support
« on: February 23, 2013, 02:27:00 AM »

I have tested on nano10 the following values on a 24V DC motor using a speed feedbacj series resister.
The series resitor measures  from 0 - 4095 (speed)
My PWM duty cycle control range must be from 500(5%) to 9500(95%) for frequency 15Hz.

what must be the PIDdef ?

what must be the PIDcompute command parameters?.

I need urgent help on PID configuration. please advise.

Roy


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PIDdef, PIDcompute support
« Reply #1 on: February 24, 2013, 09:24:20 PM »
PIDDEF is where you set the P, I and D. We can't tell you what are the parameters as these vary from system to system. So you have to experiment with it starting with some best guesses (start with smaller value of I and  P) and check the system response, then vary them until the system perform to your spec. This is called PID tuning.

As for the parameters to be passed to PIDcompute(), it is the error (= SETPOINT - MEASURED). Please refer to our reply to your earlier post on this topic:

http://www.tri-plc.com/yabbse/index.php?board=1;action=display;threadid=1939
« Last Edit: February 24, 2013, 09:24:57 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PIDdef, PIDcompute support
« Reply #2 on: February 25, 2013, 08:06:47 PM »
control input is 0 - 4096 (speed)
control output 0 to10000.
Control Input Setpoint 2048.

what is the P and I value that I can start with for the above control input and output range?.
There is no response if I follow the Nano10 software manual.

There is a demonstration in the user manual which defines  ONLY how to use PIDcompute fuction without explaining the important  P,I value calculation for PIDdef.  

The manual should have provided more importance on how to calculate P,I for PIDdef to define based on control input range an control output range.

Could you help calculating the initial value first, the PID tuning part ,I can guess based on trial and error.

Otherwise, I will have to write PID logic whcih will take sometime.


thank you




roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PIDdef, PIDcompute support
« Reply #3 on: February 28, 2013, 01:01:12 AM »
encoder input to PLC

gives

47000 for 3% PWM
300     for 25% PWM

setpoint 18%

I just need to control between 3 % to 25% as stated above.

I am almost unable to proceed further without PID working.
I am entirly depending on the your advise on how to choose the initial P and I values?

All numbers for p and I cant be FOUND trial and error. there must a proper procedure to calcualte THE INITITIAL setting, then we can adjust.

could you advise how to find p and i from the above ranages.

thank you

Roy

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PIDdef, PIDcompute support
« Reply #4 on: March 01, 2013, 12:51:43 AM »
It is really not a job of the tech support to tell you what should be the values  the P I and D value as these are dependent on individual system.

What is the open loop transfer function of your system? i.e. what is the speed with respect to the PWM duty cycle? Can you draw a graph of speed vs duty cycle.

Your last post mentioned that at 3% duty cycle would return 47000 and 25% duty cycle would return 300. That doesn?t quite make sense since a small duty cycle means less power and yet the motor runs faster?

Lets assume an example that your motor runs in the speed range from 0 to 1000 rpm between 3% and 25% duty cycle (i.e. 300 to 2500 in SETPWM), That means:
 
(change in duty cycle)         (2500-300)     2200  
----------------------------   =  --------       =  ------   (%*100/rpm)
(change in speed)                 1000             1000


This means that in order to run the motor at X rpm in open loop, you need to set the duty cycle = (X*22)/10  + 300.

In a control system that only has the P term, there will always be a steady state error between the SETPOINT and the FEEDBACK value in order for the control system to work. Assuming that you can tolerate a 50rpm steady state error in order to generate a proportional output of 500rpm, that means your P term should be 10 times that of the transfer function.

So P = 10*22/10 = 22 may be a good starting point.

You can try with a small value of I = 1. With the introduction of the integral the control system will eliminate the steady state error so that ACTUAL SPEED = SETPOINT at steady state. ?I? term  will control how fast or how slow the control system reach steady speed and you can experiment with it.

So the algorithm could be as follow:

E.g. P = 22:  I = 1 (PIDDEF in a separate custom function)

E = SETPOINT ? FEEDBACK VALUE in RPM

C = PIDCompute(E) + 300
SETPWM 1, C, 16     ? assuming 16Hz works for you.

The custom function that runs the PIDcompute and SETPWM should be called periodically (e.g. using a clock pulse with period 0.1, 0.2 or 0.5 second) so that the control system can work.

Note that if the P term is too small you may want to use a fixed point representation. E.g. each unit of P can be = 0.1. So for P = 22 it can be represented as 220 and I = 1 can be represented as 10. The PIDcompute will output a control action that is scaled up by 10 times and you just need to divide the computed value by 10 before applying to PWM.  (The integral limit should also be 10 x higher than the actual preferred limit.)

E.g. P = 220, I = 10   (PIDDEF in a separate function)

E = SETPOINT ? FEEDBACK VALUE

C = PIDCompute(E)/10 + 300
SETPWM 1, C, 16     ? assuming 16Hz works for you.

Note that PIDDEF should be placed in a different custom function (could be in an INIT function) and run only ONCE before the control action starts. Otherwise each time it is executed the integral and differential results are lost.
« Last Edit: March 01, 2013, 12:55:05 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PIDdef, PIDcompute support
« Reply #5 on: March 01, 2013, 01:12:29 AM »
What I meant was that 25% duty cycle would return 47000 and 3% duty cycle would return 300. I am sorry, I will try your advise first and let you know.

Many thanks for your response. Making this PID work is very critical. I hope that you will continue to support until it is resolved.

I will try to send the program as attachment for your review.