rawbus
Member level 1
I cannot get the following code to produce the correct results of a subtraction and I'm not sure what is wrong with it. Current is an input from an ADC that is in two's complement form. The clk is the same for both the ADC so that I should be clocking in a new sample at the same rate of the ADC sampling.
The only thing I can think of is that I need to register in current as well, although I think that syncing the process to the clock would give the same effect. Also, maybe converting the std_logic_vector type of current and prev_current to signed signals is not working correctly. This is my first time doing this so if this is the wrong approach I would appreciate any criticism/critique.
The only thing I can think of is that I need to register in current as well, although I think that syncing the process to the clock would give the same effect. Also, maybe converting the std_logic_vector type of current and prev_current to signed signals is not working correctly. This is my first time doing this so if this is the wrong approach I would appreciate any criticism/critique.
Code:
prev_current_reg: process(clk) begin
if(rising_edge(clk)) then
prev_current <= current;
prev_di_dt <= curr_di_dt;
end if;
end process;
current_i <= signed(current);
prev_current_i <= signed(prev_current);
di_dt_calc: process(clk) begin
if(rising_edge(clk)) then
curr_di_dt <= current_i - prev_current_i;
end if;
end process;