Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16612 Discussions

looping over a string character by character in Verilog

Altera_Forum
Honored Contributor II
3,289 Views

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
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
1,672 Views

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.
0 Kudos
Reply