Optimized comparator

A

ALuPin

Hi,

for arbitration purpose I need to store a 12 bit value
three times.

Then I need to compare the three registers.
What is the best way to save ressources ?
Is the approach shown a good one ?


process(Rst, Clk)
begin
if Rst='1' then
ls_reg0 <= (OTHERS => '0');
ls_reg1 <= (OTHERS => '0');
ls_equal <= '0';

elsif rising_edge(Clk) then
ls_equal <= '0';

if ls_store0='1' THEN
ls_reg0 <= DataIn;
end if;

if ls_store1='1' THEN
ls_reg1 <= DataIn;
end if;

if ls_store2='1' THEN
if ((ls_reg0=ls_reg1) AND (ls_reg1=DataIn)) then
ls_equal <= '1';
end if;
end if;

end if;
end process;

Rgds
André
 
Z

Zara

process(Rst,Clk)
begin
if Rst='1' then
ls_reg<=(OTHERS=>'0');
ls_cmp<='0';
ls_equal<='0';
elsif rising_edge(Clk) then
ls_reg<=DataIn;
if ls_reg=DataIn then
ls_cmp<='1'
ls_equal<=ls_cmp;
else
ls_cmp<='0';
ls_equal<='0';
end if;
end if;
end process;

You compare anly once.

Easy and minimum
 
A

ALuPin

No, no.

Only if there are THREE EQUAL register values in series
ONLY THEN I want my 'equal' signal going high.

The question was if there is some minimum implementation for THAT.

Rgds
André
 
M

Mike Treseler

for arbitration purpose I need to store a 12 bit value
three times.
Then I need to compare the three registers.
What is the best way to save ressources ?

You can answer this question yourself by
adding port and signal declarations and
running a trial synthesis. Read
the utilization stats and look at the RTL
schematic viewer.
Is the approach shown a good one ?

Only you can answer that question.
Let's assume that your simulation
ran as expected.

I see no arbitration here, but
it looks like valid synthesis code for
two clock-enabled input registers and
and a single bit output register,
active whenever both input registers
match the signal DataIn.

Your code could be made more readable,
but I can't think of any changes
that would affect synthesis for the better.

-- Mike Treseler
 
Z

Zara

You don´t need to register all three values. Look again at the listing
I sent:

ls_reg contains the value at last transition
ls_cmp contains the result of comparing the value at last transition
with the vaule at one-before-last transition

In the transition, some things are done:

1. if value on last transition equals value now:
a) equal is signed if value ls_cmp is signed: That gives us the
"all three values are equal" needed
b) ls_cmp is updated
2. ls_reg is updated

If you simulate it, you will see it works.
And it is really compact.

So, please don't SHOUT.
 
A

ALuPin

I was not clear:
With "In series " I do not mean in three consecutive clock cycles
but when the conditions ls_store0, ls_store1, ls_store2 become
true in series.

Rgds
André
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,230
Latest member
LifeBoostCBD

Latest Threads

Top