资讯详情

verilog源程序加测试程序加仿真波形_频率计

先放我们的实验要求。实验要求不一样的话,慎重参考。 源程序: //总模块 module FrequencyCounter( input [1:0] testmode , input sysclk , input modecontrol, output highfreq, output [6:0] hex0, output[6:0] hex1, output[6:0] hex2, output[6:0] hex3 ); wire sigin11; assign highfreq=modecontrol; signalinput signalin(.testmode(testmode),.sysclk(sysclk),.sigin1(sigin11)); Frequency freq(.sigin11(sigin11),.sysclk(sysclk),.modecontrol(modecontrol),.hex0(hex0),.hex1(hex1),.hex2(hex2),.hex3(hex3)); endmodule //频率计模块 module Frequency(sigin11,sysclk,modecontrol,hex0,hex1,hex2,hex3); input sigin11,sysclk,modecontrol; // output highfreq; output [6:0]hex0,hex1,hex2,hex3; wire [15:0]countBCD; wire [15:0]locker; wire OneClk; wire enable,reset,lock,sigin12; //signalinput siginai(.testmode(testmode),.sysclk(sysclk),.sigin1(sigin11)); OneHzClk onehz(.sysclk(sysclk),.OneClk(OneClk)); ControlSig controls(.OneClk(OneClk),.enable(enable),.reset(reset),.lock(lock)); TenDivideFre tendiv(.sigin(sigin11),.sigin1(sigin12)); TenCounter tencou(.sigin(sigin11),.sigin1(sigin12),.modecontrol(modecontrol),.enable(enable),.reset(reset),.countBCD(countBCD)); lockMachine lockma(.lock(lock),.countBCD(countBCD),.locker(locker)); ShuMa shum(.locker(locker),.hex0(hex0),.hex1(hex1),.hex2(hex2),.hex3(hex3)); endmodule //siginal Input Module module signalinput( input [1:0] testmode,//00,01,10,11????4???????3125?250?50?12500Hz???SW1~SW0??? input sysclk,//????50M output sigin1//?????? ); reg[20:0] state; reg[20:0] divide; reg sigin; assign sigin1=sigin; initial begin sigin=0; state=21'b000000000000000000000; divide=21'b0000000_1111_1010_000000; end always@(testmode) begin case(testmode[1:0]) 2'b00:divide=21'b0000000_1111_1010_000000; //3125Hz 2'b01:divide=21'b00000000_1111_1010_00000; //6250Hz 2'b10:divide=21'b01111_0100_0010_0100_0000;//50Hz 2'b11:divide=21'b00000_0000_1111_1010_0000; //12500Hz endcase end always@(posedge sysclk)//?divide?? begin if(state==0) sigin=~sigin; state=state+21'b0_00__0000_0000_0000_0000_10; if(state==divide) state=27'b000_0000_0000_0000_0000_0000_0000; end endmodule //1Hz clock module module OneHzClk(sysclk,OneClk); reg[25:0] state; reg[25:0] divide; input sysclk; output OneClk; reg sigin; assign OneClk=sigin; initial begin sigin=0; state=26'b00_0000_0000_0000_0000_0000; divide=26'b10_1111_1010_1111_0000_1000_0000; //divide=21'b000000_0000_0000_0001000; end always@(posedge sysclk)//?divide?? begin if(state==0) sigin=~sigin; state=state+26'b0000_0000__0000_0000_0000_0000_10; if(state==divide) state=26'b00_0000_0000_0000_0000_0000_0000; end endmodule //1Hz clk produce control siginal module ControlSig(OneClk,enable,reset,lock); input wire OneClk; output reg enable,reset,lock; reg countcc; initial begin enable=0; reset=1; lock=0; countcc=0; end always@(posedge OneClk) begin countcc=countcc+1; if(countcc==0) begin lock=0; reset=1; enable=1; end else if(countcc==1) begin lock=1; reset=0; enable=0; end end endmodule //10 counter module module TenCounter(sigin,sigin1,modecontrol,enable,reset,countBCD); input wire sigin,sigin1,modecontrol,enable,reset; output [15:0] countBCD; wire sigi; assign sigi=modecontrol?sigin1:sigin; reg [3:0]count0,count1,count2,count3; assign countBCD[3:0]=count0; assign countBCD[7:4]=count1; assign countBCD[11:8]=count2; assign countBCD[15:12]=count3; initial begin count0=4'b0000; count1=4'b0000; count2=4'b0000; count3=4'b0000; end always@(posedge sigi or negedge reset) begin if(!reset) begin count0=4'b0000; count1=4'b0000; count2=4'b0000; count3=4'b0000; end else begin if(enable) begin count0=count0+4'b0001; if(count0==4'b1010) begin count1=count1+1; count0=0; end if(count1==4'b1010) begin count2=count2+1; count1=0; end if(count2==4'b1010) begin count3=count3+1; count0=0; end end end end endmodule //shiliu wei suocunqi mokuai module lockMachine(lock,countBCD,locker); input lock; input wire [15:0]countBCD; output reg [15:0]locker; always@(*) begin if(!lock) locker[15:0]=countBCD[15:0]; end endmodule //shumaguan mokuai module ShuMa(input [15:0]locker,output[6:0] hex0,hex1,hex2,hex3); SevenYimaqi seven0(.A(locker[3:0]),.D0(hex0[0]),.D1(hex0[1]),.D2(hex0[2]),.D3(hex0[3]),.D4(hex0[4]),.D5(hex0[5]),.D6(hex0[6])); SevenYimaqi seven1(.A(locker[7:4]),.D0(hex1[0]),.D1(hex1[1]),.D2(hex1[2]),.D3(hex1[3]),.D4(hex1[4]),.D5(hex1[5]),.D6(hex1[6])); SevenYimaqi seven2(.A(locker[11:8]),.D0(hex2[0]),.D1(hex2[1]),.D2(hex2[2]),.D3(hex2[3]),.D4(hex2[4]),.D5(hex2[5]),.D6(hex2[6])); SevenYimaqi seven3(.A(locker[15:12]),.D0(hex3[0]),.D1(hex3[1]),.D2(hex3[2]),.D3(hex3[3]),.D4(hex3[4]),.D5(hex3[5]),.D6(hex3[6])); endmodule //qiduan yimaqi mokuai module SevenYimaqi(input[3:0] A,output D0,D1,D2,D3,D4,D5,D6); assign D0=!A[3]&&(!A[2])&&(!A[1])&&A[0]||!A[3]&&A[2]&&!A[1]&&!A[0]||A[3]&&A[2]&&!A[1]&&A[0]||A[3]&&!A[2]&&A[1]&&A[0];//1/4/11/13 assign D1=A[3]&&A[2]&&!A[1]&&!A[0]||!A[3]&&A[2]&&!A[1]&&A[0]||A[3]&&A[2]&&A[1]||A[3]&&A[1]&&A[0]||A[2]&&A[1]&&!A[0];//5/6/11/12/14/15 assign D2=!A[3]&&!A[2]&&A[1]&&!A[0]||A[3]&&A[2]&&A[1]||A[3]&&A[2]&&!A[1]&&!A[0];//2/12/14/15 assign D3=!A[3]&&!A[2]&&!A[1]&&A[0]||!A[3]&&A[2]&&!A[1]&&!A
锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台