From b631c1fa4afb6f11d54489ae14d6fb3521c2a5ae Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 11 Dec 2024 14:49:05 +0800 Subject: [PATCH] pid: add pipeline on error signal computation --- fast-servo/pid_err_sig_pipeline.patch | 19 +++++++++++++++++++ flake.nix | 1 + 2 files changed, 20 insertions(+) create mode 100644 fast-servo/pid_err_sig_pipeline.patch diff --git a/fast-servo/pid_err_sig_pipeline.patch b/fast-servo/pid_err_sig_pipeline.patch new file mode 100644 index 0000000..4e09e27 --- /dev/null +++ b/fast-servo/pid_err_sig_pipeline.patch @@ -0,0 +1,19 @@ +diff --git a/gateware/logic/pid.py b/gateware/logic/pid.py +index e737577..f1a4096 100644 +--- a/gateware/logic/pid.py ++++ b/gateware/logic/pid.py +@@ -43,10 +43,12 @@ class PID(Module, AutoCSR): + self.comb += [setpoint_signed.eq(self.setpoint.storage)] + + self.error = Signal((self.width + 1, True)) ++ error_reg = Signal((self.width + 1, True)) ++ self.sync += self.error.eq(error_reg) + + self.comb += [ +- If(self.running, self.error.eq(self.input - self.setpoint.storage)).Else( +- self.error.eq(0) ++ If(self.running, error_reg.eq(self.input - self.setpoint.storage)).Else( ++ error_reg.eq(0) + ) + ] + diff --git a/flake.nix b/flake.nix index f3d89b0..80c0b46 100644 --- a/flake.nix +++ b/flake.nix @@ -169,6 +169,7 @@ fast-servo/iir_pipeline.patch fast-servo/linien_module_pipeline.patch fast-servo/pid_pipeline.patch + fast-servo/pid_err_sig_pipeline.patch ]; nativeBuildInputs = [ (pkgs.python3.withPackages(ps: [