Forum Discussion
Altera_Forum
Honored Contributor
10 years agoComparison between old value and new value
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;15 Replies
- Altera_Forum
Honored Contributor
then why not do something like this?
Here, the output never changes dramatically, but is gradually pulled towards your new value.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; - Altera_Forum
Honored Contributor
--- 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 - Altera_Forum
Honored Contributor
thanks tricky... I dont understand what is initial value of output_ref?? So how it can be compared
- Altera_Forum
Honored Contributor
--- 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. - Altera_Forum
Honored Contributor
Thanks guys... its working now. thank you very much