
首先,FPGA本身对非2的指数次的乘法或者除法的支持并不好,所以算法中的乘法、除法运算需要调用乘法、除法核,而核调用是没法在这里表示出来的,需要你在quaters或者ISE上生成IP核然后调用
其次,标准信号的周期不确定,所以就没法确定什么时候结果不在范围之内;
你这个考试题不知道是哪个白痴老师出的,简直是在挑战FPGA的极限,专门往FPGA不擅长的方面出题。
你先拿去用着,选为最佳答案后有问题可以hi我,我一般隔一阵就会看一眼hi
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer: 搞吓米飞机
//
// Create Date:09:30:31 06/29/2010
// Design Name:
// Module Name:frequency
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module frequency(clk,En,zhamen,Input,LED4,LED1,LED2,LED3,LED5,low,high
)
input clk//时钟输入,同时也是所谓的标准信号。
input En
input zhamen//闸门输入
input Input//测试数据输入
output LED4//五个LED,当做输出
output LED1
output LED2
output LED3
output LED5
output low
output high
wire clk
wire En
wire zhamen
wire Input
reg zhamen_En//实际门限使能
reg [10:0]Nx//数据
reg [11:0]Ns//标准计数
reg [7:0]LED1
reg [7:0]LED2
reg [7:0]LED3
reg [7:0]LED4
reg [7:0]LED5
reg flag
reg [10:0]result
reg low//低于或高于测试范围的提示LED输出。这里因为具体将门限制设置到多少与clk的频率相关,需要自行设置
reg high
always@(posedge clk)
begin
if(En==1)
begin
if(zhamen==1)
begin
if(Input==1)
zhamen_En=1
end
if(zhamen==0)
begin
if(Input==1)
begin
zhamen_En=0
end
end
if(zhamen_En==1)
begin
Ns=Ns+1
flag=1
end
end
else
begin
LED5=0
LED1=0
LED2=0
LED3=0
LED4=0
zhamen_En=0
flag=0
end
end
always@(posedge Input)
begin
if(zhamen_En==1)
Nx=Nx+1
end
always@(posedge clk)
begin
if(zhamen_En==0&&flag==1)
begin
flag=0
result=(Nx/Ns)*Fs// 此处仅仅是个示例。这里需要调用除法核以及乘法核,调用之后直接输入即可
case(result%10)//这里也是要调用除法核生成余数和结果,下面同理
4'b0000: LED1=8'b11111101
4'b0001: LED1=8'b01100001
4'b0010: LED1=8'b11011011
4'b0011: LED1=8'b11110011
4'b0100: LED1=8'b01100111
4'b0101: LED1=8'b10110111
4'b0110: LED1=8'b10111111
4'b0111: LED1=8'b11100001
4'b1000: LED1=8'b11111111
4'b1001: LED1=8'b11110111
default: LED1=8'b11111101
endcase
case(((result-result%10)%100)/10)
4'b0000: LED2=8'b11111100
4'b0001: LED2=8'b01100000
4'b0010: LED2=8'b11011010
4'b0011: LED2=8'b11110010
4'b0100: LED2=8'b01100110
4'b0101: LED2=8'b10110110
4'b0110: LED2=8'b10111110
4'b0111: LED2=8'b11100000
4'b1000: LED2=8'b11111110
4'b1001: LED2=8'b11110110
default: LED2=8'b11111100
endcase
case((result%1000-result%100-result%10)/100)
4'b0000: LED3=8'b11111100
4'b0001: LED3=8'b01100000
4'b0010: LED3=8'b11011010
4'b0011: LED3=8'b11110010
4'b0100: LED3=8'b01100110
4'b0101: LED3=8'b10110110
4'b0110: LED3=8'b10111110
4'b0111: LED3=8'b11100000
4'b1000: LED3=8'b11111110
4'b1001: LED3=8'b11110110
default: LED3=8'b11111100
endcase
case((result%10000-result%1000-result%100-result%10)/1000)
4'b0000: LED4=8'b11111100
4'b0001: LED4=8'b01100000
4'b0010: LED4=8'b11011010
4'b0011: LED4=8'b11110010
4'b0100: LED4=8'b01100110
4'b0101: LED4=8'b10110110
4'b0110: LED4=8'b10111110
4'b0111: LED4=8'b11100000
4'b1000: LED4=8'b11111110
4'b1001: LED4=8'b11110110
default: LED4=8'b11111100
endcase
case((result-result%10000-result%1000-result%100-result%10)/10000)
4'b0000: LED5=8'b11111100
4'b0001: LED5=8'b01100000
4'b0010: LED5=8'b11011010
4'b0011: LED5=8'b11110010
4'b0100: LED5=8'b01100110
4'b0101: LED5=8'b10110110
4'b0110: LED5=8'b10111110
4'b0111: LED5=8'b11100000
4'b1000: LED5=8'b11111110
4'b1001: LED5=8'b11110110
default: LED5=8'b11111100
endcase
end
end
endmodule
1module sig2component(clk, rst_n, din, dout)
inputclk
inputrst_n
input [7:0]din
output [7:0] dout
always @ (posedge clk or negedge rst_n)
if (!rst_n)
dout <= 0
else if (din[7]) begin
dout[6:0] <= ~din[6:0] + 7'd1
dout[7] <= din[7]
end
else
dout <= din
endmodule
2
module compare(clk, rst_n, din, flag_out)
input clk, rst_n
input [3:0]din
output flag_out
always @ (posedge clk or negedge rst_n)
if (!rst_n)
flag_out <= 0
else if (din >4'd4)
flag_out <= 1'b1
else
flag_out <= 1'b0
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)