PID controller in 16F737


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2005
    Posts
    10

    Default PID controller in 16F737

    Hi, I want to control an oven with a pic.
    I basicaly have build the oven, including the temp-sensing with a NTC.
    The oven will be used for making SMD PCB's.
    Therefor it has to follow a temperature profile in time.
    I want to do this with a PID-controller.
    I calculated the PID parameters (gain, I, D) by the step response.

    I also tried to build the PID algorithm.
    Only, in case of overshoot, I will have a negative error (wish temp minus real temp).
    I wrote a routine to handle negative values; to multiply and subtract negative values (see below).
    As this is quite complex, does anyone know if there is a more simple (faster) method to implement a PID for this application?

    code;
    AminB: '*** PROCEDURE A - B ***
    tekA=NCD(A)
    tekB=NCD(B)
    IF (tekA = 16 AND tekB = 16) OR (tekA <>16 AND tekB<>16) Then 'check if A and B have same sign
    abswaardeAminB = ABS(A-B)
    IF tekA = 16 Then
    IF NCD(A-B) = 16 Then
    tekAminB = 16
    Else
    tekAminB = 0
    EndIF
    Else
    tekAminB = NCD(A-B)
    EndIF
    Else
    abswaardeAminB = ABS(A) + ABS(B)
    IF NCD(A-B) = 16 Then
    tekAminB = 16
    Else
    tekAminB = 0
    EndIF
    EndIF
    'assembly of the value
    IF tekAminB = 16 Then
    C= 0 - abswaardeAminB 'negative word
    Else
    C = abswaardeAminB
    EndIF
    Return

    AmaalB: '*** AmaalB ***
    IF NCD(A) = 16 XOR NCD(B) = 16 Then
    C = ABS(A) * ABS(B)
    C = 0 - C
    Else
    C = ABS(A) * ABS(B)
    EndIF
    Return

    regelkring:
    errlastlast = errlast
    errlast = err
    err = wenswaarde - adval2 'wish temp minus real temp
    A = 2
    B = errlast
    GoSub AmaalB
    A = C
    B = errlastlast
    GoSub AminB
    A = err
    B = C
    GoSub AminB
    B = C
    A = D100 'd*100
    GoSub AmaalB
    DTERM = C
    A = I100 'I*100
    B = err
    GoSub AmaalB
    A = C 'ITerm
    B = 0 - DTERM
    GoSub AminB
    ID = C 'IDterm
    A = err
    B = errlast
    GoSub AminB 'C bevat Pterm
    A = 100
    B = C
    GoSub AmaalB
    A = C
    B= 0 - ID
    GoSub AminB 'P + ID = PID
    A = gain10 'gain * 10
    B = C
    GoTo AmaalB
    IF NCD(C) = 16 Then
    C = ABS(c)/1000 'PID term
    C = 0 - C
    Else
    C = C / 1000
    EndIF
    A = duty
    B = 0 - C
    GoSub AminB
    duty = C
    IF duty > 100 AND NCD(duty)<>16 Then duty = 100
    IF NCD(duty) = 16 Then duty = 0

    Return

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,620


    Did you find this post helpful? Yes | No

    Default

    Hi,

    As it's a slow process ... Have a look here :

    http://www.parallax.com/dl/docs/books/edu/ic.pdf

    Can be directly used with PBP ... just few mods for your sensor ( will a NTC fit your temp range ??? I'm not so sure ... )

    Good reading

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Nov 2005
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    I knows this document and will have a look at it.
    My intention was to have a PID which I can use afterwards for any process I want.
    The NTC is no problem. It comes with the original oven, and I measured the curves to translate the R-value towards °C.

  4. #4
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by joeri
    I knows this document and will have a look at it.
    My intention was to have a PID which I can use afterwards for any process I want.
    The NTC is no problem. It comes with the original oven, and I measured the curves to translate the R-value towards °C.
    What are the resistance values over the range desired? Will you use it for non lead solder, and will it (oven) be quick enough to heat up so as not to over stress the components?
    I use a Cuisinart digital convection oven, and it is a little on the slow side to hit 225c. No problems though, other than pizza tasting a little metallic.

    Ron

  5. #5
    Join Date
    Nov 2005
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    at 100°C I have 11 kOhm; at 150°C I have 3 kOhm; at 260°C I have 500Ohm. I use a current source which drives a small current through the NTC, then I amplify the voltage over the NTC with a opamp and bring it into the analog pic input. So far, so good.

    The oven is a samsung with 1500W. I added two heat resistors from a waffle machine (another 1000W), so total of 2,5KW.
    This boosts quite fast. Also, I have a fan to equalize the temp inside the oven. The complete oven is packed in rockwool.

    But my problem is the PID. Any experience on how to work with negative errors (overshoot)?

    The calculate PID values are:
    gain= 10
    I= 0,04
    D = 100

    So it seems I have a PD controller. Due to the slow process, that might be ok. Or not?
    Last edited by joeri; - 19th June 2006 at 21:20.

  6. #6
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by joeri
    at 100°C I have 11 kOhm; at 150°C I have 3 kOhm; at 260°C I have 500Ohm. I use a current source which drives a small current through the NTC, then I amplify the voltage over the NTC with a opamp and bring it into the analog pic input. So far, so good.

    The oven is a samsung with 1500W. I added two heat resistors from a waffle machine (another 1000W), so total of 2,5KW.
    This boosts quite fast. Also, I have a fan to equalize the temp inside the oven. The complete oven is packed in rockwool.

    But my problem is the PID. Any experience on how to work with negative errors (overshoot)?

    The calculate PID values are:
    gain= 10
    I= 0,04
    D = 100

    So it seems I have a PD controller. Due to the slow process, that might be ok. Or not?
    It sounds like the rock wool is overkill, plus you want to cool things down pretty quickly once soldered. I crack the door of the toaster oven slightly for my high tech solution.
    I really think the PID may be overkill. If it were me, I would take the current value at a given time and compare it to a desired constant value with ...

    heat_loop:
    for time = 1 to 10

    If curr_temp_val < set_temp_val then
    relay = 0; A lower number means the temp is too high.
    else relay = 1 ; temp too low
    endif
    pause 1000
    next time
    goto get_next_heat_increment ; Put next temp constant into set_temp_val and start again.

    Otherwise, the relay pulls in to increase temperature.You can check/regulate the temp this way until the next time increment is reached. At this point, update set_temp_val and compare. You can make the time increments every 10 seconds, or every second for that matter. A heavily insulated unit will require you to cut off power to the elements early, or you will have substantial overshoot. I'd say to use the rockwool for the hydroponic "tomatoes", and use less insulation or an automatic vent to the outside.

  7. #7
    Join Date
    Nov 2005
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    I will keep it in mind for the 'tomatoes'.
    I have a fan in the oven that can cool things down quickly.
    Also, I made a LCD-screen in the oven to read out the temp.
    Thanks for the help, but I want to implement the PID in order to have the controller ready when I want to use it for more sophisticated processes..

  8. #8
    Join Date
    May 2006
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    hi:
    take a look at these links. they should get you started.

    http://www.web-ee.com/Schematics/Tem...controller.htm


    http://www.parallax.com/dl/docs/prod...eb-PC-v1.0.pdf


    the documentation from parallax is great.

    latter
    sam

  9. #9
    Join Date
    Nov 2005
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Thank you for your support.
    I continued with my code and got it up and running.
    So this subject can be closed.

Similar Threads

  1. LM628 - Precision Motion controller - PID
    By infinitrix in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st July 2009, 06:51
  2. PID controller with PIC
    By poyet16 in forum Forum Requests
    Replies: 0
    Last Post: - 16th November 2006, 05:21
  3. PID CONTROLLER help..
    By tkly36 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th April 2006, 08:19
  4. PID controller and serin/serin2...help
    By tkly36 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th April 2006, 11:19
  5. PID controller
    By toalan in forum Off Topic
    Replies: 1
    Last Post: - 18th February 2005, 16:05

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts