Hier mal meine Version eines PID Regler mit einem Verschiebealgorhytmus. Problem ist das es nach Regeltätigkeit zu einer bleibenden Abweichung kommt. Muss durch den Schritt Y = Y1 + M0 kommen da es immer der letzte Stellwert ist der die Abweichung ist.Code:$regfile = "m8def.dat" $crystal = 8000000 $baud = 9600 Dim Y As Single Dim Y1 As Single Dim Yaus As Integer Dim Xj0 As Single Dim Xj1 As Single Dim Xj2 As Single Dim M0 As Single Dim M1 As Single Dim M2 As Single Dim Ist As Integer Dim Soll As Integer Dim A As Single Dim B As Integer Const Q0 = 13.01 Const Q1 = -25.5 Const Q2 = 12.5 Config Portb = Output Config Timer1 = Timer , Prescale = 8 Enable Interrupts On Timer1 Zeit Config Adc = Single , Prescaler = Auto , Reference = Off Config Pinc.0 = Input 'Istwert Config Pinc.1 = Input 'Sollwert Portc.0 = 1 Portc.0 = 1 Start Adc Xj0 = 0 Xj1 = 0 Xj2 = 0 Y = 0 Timer1 = 55536 Enable Timer1 For B = 0 To 100 Step 1 Ist = 0 Soll = 0 Waitms 10 Next Do Ist = 0 Soll = 1 Loop Zeit: Timer1 = 55536 Xj0 = Soll - Ist M0 = Q0 * Xj0 M1 = Q1 * Xj1 M2 = Q2 * Xj2 Y = Y1 + M0 Y = Y + M1 Y = Y + M2 Xj2 = Xj1 Xj1 = Xj0 Print Y Y1 = Y Y = 0 Return
Für die Einstellung mit kp und so bitte folgende Formle benutzen:
[/img]
Die Grunde liegende Formel ist so abgeleitet:







Zitieren

Lesezeichen