基于fpga的乘法器和除法器_第1頁
基于fpga的乘法器和除法器_第2頁
基于fpga的乘法器和除法器_第3頁
基于fpga的乘法器和除法器_第4頁
基于fpga的乘法器和除法器_第5頁
已閱讀5頁,還剩7頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

任務(wù)書:1、 十六位硬件乘法器電路2、 八位硬件除法器電路摘要:設(shè)計一個16位硬件乘法器電路。要求2位十進(jìn)制乘法,能用LED數(shù)碼管同時顯示乘數(shù),被乘數(shù)和積的值.本設(shè)計利用Quartus II軟件為設(shè)計平臺,通過移位相加的乘法原理:即從被乘數(shù)的最低位開始,若為1,則乘數(shù)左移后與上一次的和相加;若為0,左移后以全零相加,直至被乘數(shù)的最高位。經(jīng)軟件仿真和硬件測試驗證后,以達(dá)到實驗要求。設(shè)計一個8位硬件除法器電路。要求2位十進(jìn)制除法,能用LED數(shù)碼管顯示結(jié)果、除數(shù)和被除數(shù)的值。根據(jù)被除數(shù)(余數(shù))和除數(shù)的大小來上商,被除數(shù)低位補(bǔ)零,再減去右移后的除數(shù)也可以改為左移余數(shù),減去除數(shù),這樣可以確保參與運(yùn)算的寄存器具有相同位數(shù)。商寫到寄存器的低位,然后再左移一位。經(jīng)軟件仿真和硬件驗證后,以達(dá)到實驗要求。目錄2.任務(wù)書23.摘要24.目錄35.正文4 5.1.1 乘法器系統(tǒng)設(shè)計4 5.1.1.1 設(shè)計要求4 5.1.2.2系統(tǒng)設(shè)計方案4 5.1.2 單元電路設(shè)計4 十進(jìn)制計算模塊5 BCD碼轉(zhuǎn)二進(jìn)制模塊5 8位右移寄存器模塊6 8位加法器模塊7 1位乘法器multi_1模塊7 16位移位寄存器reg_16模塊8 16位二進(jìn)制轉(zhuǎn)BCD碼B_BCD模塊9 8位乘法器multi_8x8頂層設(shè)計105.1.3 乘法器的系統(tǒng)測試14 仿真分析14 硬件驗證155.2.1 除法器系統(tǒng)設(shè)計5.2.2單元電路設(shè)計5.2.3 除法器的系統(tǒng)設(shè)計 仿真分析 硬件驗證6. 結(jié)論157. 參考文獻(xiàn)158. 分工155.正文題目要求設(shè)計基于fpga的乘法器和除法器。本小組想出的方案是利用位移相加和相減來制作乘法器和除法器。運(yùn)用的模塊主要包括:1、 輸入模塊:運(yùn)用計數(shù)器設(shè)編碼器將bcd碼編譯為二進(jìn)制碼;2、 運(yùn)算模塊:包括運(yùn)算器和寄存器;3、 輸出模塊:將運(yùn)算器運(yùn)算的結(jié)果的二進(jìn)制數(shù)譯碼位bcd碼在數(shù)碼管上顯示出來。其余方法:可以將輸入的二進(jìn)制數(shù)轉(zhuǎn)為十進(jìn)制再進(jìn)行運(yùn)算,此方法適用于人工初學(xué)者計算不適于利用芯片計算,故不考慮。方案先進(jìn)性:簡單易懂,將乘法器和除法器分開制作便于分工。但缺點(diǎn)也顯而易見,乘法器和除法器按照不同人的思維進(jìn)行設(shè)計,不易于整合,變?yōu)閮蓚€獨(dú)立的模塊。方案可行性:易于設(shè)計,但使用不便,需要重新燒入程序?qū)崿F(xiàn)乘除法切換。5.1乘法器系統(tǒng)設(shè)計1.1 設(shè)計要求題目要求設(shè)計一個16位硬件乘法器電路.要求2位十進(jìn)制乘法;能用LED數(shù)碼管同時顯示乘數(shù),被乘數(shù)和積的信息.設(shè)置一個乘法使能端,控制乘法器的計算和輸出.1.2 系統(tǒng)設(shè)計方案此設(shè)計問題可分為乘數(shù)和被乘數(shù)輸入控制模塊,乘法模塊和輸出乘積顯示模塊基本分.乘數(shù)和被乘數(shù)的輸入模塊使輸入的十進(jìn)制數(shù)轉(zhuǎn)化為二進(jìn)制數(shù)輸入乘法模塊,乘法模塊利用移位相加的方法將輸入的兩組二進(jìn)制數(shù)進(jìn)行相乘,并將16位乘積輸出到乘積輸出顯示模塊.顯示模塊將輸入的二進(jìn)制數(shù)按千,百,十,個位分別轉(zhuǎn)化為十進(jìn)制數(shù)輸出.乘數(shù)和被乘數(shù)的輸入可用數(shù)據(jù)開關(guān)K1K10分別代表數(shù)字1,2,9,0,用編碼器對數(shù)據(jù)開關(guān)K1K10的電平信號進(jìn)行編碼后輸入乘法器進(jìn)行計算.但此方案所用硬件資源較多,輸入繁瑣,故不采取.方案二是利用硬件箱自帶16進(jìn)制碼發(fā)生器,由對應(yīng)的鍵控制輸出4位2進(jìn)制構(gòu)成的1位16進(jìn)制碼,數(shù)的范圍是00001111,即0HFH.每按鍵一次,輸出遞增1,輸出進(jìn)入目標(biāo)芯片的4位2進(jìn)制數(shù)將顯示在該鍵對應(yīng)的數(shù)碼管.乘數(shù)和被乘數(shù)的輸入模塊將16進(jìn)制碼的AF碼設(shè)計成輸出為null.使得減少了無用碼的輸入.兩數(shù)相乘的方法很多,可以用移位相加的方法,也可以將乘法器看成計數(shù)器,乘積的初始值為零,每一個時鐘周期將乘數(shù)的值加到積上,同時乘數(shù)減一,這樣反復(fù)執(zhí)行,直到乘數(shù)為零.本設(shè)計利用移位相加的方法使得程序大大簡化.系統(tǒng)總體電路組成原理圖如下圖所示:5.1.2乘法器單元電路設(shè)計下面分解8位乘法器的層次結(jié)構(gòu),分為以下7個模塊:1. 十進(jìn)制計算模塊:使用4個十進(jìn)制計數(shù)模塊,輸入乘數(shù)的十位個位,被乘數(shù)的十位個位。2. BCD碼轉(zhuǎn)二進(jìn)制模塊:實現(xiàn)將輸入的8位BCD碼轉(zhuǎn)化成二進(jìn)制3. 右移寄存器模塊:這是一個8位右移寄存器,可將乘法運(yùn)算中的被乘數(shù)加載于其中,同時 進(jìn)行乘法運(yùn)算的移位操作。 4. 加法器模塊:這是一個8位加法器,進(jìn)行操作數(shù)的加法運(yùn)算。5. 1位乘法器模塊:完成8位與1位的乘法運(yùn)算。6. 鎖存器模塊:這是一個16位鎖存器,同時也是一個右移寄存器,在時鐘信號的控制下完成輸入數(shù)值的鎖存與移位。7. 二進(jìn)制轉(zhuǎn)BCD碼模塊:將16位寄存器的值(積)轉(zhuǎn)化成BCD碼,配合數(shù)碼管顯示十進(jìn)制加計數(shù)器設(shè)計十進(jìn)制計數(shù)器在每個時鐘來臨時計數(shù),clk=1時清零,用于輸入乘數(shù),被乘數(shù)的個位,十位Library ieee; -0到9計數(shù)器Use ieee.std_logic_unsigned.all;Use ieee.std_logic_1164.all;Entity cnt10 isPort (clk,clr: in std_logic; q: out std_logic_vector(3 downto 0);end cnt10;architecture behav of cnt10 isbegin process(clk,clr) variable cqi: std_logic_vector(3 downto 0); begin if clr=1 then cqi:=0000; elsif clkevent and clk=1 then if cqi=9 then cqi:=0000; else cqi:=cqi+1; end if; end if; q=cqi;end process;end behav;BCD碼轉(zhuǎn)二進(jìn)制碼BCD_B的設(shè)計將十進(jìn)制計數(shù)器產(chǎn)生的十位和個位合并后,為BCD碼,而計算時使用二進(jìn)制碼計算,所以采用該模塊來轉(zhuǎn)化Library ieee; -(0到99)BCD碼轉(zhuǎn)二進(jìn)制碼Use ieee.std_logic_unsigned.all;Use ieee.std_logic_1164.all;Entity BCD_B isPort ( a: in std_logic_vector(7 downto 0); q: out std_logic_vector(7 downto 0);end BCD_B;architecture behav of BCD_B is signal a1,a2,a3,a4,cq: std_logic_vector(7 downto 0);begin process(a) begin a1=0000&a(3 downto 0); a2=0000&a(7 downto 4); a3=a2(6 downto 0)&0; a4=a2(4 downto 0)&000; cq=a4+a3+a1; q=cq;end process;end behav;8位移位寄存器reg_8的設(shè)計8位移位寄存器是在時鐘(r8_clkevent and r8_clk=1)信號作用下,當(dāng)r8_load=1時,將8位乘數(shù)加載進(jìn)入;而當(dāng)r8_load=0時,對數(shù)據(jù)進(jìn)行移位操作,同時定義一個信號reg8用來裝載新數(shù)據(jù)及移位后的操作數(shù),完成這些操作后,寄存器的最低位reg8(0)傳送給r8_out輸出。library ieee; -8位移位寄存器use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity reg_8 is port(r8_clk,clr,r8_load:in std_logic; r8_in:in std_logic_vector(7 downto 0); r8_out:out std_logic);end reg_8;architecture arc_reg_8 of reg_8 is signal reg8:std_logic_vector(7 downto 0); begin process(r8_clk,clr,r8_load) begin if clr=1then reg8=; elsif r8_clkevent and r8_clk=1 then if r8_load=1 then reg8=r8_in; else reg8(6 downto 0)=reg8(7 downto 1); end if; end if; end process; r8_out=reg8(0); end arc_reg_8;8位加法器adder_8的設(shè)計該加法器由八位二進(jìn)制加法器組成。其中設(shè)計八位二進(jìn)制加法器時,為了避免加法運(yùn)算時產(chǎn)生溢出,故定義了三個信號量ss,aa,bb,將加數(shù)a8_a,a8_b分別與0連接后賦值給aa,bb,形成9位二進(jìn)制數(shù),然后aa,bb相加賦值給ss,最后將ss的低八位賦值給和a8_s,同時將ss的最高位送給a8_out輸出。library ieee; -8位加法器use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all; entity adder_8 is port(a8_a,a8_b:in std_logic_vector(7 downto 0); a8_s:out std_logic_vector(7 downto 0); a8_out:out std_logic); end adder_8; architecture arc_adder_8 of adder_8 is signal ss:std_logic_vector(8 downto 0); signal aa,bb:std_logic_vector(8 downto 0); begin aa=0&a8_a; bb=0&a8_b; ss=aa+bb; a8_s=ss(7 downto 0); a8_out=ss(8); end arc_adder_8;1位乘法器multi_1的設(shè)計 利用if語句來完成8位二進(jìn)制數(shù)與1位二進(jìn)制的乘法運(yùn)算,最后將結(jié)果送到m1_out輸出。即當(dāng)m1_x為1時,m1_out輸出為m1_y;當(dāng)m1_x為0時,m1_out輸出全為零。 library ieee; -1位乘法器use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity multi_1 is port(m1_x:in std_logic; m1_y:in std_logic_vector(7 downto 0); m1_out:out std_logic_vector(7 downto 0);end multi_1;architecture arc_multi_1 of multi_1 is begin process(m1_x,m1_y) begin if m1_x=1 then m1_out=m1_y; else m1_out=; end if; end process;end arc_multi_1;16位移位寄存器reg_16的設(shè)計當(dāng)清零信號(clr=1)到來時,定義信號變量reg_16歸零;信號(r16_clr=1)到來時,定義信號變量reg16清零;否則在時鐘信號r16_clk上升沿到來時,將reg16的低8位進(jìn)行移位操作,同時將8位的數(shù)據(jù)輸入r16_in鎖存到reg16的高8位,最后賦值給r16_out輸出,cout控制位輸出1。library ieee; - 16位移位寄存器 use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity reg_16 is port(r16_clk,clr,r16_clr:in std_logic; r16_in:in std_logic_vector(8 downto 0); cout:out std_logic; r16_out:out std_logic_vector(15 downto 0);end reg_16;architecture arc_reg_16 of reg_16 is signal reg16:std_logic_vector(15 downto 0); signal i: std_logic_vector(3 downto 0); begin process(r16_clk,r16_clr) begin if clr=1then cout=0;reg16=00000; elsif r16_clr=1 then reg16=00000; cout=0;i=0000; elsif r16_clkevent and r16_clk=1 then if (i=1000) then reg16=reg16;cout=1; else reg16(6 downto 0)=reg16(7 downto 1); reg16(15 downto 7)=r16_in; i=i+1; end if; end if; end process; r16_out=reg16; end arc_reg_16;16位二進(jìn)制轉(zhuǎn)BCD碼B_BCD的設(shè)計當(dāng)reg_16乘積結(jié)束時,cout輸出1,為B_BCD的使能信號,r16_out為B_BCD的輸入信號,隨著時鐘上升沿的到來,開始轉(zhuǎn)化,16個周期后完成16為二進(jìn)制碼到BCD碼的轉(zhuǎn)化,輸出接數(shù)碼管顯示Library ieee; -16位二進(jìn)制轉(zhuǎn)BCD碼(0到9999)Use ieee.std_logic_unsigned.all;Use ieee.std_logic_1164.all;Entity B_BCD isPort ( clk,ena:in std_logic; a: in std_logic_vector(15 downto 0); q: out std_logic_vector(15 downto 0);end B_BCD;architecture behav of B_BCD is begin process(clk,a) variable i: std_logic_vector(4 downto 0); variable in_a,out_a :std_logic_vector(15 downto 0);begin if ena=0then in_a:=a; i:=00000; out_a:=00000; elsif clkevent and clk=1 then if i=10000 then out_a:=out_a; else out_a:=out_a(14 downto 0)&in_a(15); in_a:=in_a(14 downto 0)&0; i:=i+1; if i4 then out_a( 3 downto 0):=out_a( 3 downto 0)+3; end if; if out_a( 7 downto 4)4 then out_a( 7 downto 4):=out_a( 7 downto 4)+3; end if; if out_a(11 downto 8)4 then out_a(11 downto 8):=out_a(11 downto 8)+3; end if; if out_a(15 downto 12)4 then out_a(15 downto 12):=out_a(15 downto 12)+3; end if; end if; end if; end if ; q=out_a;end process; end behav;頂層設(shè)計8位乘法器multi_8x8當(dāng)輸入a,b后,隨著STAR上升沿到來,將乘數(shù)a鎖存到REG_8中,同時將16位的移位寄存器REG_16清零,然后隨著時鐘CLK上升沿的到來,對REG_8中的乘數(shù)進(jìn)行移位操作,最低位在前,由低到高逐位輸出。1位乘法器中進(jìn)行與8位被乘數(shù)的相乘運(yùn)算,并與鎖存在16位寄存器reg_16中的高8位進(jìn)行相加,其和(包含進(jìn)位)在下一個時鐘的上升沿到來時鎖存到16位寄存器中。如此進(jìn)行直到第八個時鐘上升沿到來時,reg_16的輸出即為所求的乘積,此時reg_16輸出端cout輸出高電平,B_BCD使能端有效,隨著時鐘的到來后,開始二進(jìn)制到BCD碼的轉(zhuǎn)化,16個時鐘后轉(zhuǎn)化完成,輸出結(jié)果。由(clr)清零端歸零后,可以進(jìn)行下一次的計算。其頂層程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity multi_8x8 is port(clk,clk_a1,clk_a0,clk_b1,clk_b0,clr,start:in std_logic; out_a1,out_a0,out_b1,out_b0: buffer std_logic_vector(3 downto 0); result: out std_logic_vector(15 downto 0);end multi_8x8;architecture arc_multi_8x8 of multi_8x8 is component cnt10 -調(diào)用0到9計數(shù)器聲明Port (clk,clr: in std_logic; q: out std_logic_vector(3 downto 0);end component;component BCD_B -調(diào)用0到99)BCD碼轉(zhuǎn)二進(jìn)制碼聲明Port ( a: in std_logic_vector(7 downto 0); q: out std_logic_vector(7 downto 0);end component;component B_BCD -調(diào)用16位二進(jìn)制轉(zhuǎn)BCD碼(0到9999)聲明Port ( clk,ena:in std_logic; a: in std_logic_vector(15 downto 0); q: out std_logic_vector(15 downto 0);end component;component multi_1 -調(diào)用1位乘法器聲明port(m1_x:in std_logic; m1_y:in std_logic_vector(7 downto 0); m1_out:out std_logic_vector(7 downto 0);end component;component adder_8 -調(diào)用8位加法器聲明port(a8_a,a8_b:in std_logic_vector(7 downto 0); a8_s:out std_logic_vector(7 downto 0); a8_out:out std_logic);end component;component reg_8 -調(diào)用8位寄存器聲明port(r8_clk,clr,r8_load:in std_logic; r8_in:in std_logic_vector(7 downto 0); r8_out:out std_logic);end component;component reg_16 -調(diào)用16位寄存器聲明port(r16_clk,clr,r16_clr:in std_logic; r16_in:in std_logic_vector(8 downto 0); cout:out std_logic; r16_out:out std_logic_vector(15 downto 0);end component;signal q_a,cout:std_logic; signal andsd,a,b,aa,bb:std_logic_vector(7 downto 0);s

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論