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

相关推荐
minglie15 小时前
简易寄存器接口SMMR---正交编码器
fpga开发
神电测控9 小时前
新品发布:32通道50MS/s同步并行14位采集模块PG-FMC9249(支持任意FPGA/ZYNQ,兼容LabVIEW FPGA软件开发)
fpga开发·labview·ni·神电测控·王电令·ad9249·32通道
Drgfd10 小时前
半导体国产替代进入“深水区”:决战设备、材料、IP三大高地
网络·fpga开发
国产HT1621B11 小时前
YL1650 LED驱动芯片详解:从原理到实战应用(附51单片机驱动代码)
stm32·单片机·嵌入式硬件·mcu·fpga开发·lcd驱动
szxinmai主板定制专家13 小时前
驱控一体新范式:RK3576+FPGA+CODESYS工业实时AI控制架构全解
人工智能·嵌入式硬件·计算机视觉·fpga开发·架构·工业ai·驱控一体
国科安芯14 小时前
ASC0101S自动双向电平转换原理深剖
单片机·嵌入式硬件·fpga开发·云计算·信息与通信
落chen15 小时前
7 Series FPGAs Clocking Resources
fpga开发
落chen1 天前
基于FPGA的IIC协议通信-强化篇
fpga开发
梦开始的地方 �2 天前
实例化和句柄
fpga开发
lf2824814312 天前
11 FM调制与解调的仿真
fpga开发