Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17268 Discussions

Comparison between old value and new value

Altera_Forum
Honored Contributor II
2,517 Views

Hi All, 

 

Its a very simple question but I am unable to do that. Below is my code. I want to store signal data_o_new to signal data_o_old and then compare these signals with each other and do increment or decrement until these two signals become same. data_o_new is coming from an ip. Please help me... thanks 

 

Architechture starts here: 

Begin 

 

data_o_old <= data_o_new; 

data_o <= data_o_old; 

 

fading: PROCESS(clk) 

Begin 

if rising_edge(clk) then 

if data_o_new > data_o_old then 

data_o_old <= data_o_old + 1; 

elsif data_o_new < data_o_old then 

data_o_old <= data_o_old - 1; 

else 

data_o_old <= data_o_new; 

end if; 

end if; 

end process; 

 

end Architecture;
0 Kudos
15 Replies
Altera_Forum
Honored Contributor II
1,518 Views

hm... have you seen generated RTL? it seems you need one or two more registers. does new value arrive every clock-cycle ? 

is it just wire in synthesis data_o_old <= data_o_new; data_o <= data_o_old;
0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

What exactly is the problem you are having?

0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

My problem is that I dont understand how do I manage to store new value to old value signal... then that stored value, I need to decrement or increment it according to new value. After incrementing or decrementing, it should stop when old value will be equal to new value. Hope you understand it. If no, then dont hesitate to ask again. thanks

0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

Hi Alex96, 

 

I don't see RTL yet. And new value is not coming every clock. it changes when my temperature changes. but don't worry about temperature. Acutally, my ip is generating new value then I need to store it to a signal and decrement or increment it until it becomes equal to the new value.
0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

oh hope you will remove some lsb from comparison and pay attention to place one more register. So do you want to do work like SAR ADC ???

0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

You still havent explained youself - your current code appears to do what you want - so I dont see the problem? It load in a new value when new and old are the same.

0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

I am a little bit confused, maybe my VHDL coding is not that good. 

 

You did wire assignment as Alex pointed out. Doesn't that make your old value directly taking the new value? Why do you need the process to add/subtract the old value? 

 

Also the else statement in your process is weird, which directly take in the new value when it is not more or less then new value. I think maybe you need to do something like this: 

 

Architechture starts here: 

Begin 

 

-- not needed 

-- data_o_old <= data_o_new; 

 

-- assuming that you have data_o as an output 

data_o <= data_o_old; 

 

fading: PROCESS(clk) 

Begin 

if rising_edge(clk) then 

if data_o_new > data_o_old then 

data_o_old <= data_o_old + 1; 

elsif data_o_new < data_o_old then 

data_o_old <= data_o_old - 1; 

else 

data_o_old <= data_o_old; -- latch the old value if not more or less new data 

end if; 

end if; 

end process; 

 

end Architecture;  

 

Also I assume that the new data does not change every cycle.
0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

Hi mikedsouze, 

 

thanks for the reply... your idea is good about latching but you didn't assign new value to old value anywhere. This assignment is necessary because I need to take the new value and hold it into a signal until new value changes. And yes new value is not changing at every cycle but it is coming on every cycle with constant value.
0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

Sorry Alex, I described you wrong yesterday. the new value is coming on every cycle having constant value. And I don't understand you SAR ADC technique. Can you please explain. thanks

0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

Hi Tricky, 

 

Let me explain by an example.  

 

-- let say new_value is incrementing or decrementing after 1 msec -- means new_value is constant for every 1 msec -- let say new_value = 4095 for 1 msec then new_value = 3998 for 1 msec then new_value = 3886 (decimal values) and so on... 

Now I want to make smooth transition between 4095 to 3998 and 3998 to 3886. I dont want abrupt change of new value. that's why I store the new value to a signal then do increment or decrement to that signal while my signal is going to output having a smooth transition.
0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

then why not do something like this? 

 

signal value_ref : unsigned(Nbits-1 downto 0); signal output_ref : unsigned(Nbits-1 downto 0); process(clk) begin if rising_edge(clk) then value_ref <= new_value; if value_ref > output_ref then output_ref <= output_ref +1; elsif value_ref < output_ref then output_ref <= output_ref -1; end if; end if; end process; op <= output_ref;  

 

Here, the output never changes dramatically, but is gradually pulled towards your new value.
0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

 

--- Quote Start ---  

 

I dont want abrupt change of new value. that's why I store the new value to a signal then do increment or decrement to that signal while my signal is going to output having a smooth transition. 

--- Quote End ---  

 

 

A more practical approach is running average filter, it does not need any mults, you just add say 8 samples together then discard 3 Lsb off result. 

 

If you are aiming at incrementing/decrementing by 1 you may either not have enough time to catch up or you have more gaps
0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

thanks tricky... I dont understand what is initial value of output_ref?? So how it can be compared

0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

 

--- Quote Start ---  

thanks tricky... I dont understand what is initial value of output_ref?? So how it can be compared 

--- Quote End ---  

 

 

Sorry, I should have initialised it - you could do it like this: 

 

signal output_ref : unsigned(Nbits-1 downto 0) := (others => '0'); --or whatever value you want 

 

or with a reset.
0 Kudos
Altera_Forum
Honored Contributor II
1,518 Views

Thanks guys... its working now. thank you very much

0 Kudos
Reply