Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Optimized comparator

Reply
Thread Tools

Optimized comparator

 
 
ALuPin@web.de
Guest
Posts: n/a
 
      08-24-2005
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é

 
Reply With Quote
 
 
 
 
Zara
Guest
Posts: n/a
 
      08-24-2005
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

 
Reply With Quote
 
 
 
 
ALuPin@web.de
Guest
Posts: n/a
 
      08-24-2005
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é



Zara schrieb:

> 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


 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      08-24-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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
 
Reply With Quote
 
Zara
Guest
Posts: n/a
 
      08-25-2005
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.

 
Reply With Quote
 
ALuPin@web.de
Guest
Posts: n/a
 
      08-25-2005
Hi Zara,

not shouting )

Rgds
André


Zara schrieb:

> 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.


 
Reply With Quote
 
ALuPin@web.de
Guest
Posts: n/a
 
      08-25-2005
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é

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tolerant comparator ALuPin@web.de VHDL 4 09-01-2005 05:31 PM
counter plus comparator john VHDL 4 11-10-2004 05:41 AM
comparator problem sk VHDL 0 11-03-2004 07:12 PM
Comparator and minimum value address sunil VHDL 4 02-22-2004 08:10 PM
flags vs. comparator Valentin Tihomirov VHDL 5 11-11-2003 05:16 PM



Advertisments