sammyt09
Newbie level 6
sinc3 filter
Hi,
I have a brief question relating to some verilog for a sinc3 decimation filter.
In the code, I believe 2s complement is being used for the accumulation process, however, I cant quite understand what is going on. As I do not have a verilog simulator at the moment, I am hoping someone could explain it to me. The relative parts of the code in question is:
-----
/* Definitions */
input mdata1;
reg [23:0] ip_data1;
reg [23:0] acc1;
reg [23:0] acc2;
reg [23:0] acc3;
/* change from a 0 to a -1 for 2's comp */
always @ (mdata1)
if(mdata1==0)
ip_data1 <= 0;
else
ip_data1 <= 1;
/* Accumulation stage */
always @ (posedge mclk1 or posedge reset)
if (reset) begin
/*initialize acc registers on reset*/
acc1 <= 0;
acc2 <= 0;
acc3 <= 0;
end
else begin
/*perform accumulation process*/
acc1 <= acc1 + ip_data1;
acc2 <= acc2 + acc1;
acc3 <= acc3 + acc2;
end
------------
(Please note, the complete verilog code can be found here: https://www.analog.com/static/imported-files/data_sheets/AD7401A.pdf)
MY QUESTION:
If 2s complement is being used, why is 'ip_data1' defined as either '0' or '1'? I assumed it would have to be either '00....01' or '11....11', i.e plus or minus 1 using 2s complement notation.
If 'ip_data1' is either '0' or '1' the accumulator will surely only accumulate upwards and can never be negative. In which case, it is not 2s complement at all(?!)
If anyone is able to help me in my understanding of this piece of code, I would be extremely grateful. As I say, I do not have a simulator availalable at this stage, otherwise I could have figured this out myself.
Thank you very much in advance!
sammyt09
Hi,
I have a brief question relating to some verilog for a sinc3 decimation filter.
In the code, I believe 2s complement is being used for the accumulation process, however, I cant quite understand what is going on. As I do not have a verilog simulator at the moment, I am hoping someone could explain it to me. The relative parts of the code in question is:
-----
/* Definitions */
input mdata1;
reg [23:0] ip_data1;
reg [23:0] acc1;
reg [23:0] acc2;
reg [23:0] acc3;
/* change from a 0 to a -1 for 2's comp */
always @ (mdata1)
if(mdata1==0)
ip_data1 <= 0;
else
ip_data1 <= 1;
/* Accumulation stage */
always @ (posedge mclk1 or posedge reset)
if (reset) begin
/*initialize acc registers on reset*/
acc1 <= 0;
acc2 <= 0;
acc3 <= 0;
end
else begin
/*perform accumulation process*/
acc1 <= acc1 + ip_data1;
acc2 <= acc2 + acc1;
acc3 <= acc3 + acc2;
end
------------
(Please note, the complete verilog code can be found here: https://www.analog.com/static/imported-files/data_sheets/AD7401A.pdf)
MY QUESTION:
If 2s complement is being used, why is 'ip_data1' defined as either '0' or '1'? I assumed it would have to be either '00....01' or '11....11', i.e plus or minus 1 using 2s complement notation.
If 'ip_data1' is either '0' or '1' the accumulator will surely only accumulate upwards and can never be negative. In which case, it is not 2s complement at all(?!)
If anyone is able to help me in my understanding of this piece of code, I would be extremely grateful. As I say, I do not have a simulator availalable at this stage, otherwise I could have figured this out myself.
Thank you very much in advance!
sammyt09