Division with a Basys2 - Page 1
Forum section: electronics / general

author: Fantasma25
author_rank: Regular Contributor
timestamp: October 25, 2013, 02:43:07 pm
content: Hello. I'm trying to make a 4 bit calculator with a Basys2, but I'm having problems with the division. I've converted the input form std_logic_vector to unsigned, and I'm using the "ieee.std_logic_1164" and "ieee.numeric_std". In the simulation (with the student edition of Active HDL) it works beautifully, but when I want to sinthesize the code with the Xilinx ISE, it gives me this error refering to the line where I have the division.Operator <INVALID OPERATOR> must have constant operands or first operand must be power of 2Does anyone has ever had any problems with this?

author: tszaboo
author_rank: Super Contributor
timestamp: October 25, 2013, 02:56:43 pm
content: Makes total sense. You are trying to force an Integer logic block to make "floating point". If it is really 4 bit, you can just make the results by a table by calculating them by hand.

author: Crazy Ape
author_rank: Regular Contributor
timestamp: October 25, 2013, 07:07:57 pm
content: Why not set up a counter to count the number of times you can subtract the divisor from the dividend.If after subtraction the dividend is less than the divisor, your result is in the counter, the remainder being what's left of the dividend after all the subtractions.

author: mrflibble
author_rank: Super Contributor
timestamp: October 25, 2013, 07:16:42 pm
content: Quote from: Fantasma25 on October 25, 2013, 02:43:07 pmThe/division operator is not synthesizable. So yes it simulates fine, and no you cannot synthesize it. Best bet is either use a LUT, or use some IP / core from your favorite vendor.Edit:since you want only 4 bits, LUT (lookup table) seems to be the obvious choice.

author: belasajgo
author_rank: Contributor
timestamp: October 25, 2013, 08:36:05 pm
content: This is exactly the reason why I prefer the Altera boards more than the Xilinx boards... With the Xilinx ISE Design Suite I had the same problem and I had to do a work-around for dividing numbers. With the Altera Quartus II the division with/works just fine. I had the same problem also when I tried to make a function to find out the remainder of a division on the Xilinx software. When I made the same function on the Altera software, it worked fine without work-arounds...

author: tszaboo
author_rank: Super Contributor
timestamp: October 26, 2013, 08:06:59 am
content: Quote from: belasajgo on October 25, 2013, 08:36:05 pmYou have pre-made blocks you can configure and use. I dont see the problem with that. They probably synthesize better.

author: nkavv
author_rank: Newbie
timestamp: November 25, 2013, 04:32:41 pm
content: Quote from: NANDBlog on October 26, 2013, 08:06:59 amVery interesting, it's been some time since I've used Altera tools, my experience was positive (this was around 2005-2006). Mostly (90+%) using Xilinx tools. It seems that Altera has integrated a module generator for division; Xilinx would have you core-generate one I guess and the process would be manual.I don't know if both X and A optimize for constant multiplications or divisions. Does anybody know?There are known algorithms for strength reduction. For instance, I have implemented kdiv for division, it generates generic assembly and optimized C routine for divisions by integer constants. The result is a floored integer.I also have a kmul based on suitable algorithms (Bernstein/Briggs).See here for kdiv:http://sourceforge.net/projects/kdiv/It is licensed under BSD, so it is basically do whatever but attribute!I also have complete support for these stuff in my high-level synthesis tool , HercuLeS (http://www.nkavvadias.com/hercules) but this is another story.Best regardsNikolaos Kavvadiashttp://www.nkavvadias.com