Tolerant comparator

Guest
Hi,

I want to describe a tolerant comparator.

The basic comparation would be:


signal old_value, new_value : integer RANGE 0 to 1023;

process(Clk)
begin
if rising_edge(Clk) then
if old_value=new_value then
ls_comp <= '1';
end if;
end if;
end process;

But what if I want to include some tolerance into that comparison ?
For example: old_value is 800
ls_comp should be asserted if new_value is within the range 799 to
801.

Does someone have an idea?

Thank you for your opinions.

Rgds
André
 
One good point would be a generic tolerance.

Application: Analog DVI <---> hsync, vsync measurements
 
ALuPin@web.de wrote:
Hi,

I want to describe a tolerant comparator.

The basic comparation would be:

signal old_value, new_value : integer RANGE 0 to 1023;

process(Clk)
begin
if rising_edge(Clk) then
if old_value=new_value then
ls_comp <= '1';
end if;
end if;
end process;

But what if I want to include some tolerance into that comparison ?
For example: old_value is 800
ls_comp should be asserted if new_value is within the range 799 to
801.

Does someone have an idea?
Um, ever build an address-range comparator? Expand that a bit:

RangeComp : process (Clk, Reset) is
begin
if (Reset = '1') then
ls_comp <= '0';
elsif (rising_edge(Clk)) then
if ( (new_value < (old_value + rangemax)) or
(new_value > (old_value - rangemin)) ) then
ls_comp <= '1';
else
ls_comp <= '0';
end if;
end if;
end process RangeComp;

rangemax and rangemin can be constants or registers loaded by some
other logic.

This comparison might get pretty large and slow, so if you can't meet
timing, you might want to register the sum and difference:

RegCompValues : process (Clk, Reset) is
begin
if (Reset = '1') then
maxcomp <= 0;
mincomp <= 0;
elsif (rising_edge(Clk) then
maxcomp <= old_value + rangemax;
mincomp <= old_value - rangemin;
end if;
end process RegCompValues;

RangeComp2 : process (Clk, Reset) is
begin
if (Reset = '1') then
ls_comp <= '0';
elsif (rising_edge(Clk)) then
if ( (new_value < rangemax) or
(new_value > rangemin) ) then
ls_comp <= '1';
else
ls_comp <= '0';
end if;
end if;
end process RangeComp2;

and so forth ... in the second example, make sure you can tolerate the
pipeline delays.

-a
 
Hi Andy,

thank you for your suggestion.
In the process RegangeComp2 you compare with
the maxcomp/mincomp values defined in the first
process?

RegCompValues : process (Clk, Reset) is
begin
if (Reset = '1') then
maxcomp <= 0;
mincomp <= 0;
elsif (rising_edge(Clk) then
maxcomp <= old_value + rangemax;
mincomp <= old_value - rangemin;
end if;
end process RegCompValues;


RangeComp2 : process (Clk, Reset) is
begin
if (Reset = '1') then
ls_comp <= '0';
elsif (rising_edge(Clk)) then
if ( (new_value < maxcomp) or
(new_value > mincomp) ) then
ls_comp <= '1';
else
ls_comp <= '0';
end if;
end if;
end process RangeComp2;
 
ALuPin@web.de wrote:
Hi Andy,

thank you for your suggestion.
In the process RegangeComp2 you compare with
the maxcomp/mincomp values defined in the first
process?

RegCompValues : process (Clk, Reset) is
begin
if (Reset = '1') then
maxcomp <= 0;
mincomp <= 0;
elsif (rising_edge(Clk) then
maxcomp <= old_value + rangemax;
mincomp <= old_value - rangemin;
end if;
end process RegCompValues;


RangeComp2 : process (Clk, Reset) is
begin
if (Reset = '1') then
ls_comp <= '0';
elsif (rising_edge(Clk)) then
if ( (new_value < maxcomp) or
(new_value > mincomp) ) then
ls_comp <= '1';
else
ls_comp <= '0';
end if;
end if;
end process RangeComp2;
RangeComp2 uses the values calculated and stored in RegCompValues.

-a
 

Welcome to EDABoard.com

Sponsor

Back
Top