Question

So I need to get sinus waveform. In cases I have wrote values of x and y axis in range of 2pi

how to get the waveform of the sinus in this range?

module sinus1(in,clk,res,out);
input clk,res;
input [7:0]in;
output reg [7:0]out;
always @(posedge clk)
if (res)
case (in)
8'b00000000: out<=8'b10000000;
8'b00000001: out<=8'b10000011;
8'b00000010: out<=8'b10000110;
8'b00000011: out<=8'b10001001;
8'b00000100: out<=8'b10001100;
8'b00000101: out<=8'b10001111;
8'b00000110: out<=8'b10010010;
...
...
...
8'b11111111: out<=8'b01111101;
endcase
else out<=8'b00000000;
endmodule

module testbench;
reg clk,res;
reg [7:0]in;
sinus1 sinusoid(in,clk,res,out);
always #5 clk=~clk
initial
begin
clk=0;res=0;
#5 res=1;
#5000 $finish;
end
endmodule
Was it helpful?

Solution

If you want get the values for each input, you should sweep the values in your testbench, perhaps from 0 to 255. Here is a link that does this on Eda Playground:

http://www.edaplayground.com/x/2bx

Output:

in=00000000, out = sin(in) = 10000000
in=00000001, out = sin(in) = 10000011
in=00000010, out = sin(in) = 10000110
in=00000011, out = sin(in) = 10001001
in=00000100, out = sin(in) = 10001100
in=00000101, out = sin(in) = 10001111
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top