Index: /trunk/FACT++/src/feedback.cc
===================================================================
--- /trunk/FACT++/src/feedback.cc	(revision 12220)
+++ /trunk/FACT++/src/feedback.cc	(revision 12221)
@@ -183,5 +183,8 @@
                 return;
 
-            const double diff = (25-avg)*0.057;
+            avg /= num;
+
+
+            const float diff = (avg-25)*0.057;
 
             vector<float> vec(2*BIAS::kNumChannels);
@@ -351,18 +354,22 @@
                             // Kd = 0;
 
-                            //                    -110 / -110 (-23 DAC / -0.51V)
-                            // Reference voltage: -238 / -203
-                            //                    -360 / -343 ( 23 DAC /  0.51V)
-
-                            // 0.005 A/V
-                            // 220 Amplitude / 1V
-
-                            // Gain = 1V / 200 = 0.005
-
                             // => Kp = 0.01 * gain     = 0.00005
                             // => Ki = 0.8  * gain/20s = 0.00025
                             // => Kd = 0.1  * gain/20s = 0.00003
 
-                            //valarray<double> correction = - Kp*(PV[2] - PV[1]) + Ki * dT * (SP-PV[2]) - Kd/dT * (PV[2] - 2*PV[1] + PV[0]);
+                            //valarray<double> correction =
+                            // -      Kp * (PV[2] - PV[1])
+                            // + dT * Ki * (SP    - PV[2])
+                            // - Kd / dT * (PV[2] - 2*PV[1] + PV[0]);
+                            //
+                            // - (Kp+Kd/dT1) * (PV[2] - PV[1])
+                            // + dT2 * Ki * (SP    - PV[2])
+                            // + Kd / dT1 * (PV[1] - PV[0]);
+                            //
+                            // - Kp * (PV[2] - PV[1])
+                            // + Ki * (SP    - PV[2])*dT
+                            // - Kd * (PV[2] - PV[1])/dT
+                            // + Kd * (PV[1] - PV[0])/dT;
+                            //
                             //valarray<double> correction =
                             //    - Kp*(PV[2] - PV[1]) + Ki * T21 * (SP-PV[2]) - Kd*(PV[2]-PV[1])/T21 - Kd*(PV[0]-PV[1])/T01;
@@ -373,4 +380,16 @@
                                  +  fKd/T10*(fPV[1]-fPV[0])
                                 );
+
+                            /*
+                             integral = 0
+                             start:
+                                 integral += (fSP - fPV[2])*dt
+
+                                 output = Kp*(fSP - fPV[2]) + Ki*integral - Kd*(fPV[2] - fPV[1])/dt
+
+                                 wait(dt)
+
+                                 goto start
+                             */
 
                             vector<float> vec(2*BIAS::kNumChannels);
@@ -725,4 +744,13 @@
             return 1;
         }
+
+        //                    -110 / -110 (-23 DAC / -0.51V)
+        // Reference voltage: -238 / -203
+        //                    -360 / -343 ( 23 DAC /  0.51V)
+
+        // 0.005 A/V
+        // 220 Amplitude / 1V
+
+        // Gain = 1V / 200 = 0.005
 
         fGain = 5; // (BIAS)V / (DRS)V     ( 1V / 0.22V )
@@ -794,4 +822,6 @@
 void PrintHelp()
 {
+    Main::PrintHelp<StateMachineFeedback>();
+
     /* Additional help text which is printed after the configuration
      options goes here */
