Forum Discussion

Savino's avatar
Savino
Icon for New Contributor rankNew Contributor
10 months ago
Solved

How to force manually in ModelSim one dada bus with value like sin(x)

Hi, I am checking to force manually some data bus like: input[10..0] in MOdelSim like here(by console): force input[0] 0 0, 10, 10, ...... - repeat 200 force input[1] 0 0, 10, 10, ...... - repeat 2...
  • KennyT_altera's avatar
    9 months ago

    In that case, you may create a module for the sine function:


    module sine_generator (

    input wire clk,

    input wire reset,

    output reg signed [10:0] sine_out

    );


    reg [6:0] index; // 7-bit index for 128 samples

    reg signed [10:0] sine_lut [0:127]; // 128-point lookup table


    initial begin

    // Precompute sine values and load them into the LUT

    sine_lut[0] = 0;

    sine_lut[1] = 50;

    sine_lut[2] = 100;

    sine_lut[3] = 150;

    sine_lut[4] = 200;

    sine_lut[5] = 250;

    // ... (continue with the full sine wave values up to 127)

    sine_lut[127] = -50;

    end


    always @(posedge clk or posedge reset) begin

    if (reset) begin

    index <= 0;

    sine_out <= 0;

    end else begin

    sine_out <= sine_lut[index]; // Output the sine value

    index <= index + 1; // Increment index for next sample

    end

    end


    endmodule