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

2024-05-02 06:12

本文主要是介绍使用FPGA实现串-并型乘法器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

介绍

其实我们知道,用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,对应十进制数相乘,结果是正确的。


结语

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

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

这篇关于使用FPGA实现串-并型乘法器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/953550

相关文章

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

python使用库爬取m3u8文件的示例

《python使用库爬取m3u8文件的示例》本文主要介绍了python使用库爬取m3u8文件的示例,可以使用requests、m3u8、ffmpeg等库,实现获取、解析、下载视频片段并合并等步骤,具有... 目录一、准备工作二、获取m3u8文件内容三、解析m3u8文件四、下载视频片段五、合并视频片段六、错误

Python中提取文件名扩展名的多种方法实现

《Python中提取文件名扩展名的多种方法实现》在Python编程中,经常会遇到需要从文件名中提取扩展名的场景,Python提供了多种方法来实现这一功能,不同方法适用于不同的场景和需求,包括os.pa... 目录技术背景实现步骤方法一:使用os.path.splitext方法二:使用pathlib模块方法三

CSS实现元素撑满剩余空间的五种方法

《CSS实现元素撑满剩余空间的五种方法》在日常开发中,我们经常需要让某个元素占据容器的剩余空间,本文将介绍5种不同的方法来实现这个需求,并分析各种方法的优缺点,感兴趣的朋友一起看看吧... css实现元素撑满剩余空间的5种方法 在日常开发中,我们经常需要让某个元素占据容器的剩余空间。这是一个常见的布局需求

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4