While loop problems

Joined
Mar 30, 2009
Messages
1
Reaction score
0
Problem: The Altera compiler thinks that it will take more than 10k iterations to complete this segment of code. I am not seeing how it would take more than a maximum of 36... I have not been coding in vhdl for all that long so I will more than accept any answer that should be obvious.


Code description: This should take an integer in the range of 0 to 9999 and separate the digits into their bcd compatible segments...

Code:
doConv:	process (big_dec)
	variable temp,tOne,tTen,tHun,tTho: integer := 0;
	begin
		if(big_dec > 9999) then
			temp := 9999;
		else
			temp := big_dec;
		end if;
		
		while temp >= 1000 loop
			temp := temp - 1000;
			tTho := tTho + 1;
		end loop;
		
		while temp >= 100 loop
			temp := temp - 100;
			tHun := tHun + 1;
		end loop;
		
		while temp >= 10 loop
			temp := temp - 10;
			tTen := tTen + 1;
		end loop;
		
		while temp >= 1 loop
			temp := temp - 1;
			tOne := tOne + 1;
		end loop;
		
		ones <= tOne;
		tens <= tTen;
		hund <= tHun;
		thou <= tTho;
	end process;
 
Joined
Dec 9, 2008
Messages
88
Reaction score
0
You have the knowledge that after the first while loop that temp will be less than 1000, and after the second while loop temp will be less than 100. I expect Altera isn't that smart so it is setting itself up to deal with a very large number on the last while loop (what is your integer definition -16 bit, 32 bit?).

One solution might be to assign an eight bit variable that you set equal to temp after the second while loop. Then use that variable for the following while loops.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,294
Latest member
LandonPigo

Latest Threads

Top