How to Make 3-bit Number Comparisons
Overview
In many cases, detecting when a number is greater than, less than, and/or equal to is desirable. These comparisons only require two Look-Up Tables (LUTs) to implement for a 3-bit number. Greater than and less than are the same operation, but with the look-up values inverted.
Requirements
Verilog Code for “Counter3” module
input CLK;
output out0, out1, out2;
reg [2:0] counter;
assign out0 = counter[0];
assign out1 = counter[1];
assign out2 = counter[2];
always @(posedge CLK) begin
counter <= counter + 1;
end
endmodule
Procedure
Create the necessary Counter3 Verilog files in the CLB tool. Refer to the Verilog Code for “Counter 3” module section for the needed Verilog code.
Implement the CLB logic.
Configure the CLB to implement the breathing LED logic. Refer to the block diagram for guidance.
Configure the Look-Up Tables (LUTs).
Click on each LUT and look at the properties.
At the bottom of the table, there is a text field for entering a hexadecimal number corresponding to the truth table.
The LUT values vary depending on the configuration. See the list below:
- For Less Than (Reference Value):
MSB LUT = 00B2
- For Equal To (Reference Value):
MSB LUT = 0081
- For Less Than or Equal To (Reference Value):
MSB LUT = 00B2
- For Greater Than, invert the output of the MSB LUT or swap the inputs
Assign the outputs as desired.
Results
Less Than
The output is HIGH if the counter is greater than, but not equal to, the reference value of 4.
Equal To
The output is HIGH if the counter is equal to 4.
Less Than or Equal To
The output is HIGH if the counter is less than OR equal to the reference value of 4.