Think Backwards: Designing Hardware from Outputs to Inputs
📌 Introduction
When designing circuits, one often has to think of the problem “backwards”, starting from the outputs then working backwards towards the inputs. This is often the opposite of how one would think about a (sequential, imperative) programming problem, where one would look at the inputs first then decide on an action (or output). For sequential programs, one would often think “If (inputs are __ ) then (output should be __ )”. On the other hand, hardware designers often think “The (output should be __ ) when (inputs are __ )”.
🧑💻 Code Example
module top_module (
input ring,
input vibrate_mode,
output ringer, // Make sound
output motor // Vibrate
);
assign ringer = (~vibrate_mode & ring)? 1'b1 : 1'b0;
assign motor = (vibrate_mode & ring)? 1'b1 : 1'b0;
endmodule
module top_module (
input too_cold,
input too_hot,
input mode,
input fan_on,
output heater,
output aircon,
output fan
);
assign heater = (mode & too_cold)? 1'b1 : 1'b0;
assign aircon = (~mode & too_hot)?1'b1 : 1'b0;
assign fan = (fan_on | heater | aircon);
endmodule