电子科技大学
UNIVERSITY OF ELECTRONIC SCIENCE AND TECHNOLOGY OF CHINA
数字电路
课程设计报告
课程设计题目 近似加法器
学 号 [1**********]09 作者姓名 宁博宇 指导教师 陈学英 胡剑浩
摘要
算术运算是数字系统的基本功能,更是计算机中不可缺少的组成单元。本次报告介绍加法运算的逻辑电路。半加器, 全加器, 近似加法器, 已经他们的组合构成的串行进位加法器.
关键词:8bit加法器 行波进位加法器 近似加法器
第一章 绪论
1.1 课程设计背景
两个多位数相加时每一位都是带进位相加的,因而必须使用全加器。只要依次将低位的全加器的进位输出端接到高位全加器的进位输入端,就可以构成多位加法器了。串行进位加法器。每一位的相加结果都必须等到低一位的进位产生以后才能建立起来,因此将这种结构的电路称为串行进位加法器(或称为行波进位加法器) 。其最大的特点是运算速度慢。
一、实验内容
1、对近似加法器进行逻辑设计
2、对设计进行matlab 仿真和信噪比分析 3、对设计进行VHDL 仿真 二、实验结果
Matlab 综合设计图
1、总体设计
总体设计的设计图如下:
如图所示, 如图所示, 1、2产生二个高斯随机数,4、5、6、7将高斯随机数的输出转换为bits 的格式,其中7和8是两个不同的加法器。两个加法器都采用3个近似加法器和5个全加器进行8 bit 近似加法器的设计。其中7是不带纠错电路的加法器,而8是带有纠错电路的加法器,它们对相同信号进行处理得到不同的结果。9和10是将二进制的输出转换成为十进制。11和12得到输出。
加法器7的设计图如下
左边3个是近似加法器,右边5个是全加器。
加法器8的设计图如下
上面多了四个纠错电路,是对三个近似加法器的结果进行修正。
其中采用的 近似加法器 为:
其中全加器的实现如下:
纠错电路:
Matlab 仿真结果求信噪比程序: sum0=0;
for i =1:10000
sum0=sum0+(simout0(i)-128)^2; end sum=0;
for i =1:10000
sum=sum+(simout(i)-128)^2; end
d0=sum0/10000;
x0=20*log(128/9)/log(10)-20*log(128/d0)/log(10);
d=sum/10000;
x=20*log(128/9)/log(10)-20*log(128/d)/log(10);
其中x0得到的是通过不含纠错电路的加法器7计算得到的信噪比,x 是得到的是通过含纠错电路的加法器8计算得到的信噪比。
输出结果:
由于近似加法器是为了提升速度对二进制信号做加法时的进位进行近似处理为求得速度的提升,所以其会有计算的偏差,这就是信噪比相对较大的原因。 纠错后效果变差,信噪比变高,分析原因可能是论文中的纠错电路是针对均匀分布的信号,而实验中是高斯分布的信号。 2、VHDL 仿真
总时延是11ns (含纠错电路),效果达到要求。
Summary 如下:
Vhdl 程序: library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM;
--use UNISIM.VComponents.all;
entity app_adders is port(
A,B : in std_logic_vector(7 downto 0); S : out std_logic_vector(7 downto 0)); end app_adders;
architecture Behavioral of app_adders is signal cout: STD_LOGIC_VECTOR(0 to 7); COMPONENT app PORT( a : IN std_logic; b : IN std_logic; cin : IN std_logic; cout : OUT std_logic;
s : OUT std_logic );
END COMPONENT; COMPONENT full PORT( a : IN std_logic; b : IN std_logic; cin : IN std_logic; s : OUT std_logic; cout : OUT std_logic );
END COMPONENT;
begin
FA1: app PORT MAP( a => A(0), b => B(0), cin => '0', cout => cout(0), s => S(0) );
FA2: app PORT MAP( a => A(1), b => B(1), cin => cout(0), cout => cout(1), s => S(1) );
FA3: full PORT MAP( a => A(2), b => B(2), cin => cout(1), s => S(2), cout => cout(2) );
FA4: full PORT MAP( a => A(3), b => B(3), cin => cout(2), s => S(3), cout => cout(3) );
FA5: full PORT MAP( a => A(4),
b => B(4), cin => cout(3), s => S(4), cout => cout(4) );
FA6: full PORT MAP( a => A(5), b => B(5), cin => cout(4), s => S(5), cout => cout(5) );
FA7: full PORT MAP( a => A(6), b => B(6), cin => cout(5), s => S(6), cout => cout(6) );
FA8: full PORT MAP( a => A(7), b => B(7), cin => cout(6), s => S(7), cout => cout(7) );
end Behavioral;
Test behavior 程序代码: LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --USE ieee.numeric_std.ALL;
ENTITY test IS END test;
ARCHITECTURE behavior OF test IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT app_adders PORT(
a : IN std_logic_vector(7 downto 0); b : IN std_logic_vector(7 downto 0); s : OUT std_logic_vector(7 downto 0) );
END COMPONENT;
--Inputs
signal a : std_logic_vector(7 downto 0) := (others => '0'); signal b : std_logic_vector(7 downto 0) := (others => '0'); signal cin : std_logic := '0';
--Outputs
signal s : std_logic_vector(7 downto 0);
-- No clocks detected in port list. Replace below with -- appropriate port name
-- constant _period : time := 10 ns; -- BEGIN -- Instantiate the Unit Under Test (UUT) uut: app_adders PORT MAP ( a => a, b => b, s => s );
-- Clock process definitions -- _process :process -- begin -- _period/2; -- _period/2; -- end process;
-- Stimulus process stim_proc: process
-- hold reset state for 100 ns.
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
wait for 100 ns;
-- wait for _period*10;
-- insert stimulus here
---- wait;
end process;
END;
Matlab 中选取了10000组数据进行计算。
从Matlab 中的前十组数据中提取输入值(二进制),写入test 的vhdl 程序。 通过simulation 仿真得到结果:
将matlab 中workspace 的高斯随机数和加法器7的前十组输出结果x0进行二进制转换。
A 信号:
B 信号:
S 结果:
与simulation 的仿真结果进行比较。
结果一致。
第二章 总结与展望
运用VHDL 和MATLAB 进行程序的设计与编写,在学长与老师的指导下,总的来说进行的较为顺利,可以说这次课程设计主要帮助我熟悉了VHDL 和MATLAB 的相关操作并且帮助我复习巩固了二进制的数字运算以及门电路的相关知识,我希望在未来进行更多的VHDL 设计,加强自己的能力。
电子科技大学
UNIVERSITY OF ELECTRONIC SCIENCE AND TECHNOLOGY OF CHINA
数字电路
课程设计报告
课程设计题目 近似加法器
学 号 [1**********]09 作者姓名 宁博宇 指导教师 陈学英 胡剑浩
摘要
算术运算是数字系统的基本功能,更是计算机中不可缺少的组成单元。本次报告介绍加法运算的逻辑电路。半加器, 全加器, 近似加法器, 已经他们的组合构成的串行进位加法器.
关键词:8bit加法器 行波进位加法器 近似加法器
第一章 绪论
1.1 课程设计背景
两个多位数相加时每一位都是带进位相加的,因而必须使用全加器。只要依次将低位的全加器的进位输出端接到高位全加器的进位输入端,就可以构成多位加法器了。串行进位加法器。每一位的相加结果都必须等到低一位的进位产生以后才能建立起来,因此将这种结构的电路称为串行进位加法器(或称为行波进位加法器) 。其最大的特点是运算速度慢。
一、实验内容
1、对近似加法器进行逻辑设计
2、对设计进行matlab 仿真和信噪比分析 3、对设计进行VHDL 仿真 二、实验结果
Matlab 综合设计图
1、总体设计
总体设计的设计图如下:
如图所示, 如图所示, 1、2产生二个高斯随机数,4、5、6、7将高斯随机数的输出转换为bits 的格式,其中7和8是两个不同的加法器。两个加法器都采用3个近似加法器和5个全加器进行8 bit 近似加法器的设计。其中7是不带纠错电路的加法器,而8是带有纠错电路的加法器,它们对相同信号进行处理得到不同的结果。9和10是将二进制的输出转换成为十进制。11和12得到输出。
加法器7的设计图如下
左边3个是近似加法器,右边5个是全加器。
加法器8的设计图如下
上面多了四个纠错电路,是对三个近似加法器的结果进行修正。
其中采用的 近似加法器 为:
其中全加器的实现如下:
纠错电路:
Matlab 仿真结果求信噪比程序: sum0=0;
for i =1:10000
sum0=sum0+(simout0(i)-128)^2; end sum=0;
for i =1:10000
sum=sum+(simout(i)-128)^2; end
d0=sum0/10000;
x0=20*log(128/9)/log(10)-20*log(128/d0)/log(10);
d=sum/10000;
x=20*log(128/9)/log(10)-20*log(128/d)/log(10);
其中x0得到的是通过不含纠错电路的加法器7计算得到的信噪比,x 是得到的是通过含纠错电路的加法器8计算得到的信噪比。
输出结果:
由于近似加法器是为了提升速度对二进制信号做加法时的进位进行近似处理为求得速度的提升,所以其会有计算的偏差,这就是信噪比相对较大的原因。 纠错后效果变差,信噪比变高,分析原因可能是论文中的纠错电路是针对均匀分布的信号,而实验中是高斯分布的信号。 2、VHDL 仿真
总时延是11ns (含纠错电路),效果达到要求。
Summary 如下:
Vhdl 程序: library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM;
--use UNISIM.VComponents.all;
entity app_adders is port(
A,B : in std_logic_vector(7 downto 0); S : out std_logic_vector(7 downto 0)); end app_adders;
architecture Behavioral of app_adders is signal cout: STD_LOGIC_VECTOR(0 to 7); COMPONENT app PORT( a : IN std_logic; b : IN std_logic; cin : IN std_logic; cout : OUT std_logic;
s : OUT std_logic );
END COMPONENT; COMPONENT full PORT( a : IN std_logic; b : IN std_logic; cin : IN std_logic; s : OUT std_logic; cout : OUT std_logic );
END COMPONENT;
begin
FA1: app PORT MAP( a => A(0), b => B(0), cin => '0', cout => cout(0), s => S(0) );
FA2: app PORT MAP( a => A(1), b => B(1), cin => cout(0), cout => cout(1), s => S(1) );
FA3: full PORT MAP( a => A(2), b => B(2), cin => cout(1), s => S(2), cout => cout(2) );
FA4: full PORT MAP( a => A(3), b => B(3), cin => cout(2), s => S(3), cout => cout(3) );
FA5: full PORT MAP( a => A(4),
b => B(4), cin => cout(3), s => S(4), cout => cout(4) );
FA6: full PORT MAP( a => A(5), b => B(5), cin => cout(4), s => S(5), cout => cout(5) );
FA7: full PORT MAP( a => A(6), b => B(6), cin => cout(5), s => S(6), cout => cout(6) );
FA8: full PORT MAP( a => A(7), b => B(7), cin => cout(6), s => S(7), cout => cout(7) );
end Behavioral;
Test behavior 程序代码: LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --USE ieee.numeric_std.ALL;
ENTITY test IS END test;
ARCHITECTURE behavior OF test IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT app_adders PORT(
a : IN std_logic_vector(7 downto 0); b : IN std_logic_vector(7 downto 0); s : OUT std_logic_vector(7 downto 0) );
END COMPONENT;
--Inputs
signal a : std_logic_vector(7 downto 0) := (others => '0'); signal b : std_logic_vector(7 downto 0) := (others => '0'); signal cin : std_logic := '0';
--Outputs
signal s : std_logic_vector(7 downto 0);
-- No clocks detected in port list. Replace below with -- appropriate port name
-- constant _period : time := 10 ns; -- BEGIN -- Instantiate the Unit Under Test (UUT) uut: app_adders PORT MAP ( a => a, b => b, s => s );
-- Clock process definitions -- _process :process -- begin -- _period/2; -- _period/2; -- end process;
-- Stimulus process stim_proc: process
-- hold reset state for 100 ns.
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
cin
wait for 100 ns;
a
b
wait for 100 ns;
-- wait for _period*10;
-- insert stimulus here
---- wait;
end process;
END;
Matlab 中选取了10000组数据进行计算。
从Matlab 中的前十组数据中提取输入值(二进制),写入test 的vhdl 程序。 通过simulation 仿真得到结果:
将matlab 中workspace 的高斯随机数和加法器7的前十组输出结果x0进行二进制转换。
A 信号:
B 信号:
S 结果:
与simulation 的仿真结果进行比较。
结果一致。
第二章 总结与展望
运用VHDL 和MATLAB 进行程序的设计与编写,在学长与老师的指导下,总的来说进行的较为顺利,可以说这次课程设计主要帮助我熟悉了VHDL 和MATLAB 的相关操作并且帮助我复习巩固了二进制的数字运算以及门电路的相关知识,我希望在未来进行更多的VHDL 设计,加强自己的能力。