- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 synthesisdata_o_old <= data_o_new;
data_o <= data_o_old;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What exactly is the problem you are having?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks tricky... I dont understand what is initial value of output_ref?? So how it can be compared
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks guys... its working now. thank you very much

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page