- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi all,
i got a vhdl assignment and im stuck. i need to create a controller and data path that have 4 numbers as inputs (as well as clk and reset) and i need to arrange them from the smallest to the largest (4 outputs). i also have 1 comparator that i can use as component inside the data path (i can use only one). the comparator have 2 inputs (2 numbers) and 2 outputs (smaller number and larger number). the controller is a component inside the data path and i can program it however i want (need to have the same clk and reset as the data path as inputs, among othere inputs and outputs as we like). the contoller have a state machine, i think that the state machine has 5 or 6 states, lets say if the inputs are (A B C D) so it will compare AB and place the bigger as new A and smaller as new B, the same for CD, thats 2 states, then compare the new AC and replace larger and smaller, the same for BD, and the 5 state will be comparison of the new BC, maybe we need another state, im not sure. (thats my idea, so fell free to advice for other state machines if u got :) ) in the datapath, we can use 1 comparator, 1 controller (both as components), and whatever else we want to add, but not as components. i hope that im clear, and really need some help, cuz im stuck, thanks alot :)Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- hi all, i got a vhdl assignment and im stuck. i need to create a controller and data path that have 4 numbers as inputs (as well as clk and reset) and i need to arrange them from the smallest to the largest (4 outputs). i also have 1 comparator that i can use as component inside the data path (i can use only one). the comparator have 2 inputs (2 numbers) and 2 outputs (smaller number and larger number). the controller is a component inside the data path and i can program it however i want (need to have the same clk and reset as the data path as inputs, among othere inputs and outputs as we like). the contoller have a state machine, i think that the state machine has 5 or 6 states, lets say if the inputs are (A B C D) so it will compare AB and place the bigger as new A and smaller as new B, the same for CD, thats 2 states, then compare the new AC and replace larger and smaller, the same for BD, and the 5 state will be comparison of the new BC, maybe we need another state, im not sure. (thats my idea, so fell free to advice for other state machines if u got :) ) in the datapath, we can use 1 comparator, 1 controller (both as components), and whatever else we want to add, but not as components. i hope that im clear, and really need some help, cuz im stuck, thanks alot :) --- Quote End --- One way is to have 3 tests: test1: find max of A,B,C,D e.g C is max, put C as highest test2: find max of A,B,D e.g. D is max, put D as second highest test3: find max of A,B e.g. A is max, put A as third the last value B is fourth If you are restricted to one comparator then you need to share it for test1(3 comparisons) and test2(two comaprisons)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
as i said, the comparator only have 2 inputs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- as i said, the comparator only have 2 inputs --- Quote End --- My solution is still valid. For test1 you use one comparator to find max of A,B,C,D as follows: you assign A to a register then you update that register if B > A (one comparator with two inputs). then you update it again if C > B and again if D > C . You then move to test2, test3 It is up to you to use state machine per comparison or you can do it all in one lump of logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i understand what you saying, but i dont understand how can i do it with controller and data-path, and what state-machine the controller is?
thank you- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it your controller or somebody else's?
You are asked to do a task and I don't understand why you are supposed to do it according to a given internal recipe. You can readily design a controller based on state machine or counter and do the 6 tests using one comparator in succession.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
my controller, i can change it however i want.
im trying to understand your suggestion: my problem is like that: lets say that A is the highest, how can i continue with 3 numbers only? i mean, inside the controller and the data-path, what are the changes i need to do after im finding the new highest because, as i see it, you have more than 6 states, because u depends on what is the highest every time.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will assign all 4 numbers to 4 registers first named as reg1,reg2,reg3,reg4 (in decreasing value eventually).
at start(reset) update them with A,B,C,D respectively. in s0 : check A Vs B and update reg1,reg2 if A < B in s1: check A Vs C and update reg1,reg3 if A < C in s2: check A Vs D and update reg1,reg4 if A < D now reg1 is done and is having value of highest of 4, so now you need to check reg2,reg3,reg4 in the same way finally you check reg3,reg4 and you are done- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok, i understand you.
i will give it a try. thanks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- ok, i understand you. i will give it a try. thanks --- Quote End --- A possible guide is as follows(not tested)
when s0 =>
if reg1 < reg2 then
reg1 <= reg2;
reg2 <= reg1;
end if;
when s1 =>
if reg1 < reg3 then
reg1 <= reg3;
reg3 <= reg1;
end if;
when s2 =>
if reg1 < reg4 then
reg1 <= reg4;
reg4 <= reg1;
end if;
when s3 =>
if reg2 < reg3 then
reg2 <= reg3;
reg3 <= reg2;
end if;
when s4 =>
if reg2 < reg4 then
reg2 <= reg4;
reg4 <= reg2;
end if;
when s5 =>
if reg3 < reg4 then
reg3 <= reg4;
reg4 <= reg3;
end if;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note that above code will result in multiple comparators, one per test statement. To overcome that you need to have one comparator and wire up the nodes per state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the state machine have to be in the controller, but the registers need to be in the data-path, and the comparator is a component, so i can use that idea to the code

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page