Connect with us

analogue P(ID) controller to digital PID controller

Discussion in 'Electronic Design' started by jsmith, Apr 20, 2007.

Scroll to continue with content
  1. jsmith

    jsmith Guest

    Hi

    I try to simulate an old design controller circuit "PID.asc" on a
    microcontroller

    LTspice/SwitcherCAD III software
    here is PID.asc file :
    ---------

    Version 4
    SHEET 1 5945676 13421556
    WIRE 1696 -224 1680 -224
    WIRE 1920 -224 1696 -224
    WIRE 880 -160 880 -176
    WIRE 1696 -160 1696 -224
    WIRE 1712 -160 1696 -160
    WIRE 1840 -144 1776 -144
    WIRE 2000 -144 1920 -144
    WIRE 1712 -128 1696 -128
    WIRE 1696 -80 1696 -128
    WIRE 1920 96 1696 96
    WIRE 1696 160 1696 96
    WIRE 1712 160 1696 160
    WIRE 1840 176 1776 176
    WIRE 2000 176 1920 176
    WIRE 1712 192 1696 192
    WIRE 1696 240 1696 192
    WIRE 880 320 880 304
    WIRE 1776 432 1696 432
    WIRE 1920 432 1776 432
    WIRE 1920 464 1920 432
    WIRE 2016 464 1920 464
    WIRE 2016 480 2016 464
    WIRE 1696 528 1696 432
    WIRE 1712 528 1696 528
    WIRE 1840 544 1776 544
    WIRE 2016 544 1920 544
    WIRE 2112 544 2016 544
    WIRE 1616 560 1616 464
    WIRE 1712 560 1616 560
    WIRE 1824 672 1600 672
    WIRE 1040 736 1024 736
    WIRE 1264 736 1040 736
    WIRE 1040 800 1040 736
    WIRE 1056 800 1040 800
    WIRE 1184 816 1120 816
    WIRE 1344 816 1264 816
    WIRE 1056 832 1040 832
    WIRE 1600 832 1600 736
    WIRE 1616 832 1600 832
    WIRE 1744 848 1680 848
    WIRE 1824 848 1824 752
    WIRE 1888 848 1824 848
    WIRE 2032 848 1888 848
    WIRE 2048 848 2032 848
    WIRE 1616 864 1600 864
    WIRE 1600 928 1600 864
    FLAG 1616 -128 0
    FLAG 880 -176 V+
    FLAG 1744 -176 V+
    FLAG 1744 -112 V-
    FLAG 880 208 V-
    FLAG 880 0 Vin1
    FLAG 1600 -224 Vin1
    FLAG 880 128 0
    FLAG 880 -80 0
    FLAG 880 80 0
    FLAG 1696 0 0
    FLAG 2000 -144 Vout1
    FLAG 1744 512 V+
    FLAG 1744 576 V-
    FLAG 1536 560 Vout2
    FLAG 880 304 Vin2
    FLAG 880 400 0
    FLAG 1744 144 V+
    FLAG 1744 208 V-
    FLAG 1616 192 Vin2
    FLAG 2000 176 Vout2
    FLAG 1696 304 0
    FLAG 1536 464 Vout1
    FLAG 1776 352 0
    FLAG 1920 624 0
    FLAG 2112 544 Vout3
    FLAG 960 832 0
    FLAG 1088 784 V+
    FLAG 1088 848 V-
    FLAG 944 736 Vout3
    FLAG 1344 816 Vout4
    FLAG 1648 816 V+
    FLAG 1648 880 V-
    FLAG 1520 832 Vout4
    FLAG 1888 784 0
    FLAG 2032 848 VoutF
    FLAG 1520 928 0
    SYMBOL voltage 880 -16 R0
    WINDOW 123 24 132 Left 0
    WINDOW 39 0 0 Left 0
    SYMATTR InstName V1
    SYMATTR Value PULSE(0 5 100m 100m 100m 100m 10 10)
    SYMBOL res 1696 -240 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R1
    SYMATTR Value 10K
    SYMBOL res 1936 -160 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R4
    SYMATTR Value 2.2K
    SYMBOL res 1712 -144 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R6
    SYMATTR Value 10K
    SYMBOL voltage 880 -176 R0
    WINDOW 123 0 0 Left 0
    WINDOW 39 24 44 Left 0
    SYMATTR InstName V3
    SYMATTR Value 15
    SYMBOL voltage 880 112 R0
    WINDOW 123 0 0 Left 0
    WINDOW 39 24 132 Left 0
    SYMATTR InstName V4
    SYMATTR Value 15
    SYMBOL Opamps\\LT1001 1744 -208 R0
    SYMATTR InstName U1
    SYMBOL res 1904 -240 R0
    SYMATTR InstName R2
    SYMATTR Value 5.1K
    SYMBOL res 1680 -96 R0
    SYMATTR InstName R3
    SYMATTR Value 5.1K
    SYMBOL res 1632 544 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R5
    SYMATTR Value 20K
    SYMBOL res 1936 528 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R7
    SYMATTR Value 2K
    SYMBOL Opamps\\LT1001 1744 480 R0
    SYMATTR InstName U2
    SYMBOL res 1904 448 R0
    SYMATTR InstName R9
    SYMATTR Value 120K
    SYMBOL voltage 880 304 R0
    WINDOW 123 0 0 Left 0
    WINDOW 39 24 44 Left 0
    SYMATTR InstName V2
    SYMATTR Value PULSE(0 5 100 100 100 100 10 10)
    SYMBOL res 1712 176 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R11
    SYMATTR Value 120K
    SYMBOL res 1936 160 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R12
    SYMATTR Value 2.2K
    SYMBOL Opamps\\LT1001 1744 112 R0
    SYMATTR InstName U3
    SYMBOL res 1904 80 R0
    SYMATTR InstName R14
    SYMATTR Value 120K
    SYMBOL cap 1680 240 R0
    SYMATTR InstName C1
    SYMATTR Value 10µ
    SYMATTR SpiceLine V=10 Irms=0 Rser=0.009 MTBF=0 Lser=0 ppPkg=1
    SYMBOL res 1632 448 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R13
    SYMATTR Value 20K
    SYMBOL res 1760 336 R0
    SYMATTR InstName R8
    SYMATTR Value 18K
    SYMBOL cap 2000 480 R0
    SYMATTR InstName C2
    SYMATTR Value 0.068µ
    SYMBOL res 1904 528 R0
    SYMATTR InstName R10
    SYMATTR Value 300K
    SYMBOL res 1040 720 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R15
    SYMATTR Value 75K
    SYMBOL res 1280 800 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R16
    SYMATTR Value 2.2K
    SYMBOL res 1056 816 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R17
    SYMATTR Value 5.8K
    SYMBOL Opamps\\LT1001 1088 752 R0
    SYMATTR InstName U4
    SYMBOL res 1248 720 R0
    SYMATTR InstName R18
    SYMATTR Value 6.8K
    SYMBOL res 1840 832 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R19
    SYMATTR Value 2.2K
    SYMBOL Opamps\\LT1001 1648 784 R0
    SYMATTR InstName U5
    SYMBOL res 1808 656 R0
    SYMATTR InstName R20
    SYMATTR Value 234.5K
    SYMBOL polcap 1584 672 R0
    WINDOW 3 24 64 Left 0
    SYMATTR InstName C3
    SYMATTR Value 10µ
    SYMATTR Description Capacitor
    SYMATTR Type cap
    SYMATTR SpiceLine V=100 Irms=22m Rser=3.9 MTBF=2000 Lser=0 ppPkg=1
    SYMBOL res 1616 816 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R23
    SYMATTR Value 120K
    SYMBOL zener 1872 784 R0
    SYMATTR InstName D1
    SYMATTR Value BZX84C10L
    SYMATTR Description Diode
    SYMATTR Type diode
    SYMBOL res 1616 912 R90
    WINDOW 0 0 56 VBottom 0
    WINDOW 3 32 56 VTop 0
    SYMATTR InstName R21
    SYMATTR Value 120K
    TEXT 1008 -48 Left 0 !;ac dec 100 1 1M
    TEXT 1008 -80 Left 0 !.tran 300m startup
    TEXT 920 40 Left 0 ;Vin1 : from output of pressure transducer (0-5V)
    TEXT 920 360 Left 0 ;Vin2 : from pressure setting potensiometer of
    panel (0-5V)
    TEXT 1824 896 Left 0 ;VoutF : goto pressure controller (0-10V)


    ----------

    and it is uC function

    u16 UpdatePID1(u16 plant_value, u16 setpoint)
    { u16 error;
    u32 pTerm, dTerm, iTerm, sum;
    error = plant_value - setpoint;
    pTerm = (u32)PID1_pGain * (u32)error; // calculate the proportional
    term
    PID1_iState += error; // calculate the integral
    state with appropriate limiting
    if (PID1_iState > PID1_iMax) { PID1_iState = PID1_iMax;} else
    if (PID1_iState < PID1_iMin) { PID1_iState = PID1_iMin;}
    iTerm = (u32)PID1_iGain * (u32)PID1_iState ; // calculate the
    integral term
    error = (plant_value - PID1_dState);
    dTerm = (u32)PID1_dGain * (u32)error; // calculate the differential
    term
    PID1_dState = plant_value; // keep prev. pant_value
    sum = pTerm + iTerm ;
    sum -= dTerm;
    sum /= 1000; //Gain was * 1000
    error = (u16)sum;
    if (error > PID1_Max) { error = PID1_Max;} else
    if (error < PID1_Min) { error = PID1_Min;}
    return (error);
    }

    ///////////////

    What PID parameters values
    {
    u16 PID1_dState , PID1_iState,PID1_iMax,PID1_iMin,PID1_iGain,
    PID1_pGain,PID1_dGain, PID1_Min,PID1_Max;
    }
    calculated from circuit?
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-