nickwang1982
Newbie level 4
- Joined
- Jan 27, 2012
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Newbury, Berkshire, United Kingdom
- Activity points
- 1,354
Here is my problem.
I have unknown number of inputs (all with 3-bit wide), depending on the system configuration. I want to design a decoder to select the input with largest value as the output. So I am using embedded ruby here, so that the configuration can be passed to RTL.
Here is my design:
Will this work? I am not sure about the for-loop here. Is it going to work as I want? Is there any other way to do it?
I have unknown number of inputs (all with 3-bit wide), depending on the system configuration. I want to design a decoder to select the input with largest value as the output. So I am using embedded ruby here, so that the configuration can be passed to RTL.
Here is my design:
Code:
[B]module[/B] decoder
(
<% (1...NUM_INPUT).[B]each do[/B] |i| -%>
[B]input [/B] [2:0] freq_<%=i%>,
<% end -%>
[B]output[/B] [2:0] decoded_freq
)
<% (1...NUM_INPUT-1).[B]each do[/B] |i| -%>
[B]wire[/B] [2:0] x<%=i%>,
<% end -%>
[B]integer [/B]i;
//decode logic below
[B]assign [/B]x1 = (freq_1 > freq_2)? freq_1:freq_2; //compare the first two inputs and select the bigger one
[B]for [/B](i=1; i<NUM_INPUT-1;i++) //for-loop to do the rest
x<%=i+1%> = (x<%=i%> > freq_<%=i+2%>)? x<%=i%>:freq_<%=i+2%>;
[B]assign [/B]decoded_freq = x<%=NUM_INPUT-1%>;
[B]endmodule[/B]
Will this work? I am not sure about the for-loop here. Is it going to work as I want? Is there any other way to do it?
Last edited: