FPGA Math - Add, Subtract, Multiply, Divide - Signed vs. Unsigned

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ส.ค. 2024

ความคิดเห็น • 51

  • @jefftheusch3071
    @jefftheusch3071 6 ปีที่แล้ว +22

    To divide by a number other than 2, you can multiply by its reciprocal to an arbitrary precision. For example, to divide by 3, you can multiply by 21845, then shift the result right by 16 bits, which divides by 65536. 21845/65536 is about 1/3. For a more precise result, use more bits!

    • @Nandland
      @Nandland  6 ปีที่แล้ว +9

      Jeff, excellent point! I did neglect to talk about this trick. Darnit!

    • @jefftheusch3071
      @jefftheusch3071 6 ปีที่แล้ว +2

      nandland no worries! Hope it's helpful to someone. Thanks for the videos!

    • @jefftheusch3071
      @jefftheusch3071 3 ปีที่แล้ว +2

      @gautha pandith A binary multiply can be represented as a series of shifts and additions. Take for example 6 * 10, which in unsigned binary is 110b * 1010b. The multiplicand (6) is shifted based on the position of each 1 bit in the multiplier (10), and all of the shifted values are added together to get the result... (6

    • @TatharNuar
      @TatharNuar ปีที่แล้ว

      I need to do this to apply a low-pass filter on an image, and Vivado is complaining about a DSP not being pipelined. I don't know what that means.

  • @Ganjin88
    @Ganjin88 5 ปีที่แล้ว +4

    Appreciate the elaboration. When I took a digital design course in college, my professor didn't explain the SIgned and Unsigned stuff properly. Then again, I wasn't aware of FPGAs until my last semester in college. smh.

  • @Anikung17
    @Anikung17 4 ปีที่แล้ว +3

    In the beginning, isn't what was explained as the two's compliment of 1 actually -1.
    This is going by another simple way to explain 2's compliment, which is to say that every bit is the weight of a power of 2, except for the most significant bit, which has a weight of the NEGATIVE of its respective power of 2.

  • @Factory400
    @Factory400 6 ปีที่แล้ว

    You learn to add in 1st grade....many start in Kindergarten.
    I just ordered the Go Board - look forward to the lessons. Already watched most of the videos!

    • @Nandland
      @Nandland  6 ปีที่แล้ว

      Thanks for ordering! Glad you found the information useful!

  • @MilanKarakas
    @MilanKarakas 5 ปีที่แล้ว +1

    Excellent explanation. I just wondered how to divide with anything that 2,4,8 and so on. You gave me the coolest answer I ever heard - complicated. That is so true. Thanks.
    EDIT: Typo: should be ...anything than 2,4,8... that makes sentence different.

    • @vk2ig
      @vk2ig 5 ปีที่แล้ว

      In general:
      ÷M = shift right by N bits, where M = 2^N.
      E.g. ÷4 = shift right by 2 bits, ÷8 = shift right by 3 bits, etc.
      To multiply by the same factors, just shift left by the required number of bits instead.

    • @MilanKarakas
      @MilanKarakas 5 ปีที่แล้ว

      @@vk2ig Thanks. Okay, I made typo in my question. Should be: How to divide with anything than 2, 4, 8 and so on. This means dividing by 3, 5, 7 ...

    • @vk2ig
      @vk2ig 5 ปีที่แล้ว +1

      @@MilanKarakas OK, understood. I have used the "shift left and subtract" algorithm to divide by non-integer powers of 2, but not on FPGAs.

    • @MilanKarakas
      @MilanKarakas 5 ปีที่แล้ว

      @@vk2ig Thanks. I will figure out something. Just having pollen allergy... unable to do anything smart.

  • @sythrusrl1736
    @sythrusrl1736 3 ปีที่แล้ว

    Awesome video! Definitely learned a lot from this, thank you.

  • @siyavashadib9067
    @siyavashadib9067 6 ปีที่แล้ว

    Hey Dear Russel ,
    I'm one of the many people who used your tutorials on the GoBoard to learn a few things and take the first steps into the FPGA world .
    First I wanted to thank u for all the great help and guidance that actually helped me get my first Job related to FPGA development .
    I've been working on a more complex development board for myself with some more components like HDMI , MicroController and . . .
    But I can't figure out how to make a programmer on board using the FTDI chip like u did on the GoBoard in a way i can use it both for Serial interface and Programming the FPGA .
    I Would really appreciate it if u could give me a hand on this since I have almost no idea how to make one .
    Best Regards

    • @Nandland
      @Nandland  6 ปีที่แล้ว

      Some FPGA boards just work with the FTDI chip, some don't. It depends on the FPGA. I'm not sure which ones do or do not work. The Go Board schematic is on this page: www.nandland.com/goboard/index.html Hope that helps. Good luck!

    • @siyavashadib9067
      @siyavashadib9067 6 ปีที่แล้ว

      Thanks a lot , I've been searching about the FTDI's FT2232 and how to use it for this purpose but i can't figure out how to configure the EEPROM for the FTDI to enter the JTAG HS2 mode to program the FPGA . I Saw some Xilinx FPGA boards using this as well .
      Can u share the code of the EEPROM for the FTDI on the GoBoard ?

    • @Nandland
      @Nandland  6 ปีที่แล้ว

      For the Go Board I didn't have to do anything to the EEPROM. The Lattice toolchain is able to make it work. Sorry.

    • @siyavashadib9067
      @siyavashadib9067 6 ปีที่แล้ว

      Ah , alright . Thanks a lot for ur response . if u happened to know anything about how to make the FTDI chip to act as a JTAG HS2 let me know please .
      Best Regards

  • @ikefir
    @ikefir 7 ปีที่แล้ว +2

    Thanks for your work, man! Keep it up! Really keeps me motivated to spend my free time tinkering with FPGAs. By the way do you plan on covering fixed point arithmetic on an FPGA?

    • @Nandland
      @Nandland  7 ปีที่แล้ว +1

      Yes. Originally I planned to do it in this video, but it was already too long.

    • @ikefir
      @ikefir 7 ปีที่แล้ว

      nandland great! Will be waiting for that one. Also I would be happy to see a video on how to _properly_ organize a device configuration (i2c sensor for example, a common case with dev boards) without any kind of system on chip.

    • @Nandland
      @Nandland  7 ปีที่แล้ว

      Thanks for the suggestion, I'll add it to the list!

  • @alinparcalab7269
    @alinparcalab7269 6 ปีที่แล้ว +1

    Hello, awesome video honestly, can you make a video with Time to digital convertor explained and ring oscillator explained

  • @chrishadjipetris6059
    @chrishadjipetris6059 ปีที่แล้ว

    I'd like to know what happens when you assign an output as X in a case for don't care values

  • @riddhipadariya7517
    @riddhipadariya7517 6 ปีที่แล้ว

    Very well explained! Thanks alot.

  • @mateuszkaleta6669
    @mateuszkaleta6669 6 ปีที่แล้ว

    Great video, helped me a lot!

  • @PersonalXZ
    @PersonalXZ 4 ปีที่แล้ว

    Division is simple. division is subtraction with right shift divisor: 135/10=13 (%=5) -->> 135-("0"*'160')-("1"*'80')-("1"*'40')-("0"*'20')-("1"*'10') -->> Result="01101b"=13 Remainder=5

    • @TEAbouda
      @TEAbouda 3 ปีที่แล้ว

      Can you explain that more please?

    • @PersonalXZ
      @PersonalXZ 3 ปีที่แล้ว

      @@TEAbouda if 135>=(10 x 2e4) then multiplier is 1 else multiplier is 0
      2e4 = 16
      10 x 16 = 160
      is not 135>=160 then multiplier is 0
      (multiplier x 160) = (0 x 160) = 0
      135 - (0 x 160) = 135
      2e3 = 8
      10 x 8 = 80
      is 135>=80 then multiplier is 1
      135 - (1 x 80) = 55
      2e2 = 4
      10 x 4 = 40
      is 55>=40 then multiplier is 1
      55 - (1 x 40) = 15
      2e1 = 2
      10 x 2 = 20
      is not 15>=20 then multiplier is 0
      (multiplier x 20) = (0 x 20) = 0
      15 - (0 x 20) = 15
      2e0 = 1
      10 x 1 = 10
      is 15>=10 then multiplier is 1
      15 - (1 x 10) = 5 = remainder
      binary number 01101 is decimal 13

  • @balamurugans780
    @balamurugans780 3 ปีที่แล้ว

    How to perform fixed-point addition in verilog?

  • @keyboard_toucher
    @keyboard_toucher 5 ปีที่แล้ว

    Speaking of integer division, it is slow on CPUs as well. When the divisor is known at design time, what compilers tend to do instead of dividing is a trick involving shifting, multiplying by some constant and then shifting again. The constant and shift amounts can be chosen in such a way as to get the same result as if division had been performed. Does anyone do this on FPGAs?

  • @tomzhu8719
    @tomzhu8719 4 ปีที่แล้ว

    Veeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrry nice video for VHDL,thanks ,man。

  • @bennguyen1313
    @bennguyen1313 4 ปีที่แล้ว

    Regarding how one should use the verilog 'signed' and 'unsigned' keyword whenever comparing or doing math operations for synthesis (not simulation).. does the sign get extended automatically or does one need to do it manually? For example, would :
    reg signed [7:0] var;
    var

    • @bennguyen1313
      @bennguyen1313 4 ปีที่แล้ว

      Any idea why the last comparison fails? www.edaplayground.com/x/5g99

  • @shivsrikakolum2100
    @shivsrikakolum2100 2 ปีที่แล้ว

    after addding 1 how did it go to 1010?

  • @nivethasukumar384
    @nivethasukumar384 6 ปีที่แล้ว

    Hi! Thanks for your work! How to implement multiplication on FPGA when there is an arbitrary number of inputs? Is there a way to do so?

  • @scottwindham9824
    @scottwindham9824 6 ปีที่แล้ว

    Is your Go Board still available for purchase? I am unable to reach the sales page.. Thanks!

  • @Thjr13enGhost
    @Thjr13enGhost 7 ปีที่แล้ว

    I have a question: typically when multiplying, the result will have a width equals to the total sum of the width of both factors. However i think that in signed multiplication it always end up with 1 extra bit which is the extended sign bit. Can we trunkcate this so the result could get better resource utilization?

    • @Nandland
      @Nandland  7 ปีที่แล้ว

      Sure if you really need the extra space. I usually don't bother.

    • @NoahFect
      @NoahFect 6 ปีที่แล้ว

      You'll need to keep the "second sign bit" of the product only if you need to support multiplication of the largest negative value with the largest negative value.
      E.g., for 16-bit values, try to keep your data in the range [-32767,32767] instead of the maximum available range [-32768,32767]. The resource savings can be substantial.

  • @lekharane5344
    @lekharane5344 3 ปีที่แล้ว

    Is there is way to solve polynomial functions using Verilog on a FPGA?

    • @NoSpeechForTheDumb
      @NoSpeechForTheDumb ปีที่แล้ว

      Not in a symbolic way, and not with an arbitrary accuracy. An FPGA can do fast parallel integer operations at some user-defined accuracy, so you could just sweep the whole number area in a for loop and check if the current number is an approximate solution, but that's not an appropriate task for an FPGA.

  • @magnuswootton6181
    @magnuswootton6181 3 ปีที่แล้ว

    u dont have to use 2s complement, but i probably will. do it however u wish.

  • @David_94
    @David_94 5 ปีที่แล้ว

    But all that is like high level VHDL, what happents in real life? Behind the plus sign vhdl creates all the full adders or what?

    • @Nandland
      @Nandland  5 ปีที่แล้ว

      Are you asking how the synthesis tool works? I'm sure you could read about different approaches to adding, multiplying etc in research papers and stuff. The actual implementation of the math is less important to me.

  • @kedharguhan
    @kedharguhan 2 ปีที่แล้ว

    I dont think I have ever seen such a small whiteboard lol

  • @russianultraviolet4441
    @russianultraviolet4441 ปีที่แล้ว

    Hi, I've had a signed number problem alot lately. Sometimes either the compiler or (?) flips my number assignment, that is, for example, I declare a number as a signed number, but it treats it as an unsigned number, and vise versa. This problem comes and goes, so it's some sort of instability, but I can't seem to put a finger on it, and don't know how to fix it. Any encounter this before? Any help would be appreciated!

  • @Nicknamelikeyours
    @Nicknamelikeyours 6 ปีที่แล้ว

    Why do you depend to continue making videos on the sales number of your board? Don't you have fun doing these videos in your free time to educate your viewers?