Index: trunk/FACT++/scripts/Main.js
===================================================================
--- trunk/FACT++/scripts/Main.js	(revision 17016)
+++ trunk/FACT++/scripts/Main.js	(revision 17028)
@@ -192,5 +192,5 @@
 // ================================================================
 
-var service_feedback = new Subscription("FEEDBACK/DEVIATION");
+var service_feedback = new Subscription("FEEDBACK/CALIBRATED_CURRENTS");
 
 service_feedback.onchange = function(evt)
@@ -202,22 +202,26 @@
         return;
 
-    var delta = evt.obj['DeltaBias'];
-
-    // It seems this can happen when the feedback was newly started. Why?
-    // What is the correct solution?
-    if (!delta)
+    var Unom = evt.obj['U_nom'];
+    var Uov  = evt.obj['U_ov'];
+    if (!U_ov)
         return;
 
+    var cnt = 0;
     var avg = 0;
     for (var i=0; i<320; i++)
-        avg += delta[i];
+    {
+        var dU = Uov[i]-Unom;
+
+        // 0.022 corresponds to 1 DAC count (90V/4096)
+        if (Math.abs(dU)>0.033)
+            cnt++;
+
+        avg += dU;
+    }
     avg /= 320;
 
-    if (this.previous)
-        this.voltageStep = Math.abs(avg-this.previous);
-
-    this.previous = avg;
-
-    console.out("  DeltaV=%.3f".$(this.voltageStep));
+    this.ok = cnt==0;
+
+    console.out("  DeltaUov=%.3f [N(>0.033V)=%d]".$(this.voltageStep, cnt));
 }
 
@@ -247,23 +251,9 @@
         // ramping and will reject the command to switch the
         // voltage off
-        var isControl = dim.state("FEEDBACK").name=="CurrentControl";
-        if (isControl)
-        {
-            //console.out("  Suspending feedback.");
-            dim.send("FEEDBACK/ENABLE_OUTPUT", false);
-            dim.wait("FEEDBACK", "CurrentCtrlIdle", 3000);
-        }
+        dim.send("FEEDBACK/STOP");
+        dim.wait("FEEDBACK", "Calibrated", 3000);
 
         // Switch voltage off
-        //console.out("  "+new Date().toUTCString()+": Voltage off: switch off");
         dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
-
-        // If the feedback was enabled, re-enable it
-        if (isControl)
-        {
-            //console.out("  Resuming feedback.");
-            dim.send("FEEDBACK/ENABLE_OUTPUT", true);
-            dim.wait("FEEDBACK", "CurrentControl", 3000);
-        }
     }
 
@@ -307,7 +297,6 @@
     {
         dim.log("Switching voltage on.");
-        //console.out(JSON.stringify(dim.state("BIAS_CONTROL")));
-
-        dim.send("BIAS_CONTROL/SET_GLOBAL_DAC", 1);
+        dim.send("FEEDBACK/START", 1.1);
+        dim.wait("FEEDBACK", "InProgress", 45000);
     }
 
@@ -315,44 +304,16 @@
     dim.wait("BIAS_CONTROL", "VoltageOn", 5000);
 
-    // From now on the feedback waits for a valid report from the FSC
-    // and than switchs to CurrentControl
-    dim.wait("FEEDBACK", "CurrentControl", 60000);
-
     if (isOff)
-    {
-        dim.log("Voltage on, feedback will start ramping [cnt="+this.cnt+"]");
-
-        this.previous = undefined;
-        this.cnt = this.get().counter;
-        this.voltageStep = undefined;
-    }
+        this.ok = false;
 }
 
 service_feedback.waitForVoltageOn = function()
 {
-    // waiting 45sec for the current control to stabilize...
-    // v8.sleep(45000);
-
-    // ----- Wait for at least three updates -----
-    // The feedback is started as if the camera where at 0deg
-    // Then after the first temp update, the temperature will be set to the
-    // correct value (this has already happened)
-    // So we only have to wait for the current to get stable.
-    // This should happen after three to five current updates.
-    // So we want one recent temperature update
-    //  and three recent current updates
-
     // Avoid output if condition is already fulfilled
-    if (this.cnt && this.get().counter>this.cnt+10)
-        return;
-
     dim.log("Waiting for voltage to be stable.");
 
-    // 0.022 corresponds to 1 DAC count (90V/4096)
     function func()
     {
-        if (irq ||
-            (this.cnt!=undefined && this.get().counter>this.cnt+10) ||
-            (this.voltageStep && this.voltageStep<0.022))
+        if (irq || this.ok)
             return true;
     }
@@ -360,10 +321,10 @@
     var now = new Date();
 
-    v8.timeout(4*60000, func, this);
+    v8.timeout(60000, func, this);
 
     if (irq)
-        dim.log("Waiting for stable voltage interrupted [dU=%.3fV, cnt=%d, %.2fs]".$(this.voltageStep, this.get().counter, (new Date()-now)/1000));
+        dim.log("Waiting for stable voltage interrupted.");
     else
-        dim.log("Voltage stable within limits [dV=%.3f, cnt=%d, %.2fs]".$(this.voltageStep, this.get().counter, (new Date()-now)/1000));
+        dim.log("Voltage stable within limits");
 }
 
@@ -411,5 +372,4 @@
 
     //dim.send("FEEDBACK/STOP");
-    dim.send("FEEDBACK/ENABLE_OUTPUT", false);
     dim.send("FTM_CONTROL/STOP_TRIGGER");
     dim.send("BIAS_CONTROL/DISCONNECT");
@@ -417,5 +377,5 @@
     dim.wait("FTM_CONTROL",  "Valid",        3000);
     dim.wait("BIAS_CONTROL", "Disconnected", 3000);
-    dim.wait("FEEDBACK",     "Connected",    3000);
+    dim.wait("FEEDBACK",     "Calibrated",   3000);
 
     var report = sub.get();
@@ -483,5 +443,6 @@
          "FEEDBACK/CALIBRATED_CURRENTS",
          "FEEDBACK/CALIBRATION",
-         "FEEDBACK/DEVIATION",
+         "FEEDBACK/CALIBRATION_R8",
+         "FEEDBACK/CALIBRATION_STEPS",
          "FEEDBACK/REFERENCE",
          "FSC_CONTROL/CURRENT",
@@ -582,8 +543,5 @@
 service_feedback.get(5000);
 
-dim.send("FEEDBACK/ENABLE_OUTPUT", true);
-dim.send("FEEDBACK/START_CURRENT_CONTROL", 0.);
-
-v8.timeout(3000, function() { var n = dim.state("FEEDBACK").name; if (n=="CurrentCtrlIdle" || n=="CurrentControl") return true; });
+//v8.timeout(3000, function() { var n = dim.state("FEEDBACK").name; if (n=="CurrentCtrlIdle" || n=="CurrentControl") return true; });
 
 // ----------------------------------------------------------------
@@ -802,5 +760,5 @@
          [ "AGILENT_CONTROL", [ "VoltageOn"                ] ],
          [ "BIAS_CONTROL",    [ "VoltageOff", "VoltageOn", "Ramping" ] ],
-         [ "FEEDBACK",        [ "CurrentControl", "CurrentCtrlIdle" ] ],
+         [ "FEEDBACK",        [ "Calibrated", "InProgress" ] ],
          [ "LID_CONTROL",     [ "Open", "Closed"           ] ],
          [ "DRIVE_CONTROL",   drive_states/*[ "Armed", "Tracking", "OnTrack" ]*/ ],
@@ -946,4 +904,5 @@
         console.out("");
         break; // case "RATESCAN"
+
 
     case "DATA":
Index: trunk/FACT++/scripts/Startup.js
===================================================================
--- trunk/FACT++/scripts/Startup.js	(revision 17016)
+++ trunk/FACT++/scripts/Startup.js	(revision 17028)
@@ -217,22 +217,20 @@
 function makeCurrentCalibration()
 {
-     dim.send("BIAS_CONTROL/SET_GLOBAL_DAC", 1);
-     dim.wait("BIAS_CONTROL", "VoltageOn", 3000);
-
-     var now = new Date();
-     dim.send("FEEDBACK/CALIBRATE_CURRENTS");
-
-     // FIXME: Timeout!
-     console.out("Wait for calibration to start");
-     dim.wait("FEEDBACK", "Calibrating", 5000);
-
-     console.out("Wait for calibration to end");
-     dim.wait("FEEDBACK", "Connected", 60000);
-
-     console.out("Calibration finished ["+(new Date()-now)+"ms]");
-
-     console.out("Wait for voltage to be off");
-     dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
-     dim.wait("BIAS_CONTROL", "VoltageOff", 5000);
+    dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
+    dim.wait("BIAS_CONTROL", "VoltageOff", 15000);
+
+    var now = new Date();
+    dim.send("FEEDBACK/CALIBRATE");
+
+    console.out("Wait for calibration to start");
+    dim.wait("FEEDBACK", "Calibrating", 5000);
+
+    console.out("Wait for calibration to end");
+    dim.wait("FEEDBACK", "Calibrated", 60000);
+
+    console.out("Calibration finished ["+(new Date()-now)+"ms]");
+
+    console.out("Wait for voltage to be off");
+    dim.wait("BIAS_CONTROL", "VoltageOff", 5000);
 }
 
@@ -260,4 +258,11 @@
 
 service_calibration.close();
+
+// ================================================================
+
+dim.send("BIAS_CONTROL/SET_EXPERT_MODE", true);
+dim.send("BIAS_CONTROL/EXPERT_LOAD_MAP_FILE", "/home/fact/operation/GAPDmap_with_spare_module-new.txt");
+dim.send("BIAS_CONTROL/SET_EXPERT_MODE", false);
+dim.send("FEEDBACK/ENABLE_OLD_ALGORITHM", false);
 
 // ================================================================
@@ -279,5 +284,5 @@
  [ "AGILENT_CONTROL", [ "VoltageOn"                       ] ],
  [ "BIAS_CONTROL",    [ "VoltageOn", "VoltageOff"         ] ],
- [ "FEEDBACK",        [ "Connected"                       ] ],
+ [ "FEEDBACK",        [ "Calibrated"                      ] ],
  [ "RATE_SCAN",       [ "Connected"                       ] ],
  [ "RATE_CONTROL",    [ "Connected"                       ] ],
Index: trunk/FACT++/scripts/handleFeedbackConnected.js
===================================================================
--- trunk/FACT++/scripts/handleFeedbackConnected.js	(revision 17016)
+++ trunk/FACT++/scripts/handleFeedbackConnected.js	(revision 17028)
@@ -16,17 +16,16 @@
     case "Disconnected":
     case "Connecting":
-    case "ConnectedFSC":
-    case "ConnectedFAD":
         return undefined;
 
     case "Connected":
+    case "Calibrated":
         return "";
 
-    case "FeedbackIdle":
-    case "TempCtrlIdle":
-    case "CurrentCtrlIdle":
-    case "FeedbackControl":
-    case "TempControl":
-    case "CurrentControl":
+    case "WaitingForData":
+    case "InProgress":
+        console.out("Feedback in '"+state.name+"'... sending STOP... waiting for 'Calibrated'.");
+        dim.send("FEEDBACK/STOP");
+        return "Calibrated";
+
     case "Calibrating":
         console.out("Feedback in '"+state.name+"'... sending STOP... waiting for 'Connected'.");
