0
\$\begingroup\$

New to Verilog/HDL and have a problem whenever I try to perform an if/else conditional between two registers of different size. Synthesis completes but I am never able to get it to fit.

For example I have an 8 bit register with options. The lower 4 bits is a number between 0 and 15 I need to test against. What is the correct way to do this?

reg [7:0] options;
reg [3:0] conuter;

always @(posedge clk)
begin
    if(conuter >= options[3:0])
        ... do somthing... 
end

Have also tried it this way.

reg [7:0] options;
wire [3:0] options_lowerpartof;
assign options_partof = options[3:0];

always @(posedge clk)
begin
    if(conuter >= options_lowerpartof)
        ... do somthing... 
end
\$\endgroup\$
  • \$\begingroup\$ These two code samples should synthesize to the same logic (aside from the second having no declaration for conuter). If you had trouble fitting your design, explain more about what your target device was, and why you think this part of the design is what's causing the failure to fit. \$\endgroup\$ – The Photon Apr 2 '18 at 4:57
  • 3
    \$\begingroup\$ Sorry. Yes they worked I just ran out of space on the device. I should probably delete the question. \$\endgroup\$ – dave.zap Apr 2 '18 at 7:11
0
\$\begingroup\$

Both the options can help you to compare the part of the register. The main thing which you should keep in mind is that wire are elements in Verilog that are used to connect input and output ports of a module instantiation together with some other element in your design, so it is better to use

wire [3:0] options_lowerpartof; assign options_partof = options[3:0];

only when the only task to be done is the comparison. Here the 'wire' keyword helps to connect two different modules together (this is a concept of modular programming in Verilog).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.