Tolerant comparator

A

ALuPin

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é
 
A

ALuPin

One good point would be a generic tolerance.

Application: Analog DVI <---> hsync, vsync measurements
 
A

Andy Peters

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
 
A

ALuPin

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;
 
A

Andy Peters

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
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top