Sure, here’s an example of a 3-bit synchronous down counter with enable implemented using SystemVerilog:
module down_counter_3bit_enable( input logic clk, input logic enable, output logic [2:0] count ); always_ff @(posedge clk) begin if (enable) begin count <= count - 1; end end endmodule
In this code, we define a module called `down_counter_3bit_enable` with three ports: `clk`, `enable`, and `count`. The `clk` input is used as the clock signal, the `enable` input is an enable signal which allows the counter to count when it is asserted, and the `count` output is a 3-bit binary counter that counts from 7 to 0.
The `always_ff` block is used to describe the behavior of the counter. The `posedge clk` event triggers the counter to decrement on every rising edge of the clock signal. The `enable` signal is used to enable or disable the counter from counting.
When the enable signal is asserted (`enable = 1`), the counter decrements by 1 (`count <= count - 1`). When the enable signal is deasserted (`enable = 0`), the counter stops counting and maintains its current value. You can instantiate this module in your top-level design hierarchy and connect it to other modules or input/output signals as needed. Note that you can modify the code to implement an up/down counter or a bidirectional counter by changing the logic in the always_ff block to increment or decrement the counter value based on a control signal.