Author Topic: Division with a Basys2  (Read 3153 times)

0 Members and 1 Guest are viewing this topic.

Fantasma25

• Regular Contributor
• Posts: 91
• Country:
Division with a Basys2
« on: October 25, 2013, 02:43:07 pm »
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 2

Does anyone has ever had any problems with this?

NANDBlog

• Super Contributor
• Posts: 4660
• Country:
• Current job: ATEX certified product design
Re: Division with a Basys2
« Reply #1 on: October 25, 2013, 02:56:43 pm »
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.

Crazy Ape

• Regular Contributor
• Posts: 181
Re: Division with a Basys2
« Reply #2 on: October 25, 2013, 07:07:57 pm »
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.

mrflibble

• Super Contributor
• Posts: 2024
• Country:
Re: Division with a Basys2
« Reply #3 on: October 25, 2013, 07:16:42 pm »
Operator <INVALID OPERATOR> must have constant operands or first operand must be power of 2

Does anyone has ever had any problems with this?

The / 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.
« Last Edit: October 25, 2013, 07:25:54 pm by mrflibble »

belasajgo

• Contributor
• Posts: 47
• Country:
Re: Division with a Basys2
« Reply #4 on: October 25, 2013, 08:36:05 pm »
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...

NANDBlog

• Super Contributor
• Posts: 4660
• Country:
• Current job: ATEX certified product design
Re: Division with a Basys2
« Reply #5 on: October 26, 2013, 08:06:59 am »
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...
You have pre-made blocks you can configure and use. I dont see the problem with that. They probably synthesize better.

nkavv

• Contributor
• Posts: 5
Re: Division with a Basys2
« Reply #6 on: November 25, 2013, 04:32:41 pm »
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.

Very 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/

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 regards