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

devtools/2024/10/18 18:23:54/

介绍

其实我们知道,用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/devtools/27823.html

相关文章

用户中心(终)

文章目录 Ant Design Pro&#xff08;Umi 框架&#xff09;ProComponents 高级表单待优化点 todo注册逻辑增加注册页面页面重定向问题注册页面 **获取用户的登录态****前端用户管理功能** Ant Design Pro&#xff08;Umi 框架&#xff09; app.tsx 项目全局入口文件&#xff0c…

第49期|GPTSecurity周报

GPTSecurity是一个涵盖了前沿学术研究和实践经验分享的社区&#xff0c;集成了生成预训练Transformer&#xff08;GPT&#xff09;、人工智能生成内容&#xff08;AIGC&#xff09;以及大语言模型&#xff08;LLM&#xff09;等安全领域应用的知识。在这里&#xff0c;您可以找…

PySpark学习---销售情况数据统计分析案例

需求分析&#xff1a; 某公司是做零售相关业务&#xff0c;旗下出品各类收银机. 目前公司的收银机已经在全国铺开,在各个省份均有店铺使用.机器是联网的,每一次使用都会将售卖商品数据上传到公司后台.老板现在想对省份维度的销售情况进行统计分析 逻辑需求&#xff1a; 1.各省销…

模型智能体开发之metagpt-多智能体实践

参考&#xff1a; metagpt环境配置参考模型智能体开发之metagpt-单智能体实践 需求分析 之前有过单智能体的测试case&#xff0c;但是现实生活场景是很复杂的&#xff0c;所以单智能体远远不能满足我们的诉求&#xff0c;所以仍然还需要了解多智能体的实现。通过多个role对动…

笨蛋学C++之 C++连接数据库

笨蛋学C 之 VS2019使用C连接数据库 创建数据库SQL语句VS2019选择空项目&#xff0c;点击下一步创建输入项目名称&#xff0c;点击创建创建成功点击新建项创建源文件因为mysql是64位&#xff0c;此时的c项目是86位&#xff0c;所以这里需要将项目修改为x64位点击项目 -> 0501…

Web开发基础概念

Python的Web开发是指使用Python语言来开发Web应用程序&#xff0c;如网站、网络应用程序等。在Python的Web开发中&#xff0c;有一些核心概念和技术栈需要了解。本文将介绍Python的Web开发框架和技术栈&#xff0c;并提供一些相关的资源供参考。一、Python的Web开发框架Python的…

MATLAB 函数

MATLAB 函数 函数是一起执行任务的一组语句。在MATLAB中&#xff0c;函数是在单独的文件中定义的。文件名和函数名应该相同。 函数在其自己的工作空间&#xff08;也称为本地工作空间&#xff09;中对变量进行操作&#xff0c;与在MATLAB命令提示符下访问的工作空间&#xff0…

mac如何打开exe文件?如何mac运行exe文件 如何在Mac上打开/修复/恢复DMG文件

在macOS系统中&#xff0c;无法直接运行Windows系统中的.exe文件&#xff0c;因为macOS和Windows使用的是不同的操作系统。然而&#xff0c;有时我们仍然需要运行.exe文件&#xff0c;比如某些软件只有Windows版本&#xff0c;或者我们需要在macOS系统中运行Windows程序。 虽然…