Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on a verilog program that I want to have display some sort of audio waveform (captured from my microphone) over a VGA. I use the following module to shift in new audio samples, and swap it with the buffer used to store the values for the current frame being rendered by the vga controller.

module audio_shift_buffer#
(parameter BUFFER_SIZE = 1280)
(
    input vga_clk,
    input smp_clk,
    input [7:0] sample_in,
    input  sample_in_valid,
    input [10:0] vga_read_index,
    output reg [7:0] vga_read_out,
    input vga_swap_buffers
);

    reg [7:0] smp_buf[BUFFER_SIZE - 1:0];
    reg [7:0] vga_buf[BUFFER_SIZE - 1:0];

    integer i;
    always @(posedge smp_clk) 
        if(sample_in_valid) begin
            for(i = 0; i < BUFFER_SIZE - 1; i = i + 1)
                smp_buf[i] <= smp_buf[i + 1];
            smp_buf[BUFFER_SIZE - 1] <= sample_in;
        end

    integer j;
    always @(posedge vga_clk) begin
        if(vga_swap_buffers)
            for(j = 0; j < BUFFER_SIZE; j = j + 1)
                vga_buf[j] <= smp_buf[j];
        vga_read_out <= vga_buf[vga_read_index];
    end

endmodule

This module is created inside of my top level audio visualizer along with the vga_controller.

module audio_visualizer
(
    input clk,
    input m_data,
    output m_clk,
    output reg m_lr = 1'b1,
    output vga_hs, vga_vs,
    output [3:0] vga_r, vga_g, vga_b,
    input sw
);

    wire vga_clk;
    wire [10:0] sound_level_index;
    clk_wiz_0 cwz(clk, vga_clk);
    wire [7:0] vga_read;
    wire swap;

    audio_shift_buffer sb
    (
        .vga_clk(vga_clk),
        .smp_clk(vga_clk),
        .sample_in({8{sw}}),
        .sample_in_valid(swap),
        .vga_read_index(sound_level_index),
        .vga_read_out(vga_read),
        .vga_swap_buffers(swap)
    );

    vga_controller v
    (
        .vga_clk(vga_clk),
        .hsync(vga_hs),
        .vsync(vga_vs),
        .r(vga_r),
        .g(vga_g),
        .b(vga_b),
        .sound_level_index(sound_level_index),
        .sound_level(vga_read),
        .swap_buffers(swap)
    );

endmodule

Finally here is my VGA controller.

module vga_controller#
(
    parameter H_VISIBLE = 1280,
    parameter H_FRONT_PORCH = 72,
    parameter H_BACK_PORCH = 216,
    parameter H_SYNC = 80,
    parameter V_VISIBLE = 720,
    parameter V_FRONT_PORCH = 3,
    parameter V_BACK_PORCH = 22,
    parameter V_SYNC = 5
)
(
    input vga_clk,
    output [3:0] r, g, b,
    output reg hsync, vsync,
    output [10:0] sound_level_index,
    input [7:0] sound_level,
    output reg swap_buffers
);

    localparam H_RES = H_VISIBLE + H_FRONT_PORCH + H_BACK_PORCH + H_SYNC;
    localparam V_RES = V_VISIBLE + V_FRONT_PORCH + V_BACK_PORCH + V_SYNC;

    localparam H_IN_VIDEO = H_VISIBLE;
    localparam H_IN_BP = H_IN_VIDEO + H_BACK_PORCH;
    localparam H_IN_SYNC = H_IN_BP + H_SYNC;
    localparam H_IN_FP = H_IN_SYNC + H_FRONT_PORCH;

    localparam V_IN_VIDEO = V_VISIBLE;
    localparam V_IN_BP = V_IN_VIDEO + V_BACK_PORCH;
    localparam V_IN_SYNC = V_IN_BP + V_SYNC;
    localparam V_IN_FP = V_IN_SYNC + V_FRONT_PORCH;

    reg [10:0] x = 0, y = 0, next_x, next_y;
    always @(posedge vga_clk) begin
        x <= next_x;
        y <= next_y;
    end

    always @* begin
        next_y = y;
        if(x == H_RES - 1) begin
            next_x <= 0;
            if(y == V_RES - 1)
                next_y <= 0;
            else
                next_y <= y + 1;
        end else
            next_x <= x + 1;
    end

    always @(posedge vga_clk) begin
        hsync <= ~(next_x >= H_IN_BP && next_x < H_IN_SYNC);
        vsync <= ~(next_y >= V_IN_BP && next_y < V_IN_SYNC);
        swap_buffers <= next_y == V_IN_VIDEO && next_x == 0;
    end

    reg vout_enable;
    always @(posedge vga_clk) begin
        vout_enable <= next_x < H_IN_VIDEO && next_y < V_IN_VIDEO;
    end

    wire [10:0] request_x = next_x + 1;
    assign sound_level_index = request_x < H_IN_VIDEO ? request_x : 0;

    wire [10:0] ubound = 11'd360 + sound_level;
    wire [10:0] lbound = 11'd360 - sound_level;
    reg color;
    always @(posedge vga_clk) begin
        color <= next_y <= ubound && next_y >= lbound;
    end

    assign r = {4{color & vout_enable}};
    assign g = {4{color & vout_enable}};
    assign b = {4{color & vout_enable}};
endmodule

Right now I just have it hooked up to a switch on my board. It adds a "sample" of the switch after every frame. When I tested it everything seems to work perfectly. White bars scroll across the screen when the switch is on and black otherwise. However, I get the following synthesis warnings which do not make any sense to me. The elements it is listing are clearly being used. If they weren’t then I doubt the program would work. It even lists vga_read_out as unused which can't be true since it is the only way the controller can get data out and display the correct result. What is going on here?

[Synth 8-3332] Sequential element (\smp_buf_reg[1279][5] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1279][4] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1279][3] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1279][2] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1279][1] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1279][0] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[0][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[0][5] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[0][4] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[0][3] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[0][2] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[0][1] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[0][0] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_read_out_reg[7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_read_out_reg[5] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_read_out_reg[4] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_read_out_reg[3] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_read_out_reg[2] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_read_out_reg[1] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_read_out_reg[0] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1279][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1278][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1278][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1277][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1277][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1276][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1276][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1275][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1275][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1274][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1274][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1273][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1273][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1272][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1272][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1271][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1271][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1270][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1270][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1269][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1269][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1268][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1268][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1267][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1267][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1266][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1266][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1265][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1265][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1264][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1264][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1263][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1263][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1262][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1262][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1261][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1261][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1260][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1260][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1259][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1259][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1258][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1258][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1257][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1257][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1256][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1256][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1255][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1255][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1254][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1254][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1253][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1253][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1252][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1252][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1251][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1251][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1250][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1250][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1249][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1249][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1248][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1248][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1247][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1247][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1246][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1246][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1245][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1245][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1244][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1244][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1243][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1243][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1242][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1242][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1241][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1241][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\smp_buf_reg[1240][7] ) is unused and will be removed from module audio_shift_buffer.
[Synth 8-3332] Sequential element (\vga_buf_reg[1240][7] ) is unused and will be removed from module audio_shift_buffer.
share|improve this question
up vote 9 down vote accepted

If it is removing them, they are in fact unused, but it is not always obvious why.

I think in your case, the reason is:

.sample_in({8{sw}}),

The synthesiser is clever enough to realise the bits in each word of your memories (smp_buf and vga_buf) are identical. As a result, it decides there is no point duplicating the hardware, it might as well just have a 1 bit wide version.

Wherever the 8bit wide word was used, it just fills all 8 bits with the value from the new 1bit wide word. This results in the same behaviour but with less logic.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.