登录站点

用户名

密码

FPGA笔试问题整理归纳(三)

已有 808 次阅读  2009-09-28 08:38   标签笔试  FPGA  归纳 
本题考察利用有限状态机进行时序逻辑的设计下面用verilog进行描述:(有限状态机提供6个状态)
 module sequence_detect(in,out,clk,rst,state);
output out;
output[2:0]state;
input clk;
input rst;
input in;
reg[2:0]state;
wire out;
parameter IDLE='d0, A='d1, B='d2, C='d3, D='d4, E='d5;
assign out=((state==D)&&(in==1))?1:0;
always @(posedge clk)
begin if(!rst)
begin
 state<=IDLE;
end
else
 case(state)
 IDLE:if(in==1) // the first code is right, storing the state A
 // begin state<=A; end
 A:if(in==1) // the second code is right, storing the state B
 // begin state<=B; end else begin state<=IDLE; end
 B:if(in==0) // the third code is right, storing the state C
 // begin state<=C; end else begin state<=E; end
 C:if(in==1) // the fourth code is right, storing the state D
 // begin state<=D; // out<=1; end else
 begin state<=IDLE; // out<=0; end
 D:if(in==1) // connecting the front inputted sequence,again introducing one,storing state B
 // begin state<=B; end else begin state<=IDLE; end
 E:if(in==0) begin state<=C; end else begin state<=B; end
 default:state=IDLE;
 endcase
end
endmodule
 
library ieee;
 
use ieee.std_logic_1164.all;
use ieee.STD_LOGIC_ARITH.all;
use ieee.STD_LOGIC_UNSIGNED.all;
entity test is
port ( rst : in std_logic;
clk : in std_logic;
a : in std_logic;
b : out std_logic );
end test;
architecture test of test is
signal p: std_logic_vector(2 downto 0 );
begin
Start:process (rst, clk)
begin if rst = '1' then
p<="000";
if clk'event and clk = '1' then
p<=p(1 downto 0)&a;
end if;
end if;
end process;
Start1:process (rst, clk)
begin -- process
if rst = '1'
then b<='0';
if clk'event and clk = '1'
then if p = "110" and a='1'
then b<='1'; else b<='0';
end if;
end if;
end if;
end process;
end test;
有两段代码 1。
proceee(a,b,c,sel,y)
begin
if (sel) y = a+b;
else y = a+c;
end
2.y = sel ? a+b : a+c;
面试官说第一中表达方法是先选后加,所以电路实现是一个选择器和一个加法器第二种方法是先加后选,用到两个加法器和一个选择器,所以他说第一种表达方式要好一些。查了一下书,发现面试官说的并不全对,一般来说,综合工具会自动的优化,一般只会综合出一个加法器和一个选择器先选后加是加法器共用,节省面积先加后选是用面积换时间,电路的工作速度更快些。
为了实现逻辑(A XOR B)OR (C AND D),请选用以下逻辑中的一种,并说明为什么?
1)INV 2)AND 3)OR 4)NAND 5)NOR 6)XOR 我没有做出来,请大家帮忙看看我想了一下,用与非是肯定可以实现的
1。与非门的两个输入连在一起就成了非门
2。或门可以用与非和非门搭建 或非其实也可以
1。或非的两个输入PAD连在一起成非门
2。与门可以用或非门和非门搭建奇数分频(6或者3)
module s1 (// {{ALTERA_ARGS_BEGIN}} DO NOT REMOVE THIS LINE!
clkin, clkout, s1, s2 // {{ALTERA_ARGS_END}} DO NOT REMOVE THIS LINE! );
// Port Declaration // {{ALTERA_IO_BEGIN}} DO NOT REMOVE THIS LINE!
input clkin; output clkout, s1, s2; // {{ALTERA_IO_END}} DO NOT REMOVE THIS LINE!
wire s1,s2; reg [1:0] step1, step2;
always @(posedge clkin)
begin
case (step1)
2'b00: step1<=2'b01;
2'b01: step1<=2'b10;
2'b10: step1<=2'b00;
default :step1<=2'b00;
endcase
end
always @(negedge clkin)
begin
case (step2)
2'b00: step2<=2'b01;
2'b01: step2<=2'b10;
2'b10: step2<=2'b00;
default :step2<=2'b00;
endcase
end
assign clkout=step1[1]|step2[1];
assign s1=step1[1];
assign s2=step2[1];
endmodule
testbench: `timescale 1ns/1ns
module s1_tb;
reg clk_in;
wire clk_out,s1, s2;
always #50 clk_in=~clk_in;
initial begin clk_in=0;
#1000 $stop;
end s1 s10(.clkin(clk_in), .clkout(clk_out), .s1(s1), .s2(s2));
endmodule
 

上一篇: AD/DA的分类与主要技术指标 下一篇: FPGA笔试问题整理归纳(四)

分享 举报