Skip to content

Commit

Permalink
allow user to specify clock and reset for an LDS
Browse files Browse the repository at this point in the history
  • Loading branch information
sgherbst committed Jan 21, 2020
1 parent 6e969b2 commit 861381c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
13 changes: 9 additions & 4 deletions msdsl/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def get_equation_io(self, eqn_sys: EqnSys):
# return result
return inputs, states, outputs, sel_bits

def add_eqn_sys(self, eqns: List[ModelExpr], extra_outputs=None):
def add_eqn_sys(self, eqns: List[ModelExpr], extra_outputs=None, clk=None, rst=None):
"""
Accepts a list of equations that can contain derivatives of analog state variables. The approach used is
to convert the system of differential equations into a standard-form linear dynamical system (reference:
Expand All @@ -322,6 +322,8 @@ def add_eqn_sys(self, eqns: List[ModelExpr], extra_outputs=None):
:param eqns: List of equations.
:param extra_outputs: List of internal variables in the system of equations that should be bound to analog signals.
:param clk: Name of clock signal to use (None will default to `CLK_MSDSL)
:param rst: Name of the reset signal to use (None will default to `RST_MSDSL)
"""

# set defaults
Expand Down Expand Up @@ -368,9 +370,12 @@ def add_eqn_sys(self, eqns: List[ModelExpr], extra_outputs=None):
sel = None

# add the discrete-time equation
self.add_discrete_time_lds(collection=collection, inputs=inputs, states=states, outputs=outputs, sel=sel)
self.add_discrete_time_lds(collection=collection, inputs=inputs,
states=states, outputs=outputs, sel=sel,
clk=clk, rst=rst)

def add_discrete_time_lds(self, collection, inputs=None, states=None, outputs=None, sel=None):
def add_discrete_time_lds(self, collection, inputs=None, states=None, outputs=None, sel=None,
clk=None, rst=None):
# set defaults
inputs = inputs if inputs is not None else []
states = states if states is not None else []
Expand All @@ -381,7 +386,7 @@ def add_discrete_time_lds(self, collection, inputs=None, states=None, outputs=No
for row in range(len(states)):
expr = sum_op([array(collection.A[row, col], sel) * states[col] for col in range(len(states))])
expr += sum_op([array(collection.B[row, col], sel) * inputs[col] for col in range(len(inputs))])
self.set_next_cycle(states[row], expr)
self.set_next_cycle(states[row], expr, clk=clk, rst=rst)

# output updates
for row in range(len(outputs)):
Expand Down
6 changes: 4 additions & 2 deletions tests/rc/test_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def gen_model(tau, dt):
model = MixedSignalModel('model', dt=dt)
model.add_analog_input('v_in')
model.add_analog_output('v_out')
model.add_digital_input('clk')
model.add_digital_input('rst')

model.add_eqn_sys([Deriv(model.v_out) == (model.v_in - model.v_out)/tau])
model.add_eqn_sys([Deriv(model.v_out) == (model.v_in - model.v_out)/tau],
clk=model.clk, rst=model.rst)

BUILD_DIR.mkdir(parents=True, exist_ok=True)
model_file = BUILD_DIR / 'model.sv'
Expand Down Expand Up @@ -76,7 +79,6 @@ def cycle():
simulator=simulator,
ext_srcs=[model_file, get_file('rc/test_rc.sv')],
inc_dirs=[get_svreal_header().parent],
defines={'CLK_MSDSL': 'dut.clk', 'RST_MSDSL': 'dut.rst'},
ext_model_file=True,
disp_type='realtime'
)
4 changes: 3 additions & 1 deletion tests/rc/test_rc.sv
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module test_rc(
`PASS_REAL(v_out, v_out_int)
) model_i (
.v_in(v_in_int),
.v_out(v_out_int)
.v_out(v_out_int),
.clk(clk),
.rst(rst)
);
endmodule

0 comments on commit 861381c

Please sign in to comment.