Today we continue with the Logic Design series on SystemVerilog in order to get into Circuit Examples. Both combinational and sequential logic will be covered!
So, without further ado, let's get straight into it!
Combinational Logic
In Verilog and SystemVerilog combinational circuitry can be written using:
assign statement (data flow representation)
combinational always block
gate primitives (structural representation)
user-defined primitives (truth table)
The main difference between SystemVerilog and Verilog is that a combinational always block uses a different keyword, always_comb, instead of always, so that unintentional design mistakes are avoided.
Let's only cover such implementations...
Encoder
The best way of implementing encoders, decoders and multiplexers in SystemVerilog is within a combinational always block, and using either if-else statements or a case statement. The second approach usually leads to better maintainability.
Let's, for example, consider an 4-to-2 encoder with input i and output o. One valid implementation in SystemVerilog looks like this:
moduleencoder_4to2(output[1:0]o,input[3:0]i);always_combbegincase(i)4'b0001 : o = 2'b00;4'b0010 : o = 2'b01;4'b0100 : o = 2'b10;4'b1000 : o = 2'b11;default:o=2'bxx;endcaseendendmodule
Sequential Logic
Sequential logic in Verilog and SystemVerilog is written within sequential always blocks. This includes Flips Flops, Latches and Counters. The main difference of SystemVerilog and Verilog is that different keywords are used instead of a simple always. There are two keywords of them, one for flip flops and one for latches, which are always_ff and always_latch respectively.
Flip Flops
Specifying a synchronous reset D-FF in SystemVerilog looks like this:
In Verilog, such non-synthesizable circuitry is sometimes accidentally generated due to the use of the same keyword, always, for all types of blocks. So, these specialized blocks are a big plus for SystemVerilog!
Constraints and Randomization → Testing and Verification, Random Variables (Standard, Random-Cyclic), Randomize Method (Constraint and Random Mode, Pre / Post Randomize)