verilog-正弦波生成器

复制代码
module sinewave(sindata,clk,addm,cs);
	input clk,cs;
	input [4:0] addm;
	output [7:0] sindata;
	reg [7:0] sindata;
	reg [7:0] sinrom [19:0];
	
	initial
	begin
	sinrom[0]=8'd128;
	sinrom[1]=8'd167;
	sinrom[2]=8'd203;
	sinrom[3]=8'd231;
	sinrom[4]=8'd250;
	sinrom[5]=8'd255;
	sinrom[6]=8'd250;
	sinrom[7]=8'd231;
	sinrom[8]=8'd203;
	sinrom[9]=8'd167;
	sinrom[10]=8'd128;
	sinrom[11]=8'd88;
	sinrom[12]=8'd53;
	sinrom[13]=8'd24;
	sinrom[14]=8'd6;
	sinrom[15]=8'd0;
	sinrom[16]=8'd6;
	sinrom[17]=8'd24;
	sinrom[18]=8'd53;
	sinrom[19]=8'd88;
	end
	
always@(posedge clk)
	if(cs)
		sindata<=8'hzz;
	else
		sindata<=sinrom[addm];
endmodule

//测试平台送地址读出rom中数据

`timescale 1 ps/ 1 ps
module sinewave_vlg_tst();
// constants                                           
// general purpose registers
reg eachvec;
// test vector input registers
reg [4:0] addm;
reg clk;
reg cs;
// wires                                               
wire [7:0]  sindata;

// assign statements (if any)                          
sinewave i1 (
// port map - connection between master ports and signals/registers   
    .addm(addm),
    .clk(clk),
    .cs(cs),
    .sindata(sindata)
);

// 添加时钟生成
initial begin
    clk = 1'b0;
    forever #10000 clk = ~clk;  // 10ns 周期 (对应 timescale 1ps)
end

initial begin
    // 初始化
    cs = 1'b1;      // 片选无效
    addm = 5'b0;
    
    #20000;         // 等待20ns
    
    $display("========== 开始正弦波ROM测试 ==========");
    $display("时间(ps) | 地址 | 数据");
    $display("--------------------------");
    
    // 使能片选并顺序读取所有地址
    cs = 1'b0;      // 片选有效
    
    // 顺序读取地址0-19
    addm = 5'd0;   #20000;  // 每个地址等待20ns
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd1;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd2;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd3;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd4;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd5;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd6;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd7;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd8;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd9;   #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd10;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd11;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd12;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd13;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd14;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd15;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd16;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd17;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd18;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    addm = 5'd19;  #20000;
    $display("  %t |  %2d  |  %3d", $time, addm, sindata);
    
    $display("========== 测试完成 ==========");
    #50000;
    $stop;
end

// 删除无用的 always 块(可选)
/*
always 
begin
    @eachvec;  // 这个在大多数情况下不需要
end
*/

endmodule

右键选中,radix选中unsigned,format选中analog

相关推荐
千寻xun14 小时前
一、理论篇-NVME协议学习笔记
笔记·学习·fpga开发·nvme ssd·nvme协议
nuoxin1141 天前
HR4988替代A4988-富利威
网络·人工智能·嵌入式硬件·fpga开发·dsp开发
一口一口吃成大V1 天前
vivado的bit 和 bin的区别
fpga开发
尤老师FPGA2 天前
HDMI数据的接收发送实验(十八)
fpga开发
北京青翼科技2 天前
青翼科技 JFM7K325T FPGA+FT-M6678 DSP 的全国产化信号处理平台丨FPGA开发板
fpga开发·数据采集卡·fmc子卡·fpga开发板·ad采集卡·图像处理卡·dsp信号处理
zlinear数据采集卡3 天前
从0到1硬核拆解:工业级数据采集卡的隔离设计与Modbus通信实战
arm开发·单片机·嵌入式硬件·fpga开发·开源
FakeOccupational3 天前
fpga系列 HDL:Microchip FPGA开发软件 Libero Soc FPGA 在线逻辑分析
fpga开发
FPGA技术联盟3 天前
如何在跨时钟域分析中处理好复位信号?
fpga开发
国科安芯3 天前
基于ASM1042S2S的箭载通信网络抗辐射加固方案研究
服务器·网络·嵌入式硬件·fpga开发·架构·信号处理
YYRAN_ZZU4 天前
Lattice 自定义IP业务逻辑核
嵌入式硬件·fpga开发