Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Verilog Code giving wrong output for subtraction / -1 * number

Status
Not open for further replies.

rahdirs

Advanced Member level 1
Joined
May 22, 2013
Messages
424
Helped
93
Reputation
192
Reaction score
91
Trophy points
1,308
Location
Mordor
Activity points
4,492
Hi,

I am trying to do the following in Verilog: if count < 8, pass the i/p to o/p, else multiply the i/p by -j. Note: i/p is a complex number.

My code:

Code:
always @(count,out2_complex_bf1,out2_real_bf1) begin
if (count >= 4'b1000) begin
	out2_real_bf1_t 		<= out2_complex_bf1;
	out2_complex_bf1_t 	<= (~(out2_real_bf1)) + 1;
end else
	out2_real_bf1_t 		<= out2_real_bf1;
	out2_complex_bf1_t 	<= out2_complex_bf1;	
end

I tried doing
Code:
out2_complex_bf1_t 	<= (~(out2_real_bf1)) + 1;
by just putting -(out2_real_bf1). But o/p is all 0. I have attached the waveform.

Capture.JPG
 

Is the missing begin a typo? As written above you have the following code:


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
always @(count,out2_complex_bf1,out2_real_bf1) begin
 
  if (count >= 4'b1000) begin
    out2_real_bf1_t    <= out2_complex_bf1;
    out2_complex_bf1_t <= (~(out2_real_bf1)) + 1;
  end else
    out2_real_bf1_t    <= out2_real_bf1;
 
 
  out2_complex_bf1_t <= out2_complex_bf1;  
 
end



So the simulation is showing exactly what you wrote, assign out2_complex_bf1 to that ..._t version on every clock after the count goes over 8 as you replace the first assignment is overwritten.

BTW use the @* instead of writing out all the signals, less likely to make a mistake and end up with simulation synthesis mismatches.
 

Is the missing begin a typo? As written above you have the following code:


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
always @(count,out2_complex_bf1,out2_real_bf1) begin
 
  if (count >= 4'b1000) begin
    out2_real_bf1_t    <= out2_complex_bf1;
    out2_complex_bf1_t <= (~(out2_real_bf1)) + 1;
  end else
    out2_real_bf1_t    <= out2_real_bf1;
 
 
  out2_complex_bf1_t <= out2_complex_bf1;  
 
end



So the simulation is showing exactly what you wrote, assign out2_complex_bf1 to that ..._t version on every clock after the count goes over 8 as you replace the first assignment is overwritten.

BTW use the @* instead of writing out all the signals, less likely to make a mistake and end up with simulation synthesis mismatches.


I understood the error, there was a missing end .. statement. Not sure why it didn't raise an error

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
always @(count,out2_complex_bf1,out2_real_bf1) begin
 
  if (count >= 4'b1000) begin
    out2_real_bf1_t    <= out2_complex_bf1;
    out2_complex_bf1_t <= (~(out2_real_bf1)) + 1;
  end else begin
    out2_real_bf1_t    <= out2_real_bf1;
    out2_complex_bf1_t <= out2_complex_bf1;  
  end
end

 
Last edited:

It isn't an error, notice ads_ee's post that has the correct indentation.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top