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.

divide by two operation in vhdl

Status
Not open for further replies.

symlet

Member level 1
Joined
Oct 12, 2012
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,616
Hai,

First of all, I want to apologize because of my mistake in the previous thread. I hope anyone can help me here. I have write vhdl code for divide by two operation. Below is the short code:
Code:
SRL16_a:process(CLK)  begin                        --  SRL16
		if CLK'event and CLK='1' then 
			if en='1' and (cycle=0 or cycle=2 or cycle=4 or cycle=6) then	 
				sr16<=di & sr16(0 to 14);                  -- shift SRL16		  
			end if;
		end if;
	end process;	 
	a1<= sr16(ad1);                 -- output from SRL16
SM_B:process(clk,rst)
	begin
		if RST = '1' then	  
			di <= (others => '0');		  
			bp <= (others => '0');      
			bm <= (others => '0');
		elsif CLK = '1' and CLK'event then 	 
			if en = '1' then	  				  
				if 	d_signed =0 then
					di<=unsigned(DATA_IN) - unsigned( a1_2);
				else
					di<= DATA_IN;
				end if;	
				add_temp<=SXT(di,9)+a1;
				bp<='0'& add_temp(8 downto 1);
				bm<=SXT(di,9)-a1;
				
			end if;
		end if;
	end process;
I try to add to numbers (di & a1), and then divide the sum by 2. When I simulate the testbench code in ModelSim, the values of add_temp and bm is correct. But, the values of bp is wrong (not as manual calculation). I attach the figure. Anyone please help me. Do I make anything wrong?Thank in advance
 

Attachments

  • wave1.JPG
    wave1.JPG
    296 KB · Views: 89

add_temp, bp and bm are signals that are updated in a clocked process. They are updated at the same time,
so bp will be calculated using the add_temp value from the previous clock cycle.
 

add_temp, bp and bm are signals that are updated in a clocked process. They are updated at the same time,
so bp will be calculated using the add_temp value from the previous clock cycle.

Hai std_match,

Yes you are right. But, from the simulation results it shows that bp value is no right. Correct me if I'm wrong. Thank in advance
 

Attachments

  • wave1.JPG
    wave1.JPG
    296 KB · Views: 95

Move the calculation of bp outside the process completely.

Kevin
 

Move the calculation of bp outside the process completely.

Kevin

Hai Kevin,

I try your suggestion but in simulation the values of bp shows 'X' all times.
 

Hai Kevin,

I try your suggestion but in simulation the values of bp shows 'X' all times.

Then, here are a few hypotheses...
1. Your statement that the values of add_temp and bm is correct must be wrong
2. You copied rather than moved the calculation of bp
3. You didn't move the calculation of bp outside of the process

To verify the above points...
1. Look at add_temp in the waveform window make sure it is still 'correct'
2. Type 'drivers bp' at the Modelsim command prompt and verify that there is only one process driving bp. That driving process should be the concurrent statement that assigns bp. Alternatively, you can add 'bp' to the dataflow window to verify this point.
3. Verify either with the 'drivers' command or the dataflow window that 'bp' and 'add_temp' do NOT come out of the same block of code.

As an aside, if 'bp' happens to be of type std_logic_vector, then try changing it to std_ulogic_vector. Compile and fix any errors that are flagged. If you're still having trouble, I would suggest using a simulator to single step through the code to debug.

Kevin
 

Then, here are a few hypotheses...
1. Your statement that the values of add_temp and bm is correct must be wrong
2. You copied rather than moved the calculation of bp
3. You didn't move the calculation of bp outside of the process

To verify the above points...
1. Look at add_temp in the waveform window make sure it is still 'correct'
2. Type 'drivers bp' at the Modelsim command prompt and verify that there is only one process driving bp. That driving process should be the concurrent statement that assigns bp. Alternatively, you can add 'bp' to the dataflow window to verify this point.
3. Verify either with the 'drivers' command or the dataflow window that 'bp' and 'add_temp' do NOT come out of the same block of code.

As an aside, if 'bp' happens to be of type std_logic_vector, then try changing it to std_ulogic_vector. Compile and fix any errors that are flagged. If you're still having trouble, I would suggest using a simulator to single step through the code to debug.

Kevin

Hai Kevin,

I solve the problem. Thanks for your helps :)
 

I think you owe an explanation to those who took part in the discussion.

The actual problem was expecting a signed divide by 2 (ASR operation ) from the below expression but it's an unsigned divide respectively LSR.
Code:
bp<='0'& add_temp(8 downto 1);

Unfortunately, there are no hints to a signed/unsigned problem except for the simulation display format.
 

I think you owe an explanation to those who took part in the discussion.

The actual problem was expecting a signed divide by 2 (ASR operation ) from the below expression but it's an unsigned divide respectively LSR.
Code:
bp<='0'& add_temp(8 downto 1);

Unfortunately, there are no hints to a signed/unsigned problem except for the simulation display format.

I'm sorry because not explain the solution to others. Btw, thanks to FvM for your explanation and reminder :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top