使用FPGA实现串-并型乘法器

server/2024/10/19 15:24:40/

介绍

其实我们知道,用FPGA实现乘法器并不是一件很简单的事,而且在FPGA中也有乘法器的IP核可以直接调用,我这里完全就是为了熟悉一些FPGA的语法然后写了这样一个电路。


串-并型乘法器模块

从字面上看,串-并乘法器就是其中一个乘数是串行的,另一位乘数是并行的。我在这里只描述一下模块的输入输出端口,相比于并行乘法器,串-并型乘法器占用的资源更少。

在这里,a是串行的数据,b是并行的4位数据,output也是串行的数据。


设计文件

这里我把基础的与门,D触发器和乘法器都给省略掉了。


--pipe元件

library ieee;
use ieee.std_logic_1164.all;
use work.my_component.all;
entity pipe is
    port( a,b,clk,rst : in std_logic;
            d_reg_out : out std_logic);
end entity;
architecture behavior of pipe is
    signal f_add_outc,cin,f_add_outs : std_logic;
begin 
    u1 : component f_add
    port map(a,b,cin,f_add_outs,f_add_outc);
    u2 : component d_reg
    port map(f_add_outc,clk,rst,cin);
    u3 : component d_reg 
    port map(f_add_outs,clk,rst,d_reg_out);
end architecture;


--packeg声明元件

library ieee;
use ieee.std_logic_1164.all;
package my_component is
------------------------------------
component and_2 is
    port( a,b : in std_logic;
            and_2_out: out std_logic);
end component;
------------------------------------
component d_reg is
    port( d_reg_in,clk,rst : in std_logic;
            d_reg_out : out std_logic);
end component;
------------------------------------
component f_add is
    port (a,b,cin : in std_logic;
            f_add_outs,f_add_outc : out std_logic);
end component;
------------------------------------
component pipe is
    port( a,b,clk,rst : in std_logic;
            d_reg_out : out std_logic);
end component;
end package;


顶层文件

library ieee;
use ieee.std_logic_1164.all;
use work.my_component.all;
entity multiplier is
    port( a,rst,clk : in std_logic;
            b : in std_logic_vector(3 downto 0);
            output : out std_logic);
end entity;
architecture behavior of multiplier is
    signal and_out,reg_out : std_logic_vector(3 downto 0);
begin
    u1: component and_2 port map(a,b(3),and_out(3));
    u2: component and_2 port map(a,b(2),and_out(2));
    u3: component and_2 port map(a,b(1),and_out(1));
    u4: component and_2 port map(a,b(0),and_out(0));
    u5: component d_reg port map(and_out(3),clk,rst,reg_out(3));
    u6: component pipe port map(and_out(2),reg_out(3),clk,rst,reg_out(2));
    u7: component pipe port map(and_out(1),reg_out(2),clk,rst,reg_out(1));
    u8: component pipe port map(and_out(0),reg_out(1),clk,rst,reg_out(0));
    output <= reg_out(0);
end behavior;


测试文件

在测试文件中,我只对顶层文件进行了测试,有兴趣的小伙伴可以对各个信号进行仿真验证。

library ieee;
use ieee.std_logic_1164.all;
use work.my_component.all;
entity tb_multiplier is
    
end entity;
architecture behavior of tb_multiplier is
    component multiplier is
        port( a,rst,clk : in std_logic;
                b : in std_logic_vector(3 downto 0);
                output : out std_logic);
    end component;
    signal a,rst,clk : std_logic := '0';
    signal output : std_logic := '1'; 
    signal b : std_logic_vector(3 downto 0);
begin
    dut : multiplier
    port map(a,rst,clk,b,output);
    process
    begin
        clk <= '1';
        wait for 10ns;
        clk <= '0';
        wait for 10ns;
    end process;
    process
    begin
        a <= '0';
        b <= "1101";
        wait for 40ns;
        a <= '1';
        wait for 40ns;
        a <= '0';
        wait for 80ns;
    end process;
end architecture;


仿真结果

在仿真测试中,我们把a看作是4位串行的数据,我们看黄线中间的8位数据,a是0011,后面紧跟4个0,b是1101,输出结果是10011100,对应十进制数相乘,结果是正确的。


结语

确实是不太好写的,对于这种比较复杂的电路,一定要去建立一个一个的元件,然后将各个元件进行连接,这样会容易很多。

更完整的代码在相关的压缩包,有问题大家留言。


http://www.ppmy.cn/server/28626.html

相关文章

unity制作app(1)--登录 注册 界面

把学到的知识投入到生产中反而是一件简单的事情&#xff01; 1.调整canvas的形状&#xff0c;这里和camera没有任何关系! overlay&#xff01; 2.既然自适应&#xff0c;空间按钮的位置比例就很重要了&#xff01; game窗口中新增720*1280的分辨率&#xff01; 3.再回到can…

fdfs安装启动及性能优化

fsatDFS安装 1、使用 wget 命令下载压缩包&#xff0c;如果没有 wget 命令使用 yum 命令安装 yum install wget 2、下载 fastdfs wget -c “https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz” 3、下载 libfastcommon wget -c “https://github.com/happyfish10…

Android 文件传输

目录 device explorer 文件目录关系对应&#xff1a; device explorer 经常写adb命令传文件&#xff0c;结果发现Android studio有自带的文件管理器&#xff0c;可以上传下载文件。 tool windows ->device explorer 文件目录关系对应&#xff1a; Android java获取的程序…

操作系统安全:安全审计,Windows系统日志详解,Windows事件ID汇总

「作者简介」&#xff1a;2022年北京冬奥会网络安全中国代表队&#xff0c;CSDN Top100&#xff0c;就职奇安信多年&#xff0c;以实战工作为基础对安全知识体系进行总结与归纳&#xff0c;著作适用于快速入门的 《网络安全自学教程》&#xff0c;内容涵盖系统安全、信息收集等…

【机器学习与流体力学交叉领域的期刊】

当涉及到机器学习与流体力学交叉领域的期刊时&#xff0c;以下是一些建议的期刊&#xff0c;这些期刊涵盖了机器学习和流体力学领域的最新研究和发展&#xff1a; Journal of Fluid Mechanics&#xff1a;这是流体力学领域的顶级期刊&#xff0c;虽然主要关注流体力学的理论、…

Python selenium

1.搭建环境 1.安装&#xff1a; pip install msedge-selenium-tools 不要使用pip install selenium&#xff0c;我的电脑上没法运行 2.下载驱动 Microsoft Edge WebDriver |Microsoft Edge 开发人员 edge浏览器点设置---关于即可找到版本号&#xff0c;一定要下载对应版…

詳細瞭解Nginx反向代理與正向代理的區別

正向代理與反向代理是在網路架構中常見的兩種代理模式&#xff0c;它們在Nginx中都有廣泛的應用。下麵我們詳細討論一下它們的區別&#xff1a; 代理對象的區別&#xff1a; 正向代理&#xff08;Forward Proxy&#xff09;&#xff1a;在正向代理模式下&#xff0c;客戶端知…

Linux CPU 飙升 排查五步法

排查思路-五步法 1. top命令定位应用进程pid 找到最耗时的CPU的进程pid top2. top-Hp[pid]定位应用进程对应的线程tid 找到最消耗CPU的线程ID // 执行 top -Hp [pid] 定位应用进程对应的线程 tid // 按shift p 组合键&#xff0c;按照CPU占用率排序 > top -Hp 111683.…