---
+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Newbie level 2
    Points: 1,007, Level: 7

    Join Date
    Jun 2007
    Posts
    2
    Helped
    3 / 3
    Points
    1,007
    Level
    7

    pid c code

    I want to develop a 8051 based PID temeperature controller.i will be using IC temperture sensor LM35DZ .
    Please send me the code in C for the same on my mail id ritula.thakur@gmail.com.
    Writing code in C is not my cup of tea.Im gud in developing hardware but when softwware comes i get panicky.so please please help me. I any one has the full code please mail it to me as soon as possible. i shall e highly obliged
    Thanks in advance

  2. #2
    Newbie level 2
    Points: 1,007, Level: 7

    Join Date
    Jun 2007
    Posts
    2
    Helped
    3 / 3
    Points
    1,007
    Level
    7

    pid control c code

    To be moore precise abt my project. The temp sensor LM35DZ will be sensing the actual temperature of process and this temp will be converted into digital form by ADC 0809 and sent to microcontroller.The user can set the desired temp through keyboard.There is also LCD interfacing which will display the actual tempertaure and set temp.Th eprogram in C will containg PID algorithm to operate a relay which is connected to heater and thus accordingly turn it ON and OFF.


    2 members found this post helpful.

    •   Alt10th June 2007, 12:32

      advertising

        
       

  3. #3
    Newbie level 6
    Points: 1,571, Level: 9
    oscar_pdx's Avatar
    Join Date
    Jan 2006
    Posts
    12
    Helped
    6 / 6
    Points
    1,571
    Level
    9

    pid control code

    Simple PID

    PID = GainP * actual error + GainI * SUM(previous errors) + GainD * (actual error - last error)

    error = sp(set point) - pv(process value)


    float pid (float sp, float pv)
    {

    err_old = err;
    err = sp - pv;

    // note
    P_err = err;
    I_err += err_old;
    D_err = err - err_old;

    return 0.1*P_err + 0.3*I_err + 0.02*D_err;

    }


    //note. Dead zone example: if (err<2 && err>-2){err=0;}


    3 members found this post helpful.

    •   Alt14th June 2007, 19:58

      advertising

        
       

  4. #4
    Junior Member level 2
    Points: 1,626, Level: 9

    Join Date
    Apr 2006
    Posts
    20
    Helped
    3 / 3
    Points
    1,626
    Level
    9

    pid controller c code

    Good explanation oscar_pdx.



    •   Alt30th November 2007, 11:04

      advertising

        
       

  5. #5
    Banned
    Points: 22,963, Level: 36

    Join Date
    May 2007
    Location
    USA & Canada
    Posts
    437
    Helped
    50 / 50
    Points
    22,963
    Level
    36

    pid code in c

    That's a float-point version.



  6. #6
    Junior Member level 3
    Points: 1,211, Level: 7

    Join Date
    Dec 2007
    Location
    Peru
    Posts
    30
    Helped
    4 / 4
    Points
    1,211
    Level
    7

    c code pid

    /*u=kp*(e+Td*diff(e)+Td*int(e))
    y0=analog input 1;
    r0=ref=set point or reference;
    T=sample time;
    qd=diff constant=Kp*Td/T; //Td:diff time
    qi=integral cosntant=Kp*T/Ti; //Ti:Integration time
    Kp=prop gain;*/

    float pid (float r0, float y0)
    {
    e0=r0-y0;
    D=qd*(e0-e1);
    if (((u>umin)|(e>0))&((u<umax)|(e<0))) //antiwindup integral
    I=I+qi*(r0-y0);

    u=Kp*e0+D+I;//pid control signal
    if (u>umax) u=umax; //antiwindup PID
    if (u<umin) u=umin;

    e1=e0; //save old values
    y1=y0;
    }


    1 members found this post helpful.

  7. #7
    Member level 1
    Points: 1,475, Level: 8

    Join Date
    Apr 2006
    Location
    USA (Southern California)
    Posts
    36
    Helped
    5 / 5
    Points
    1,475
    Level
    8

    simple pid c code

    Quote Originally Posted by Fernando Vasquez
    if (((u>umin)|(e>0))&((u<umax)|(e<0))) //antiwindup integral
    Your code should use the || and && operators. I put in bold the problem areas.

    & and | are binary bitwise operators and not logical operators.



  8. #8
    Advanced Member level 4
    Points: 14,471, Level: 29

    Join Date
    Jun 2005
    Location
    Stanford, SF Bay Peninsula, California, Earth, Solar System, Milky Way
    Posts
    1,409
    Helped
    136 / 136
    Points
    14,471
    Level
    29

    simple pid code

    Here's a link to an article "PID without Ph.D." it has some ANSI C code. It's not complete, but it might still be helpful.


    1 members found this post helpful.

  9. #9
    Junior Member level 1
    Points: 702, Level: 5

    Join Date
    Jan 2010
    Location
    Mumbai
    Posts
    16
    Helped
    6 / 6
    Points
    702
    Level
    5

    Re: Code in C for PID temperature controller

    This all code ref is not working properly....
    I want to inplement full controlled pid...
    How can i do that please help me out in this...

    Thanks...

    kapilddit...



+ Post New Thread
Please login