Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

looping over a string character by character in Verilog

I'm attempting to send a string character by character over a serial port. I have the serial port down, but I don't quite see how to implement a changing index on a string...

Ideally, my module would take as input a clock counter (synced to the baud rate of my serial module), and based on that clock input send out a character.

Here's what I have so far, which works, but it seems like there is a much better way of doing it.

module sendString(
    input wire  clockInput,
    output  TxD_start,
    output  TxD_buffer
    );
reg  message = "Help! I'm trapped in an FPGA!";
reg  tmpbuffer;
always @*
begin
    if(clockInput==5'b00000)
    begin
        tmpbuffer <= message;
    end
    if(clockInput==5'b00001)
    begin
        tmpbuffer <= message;
    end
    //and so on, for the other clock cases
end
assign TxD_buffer = tmpbuffer;
assign TxD_start = 1;
endmodule

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You may start defining your message array like this:

    reg [7:0] message [29:0]

    Then you can use simple indexing to access each character.

    Moreover I would recommend using a clock and synchronous logic.

    Infact, always @* implies a purely combinatorial behaviour: this is usually not recommended, especially in your case which is basically a clock-driven process.