Comments on: How to Divide an Integer by Constant in VHDL https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/ The Easiest Way To Learn VHDL Mon, 11 Oct 2021 20:45:53 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: Eric https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-21330 Mon, 11 Oct 2021 20:45:53 +0000 http://surf-vhdl.com/?p=680#comment-21330 Do you have the similar algorithm that calculates the remainder of the division?

]]>
By: Surf-VHDL https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-16594 Sat, 01 May 2021 10:22:18 +0000 http://surf-vhdl.com/?p=680#comment-16594 In reply to Joe.

if you quantize 17 with 15 bit the result is

435*(32768/17)/32768=
(435*1927)/32768 = 838245/32768 = 25 (this division is a simply 15 bit right shift)

NOTE
The right shift is valid ONLY if you are quantizing using a power of two

]]>
By: Joe https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-16017 Thu, 25 Mar 2021 19:05:55 +0000 http://surf-vhdl.com/?p=680#comment-16017 Very good post and general content, thanks for sharing!

One question, given the above code (truncate one) if we divide like in the example 435/17 we’ve got:

constant const_val : unsigned(14 downto 0) := to_unsigned(17,15);

signal val_in : unsigned( 11 downto 0);
signal valIn_x_const_val : unsigned(36 downto 0);
signal val_out : unsigned( 11 downto 0);
begin
valIn_x_const_val <= val_in * const_val;
— right shift by 15
val_out <= valIn_x_const_val(36 downto 21);
end;

If val_in will be 435 then the val_out result will be 0.

What I'm doing wrong?

]]>
By: Dante https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-15759 Fri, 12 Mar 2021 10:37:14 +0000 http://surf-vhdl.com/?p=680#comment-15759 In reply to Ln.

I had the same doubt in first instance, but if you look at the code, the division is not implement IN the code. Instead, it’s assigned to the constant “const_val” directly: to_unsigned(1927,15).
Hope it clarifies a little bit.

]]>
By: Surf-VHDL https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-13960 Fri, 27 Nov 2020 21:53:35 +0000 http://surf-vhdl.com/?p=680#comment-13960 In reply to jjhelef.

thank you,
take a look here:
https://surf-vhdl.com/how-to-implement-division-in-vhdl/

]]>
By: jjhelef https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-13356 Wed, 21 Oct 2020 14:08:03 +0000 http://surf-vhdl.com/?p=680#comment-13356 Great Post! How to divide a constant with an integer?

]]>
By: Surf-VHDL https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-12761 Sat, 29 Aug 2020 20:39:49 +0000 http://surf-vhdl.com/?p=680#comment-12761 In reply to Ln.

32.768 = 2^15
this means that you are performing a quantization of 1/17 using 15 bits.
the last division by 32.768 is performed by a right shift of 15 bit

]]>
By: Surf-VHDL https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-12758 Sat, 29 Aug 2020 20:06:04 +0000 http://surf-vhdl.com/?p=680#comment-12758 In reply to Saif.

because in this post I quantized the number using 15 bit.
If you need to quantize at 8 bit you shall use 2^8=256

]]>
By: Saif https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-12279 Sun, 21 Jun 2020 16:53:11 +0000 http://surf-vhdl.com/?p=680#comment-12279 Thank you for this post. I was wondering how you picked the number 32.768 (2^15) to quantize the divider? Shall one test many nr until you reach a suitable one or there is a way to pick a specific number?

]]>
By: Ln https://surf-vhdl.com/how-to-divide-an-integer-by-constant-in-vhdl/#comment-12194 Thu, 11 Jun 2020 03:04:08 +0000 http://surf-vhdl.com/?p=680#comment-12194 To avoid divider to calculate 435/17,
I understand we are doing 435 * (32.768/17) / 32.768 = 435 * 1.927 / 32.768

We still got to divide 32.768/17. How is this done without divider?
I see I am missing some basic concept here.
Please clarify.

Thanks
Ln

]]>