adccommunitymod (AutomationDirect) asked a question.

PID question

Created Date: May 16,2007

Created By: dwalker611

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

This is a continuation of a question I had a few threads ago..... I'm using the output of a PID loop to control the speed of a conveyor. The input to the PID is an analog sensor, the setpoint is captured by the HMI and the output of the PID will be what the conveyor should be running (0-4095 = 0-120Hz). The conveyor will run at a set speed (60Hz) and based on the output of the PID will either increase or decrease depending on the value. The following is the code I 've come up to do this with. Take a look and let me know what you think, or if there is an easier way of doing this. Thanks in advance. - Dave #BEGIN COMMENT "This instruction loads the base frequency stored in V2020, which is written by the HMI and converts it to a 0-4095 output BCD #. Assuming a range of 0-120 Hz V2020 = base freq in Hz read/set from HMI 0 -120 V2021 = BCD value of Hz 0-4095 for analog output " #END STR SP1 LD V2020 MUL K4095 DIV K120 OUT V2021 #BEGIN COMMENT "On first scan, load base frequency to the output channel. " #END STR SP0 LD V2021 OUT V2010 #BEGIN COMMENT "These two rungs set the sample time of comparing the PID output to the base speed. " "This time is to keep from over running the drive either up or down. " " " #END STR C57 ANDN T15 TMR T14 K20 STR T3 TMR T15 K20 #BEGIN COMMENT "When conveyor is set to run and sample time is comlete, " "Compare PID output V3503 to the base freq V2021 " #END STR C57 AND T3 LD V2021 CMP V3503 #BEGIN COMMENT "When SP 60 is true; " "Subtract V3503 by V2121 and store in V2022 " #END STR SP60 LD V2021 SUB V3503 OUT V2022 SET C100 #BEGIN COMMENT "When C100 is set on, Load the value in 2022 and add it to the value in V2021 and store " "the value in V2021 (analog output) " #END STR C100 LD V2022 ADD V2021 OUT V2010 RST C100 #BEGIN COMMENT "When SP 62 is true; " "Subtract V3503 by V2121 and store in V2022 " #END STR SP62 LD V2021 SUB V3503 OUT V2022 SET C101 #BEGIN COMMENT "When C101 is set on, Load the value in 2021 and subtract it from the value in V2022 and " "store the value in V2010 (analog output) " #END STR C100 LD V2021 SUB V2022 OUT V2010 RST C101


  • adccommunitymod (AutomationDirect)

    Created Date: May 17,2007

    Created by: Kristjan H

    Are you sure you are using the built in PID controllers? This seems like a very complicated solution. I would reccomend for you to set up one PID loop in your PLC (PLC - Setup - PID). If you - for example - set up with table start address in V5000 then you have your set point in V5002, process value in V5003 and loop output in V5005. Note that all these values are in BIN format. Extensive information about PID in chapter 8 of your manual.

    Now program the following:

    STR C10 (on when conveyor is on)

    LD set point

    BIN

    OUT V5002

    LD process value

    BIN

    OUT V5003

    LD V5005

    BCD

    OUT analog output to drive

    STRN C10

    LD K0

    OUT analog output to drive

    This is all it takes. First you take the set point as input in the HMI. Go ahead and use it directly or multiplied by 10 to get better resolution. You have to convert it to BIN before outputting to controller. Same with process value. Scale the input from the sensor in the same way that you scale the set point. If you input 90Hz as set point in HMI you can use it as 900. You also scale the sensor value so that when it measures 110Hz you have 1100 in the associated V-memory.

    Finally you take the loop output, convert to BCD and write to the analog output. It is good practice to shut off the output when the system is not running, thus the last three lines.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: May 17,2007

    Created by: dwalker611

    Here's my setup:

    Ultrasonic sensor (4-20mA input) is monitoring the height of a powder range 0-20mm. The conveyor (4-20ma output) is running continuusly @ 60Hz.

    The sensor is my PV, the setpoint is set via the HMI. The operator will monitor the height of the powder, when the correct level is acheaved, they press a button which captures the analog sensor input as the setpoint.

    The VFD is running at 60 Hz. Based on the output value of the PID, we want to increase or decrease the speed from the base speed of 60Hz. How do I do this???

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: May 18,2007

    Created by: Kristjan H

    Lets say you have your set point (SP) in V2000, the sensor input (PV) in V2010, and the analog output in V2020. C0 comes on momentarily when the operator pushes the "setpoint snapshot " button. Now, in order to acquire a new SP based on the current PV, you could simply do the following:

    STR C0

    LD V2010

    OUT V2000

    Why would it need to be any more complicated? Why do you want to change the speed "based on the output of the PID "? The PID takes care of it self, being in a closed loop and all. You just have to throw in the SP and PV and it calculates your output provided you are in Auto mode.

    The code from my previous post would look like the following when using the variables in this post:

    STR C10 (on when conveyor is on)

    LD V2000

    BIN

    OUT V5002

    LD V2010

    BIN

    OUT V5003

    LD V5005

    BCD

    OUT V2020

    STRN C10

    LD K0

    OUT V2020

    Hope this helps some.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: May 18,2007

    Created by: dwalker611

    Thanks for your help, I think I was making it a little more complicated than it should be.

    I'm new to programing Koyo PLC's and am used to AB style.

    So if I understand your logic in the last reply you are simple converting the SP and PV to binary and using that in the PID loop; then convert the binary out back to BCD for the output card?

    Easy enough! Thank you for responding and helping out.

    - Dave

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: May 16,2007

    Created by: dwalker611

    This is a continuation of a question I had a few threads ago.....

    I'm using the output of a PID loop to control the speed of a conveyor. The input to the PID is an analog sensor, the setpoint is captured by the HMI and the output of the PID will be what the conveyor should be running (0-4095 = 0-120Hz).

    The conveyor will run at a set speed (60Hz) and based on the output of the PID will either increase or decrease depending on the value. The following is the code I 've come up to do this with. Take a look and let me know what you think, or if there is an easier way of doing this.

    Thanks in advance.

    - Dave

    #BEGIN COMMENT

    "This instruction loads the base frequency stored in V2020, which is written by the HMI and converts it to a 0-4095 output BCD #. Assuming a range of 0-120 Hz V2020 = base freq in Hz read/set from HMI 0 -120 V2021 = BCD value of Hz 0-4095 for analog output "

    #END

    STR SP1

    LD V2020

    MUL K4095

    DIV K120

    OUT V2021

    #BEGIN COMMENT

    "On first scan, load base frequency to the output channel. "

    #END

    STR SP0

    LD V2021

    OUT V2010

    #BEGIN COMMENT

    "These two rungs set the sample time of comparing the PID output to the base speed. "

    "This time is to keep from over running the drive either up or down. "

    " "

    #END

    STR C57

    ANDN T15

    TMR T14 K20

    STR T3

    TMR T15 K20

    #BEGIN COMMENT

    "When conveyor is set to run and sample time is comlete, "

    "Compare PID output V3503 to the base freq V2021 "

    #END

    STR C57

    AND T3

    LD V2021

    CMP V3503

    #BEGIN COMMENT

    "When SP 60 is true; "

    "Subtract V3503 by V2121 and store in V2022 "

    #END

    STR SP60

    LD V2021

    SUB V3503

    OUT V2022

    SET C100

    #BEGIN COMMENT

    "When C100 is set on, Load the value in 2022 and add it to the value in V2021 and store "

    "the value in V2021 (analog output) "

    #END

    STR C100

    LD V2022

    ADD V2021

    OUT V2010

    RST C100

    #BEGIN COMMENT

    "When SP 62 is true; "

    "Subtract V3503 by V2121 and store in V2022 "

    #END

    STR SP62

    LD V2021

    SUB V3503

    OUT V2022

    SET C101

    #BEGIN COMMENT

    "When C101 is set on, Load the value in 2021 and subtract it from the value in V2022 and "

    "store the value in V2010 (analog output) "

    #END

    STR C100

    LD V2021

    SUB V2022

    OUT V2010

    RST C101

    Expand Post