Questions about the Serial Tutorial

General discussion about the Mojo
Post Reply
leictreonaic
Posts: 23
Joined: April 24th, 2013, 12:17 am

Questions about the Serial Tutorial

Post by leictreonaic » May 27th, 2013, 1:49 am

So I got the serial tutorial working just fine. I am wondering about a few of the lines of message_printer.v.

Code: Select all

...
localparam STATE_SIZE = 1 
...
reg [STATE_SIZE-1:0] state_d, state_q;
What is the meaning of the STATE_SIZE? It looks like state_d & state_q are just one bit right?
does it set state_d to 1 and state_q to 0 or is it [STATE_SIZE minus 1 : 0]
which would make it a zero length or one bit reg? I don't know I'm confused.

I know that state_q is the case statement argument and then state_d is poked IDLE or PRINT_MESSAGE then pushes to state_q at the posedge clk.

Why the STATE_SIZE ? Okay after going back and reading the tutorial it looks like both state_d and state_q are 2 bits. So then it is not STATE_SIZE minus 1 : 0 but rather STATE_SIZE 1:0. Why the dash in there?

One more thing, the line

Code: Select all

wire [7:0] rom_data
in message_printer does not seem to need to be there, as in not hooked up to anything.

User avatar
morseworld
Posts: 9
Joined: March 30th, 2013, 1:27 pm

Re: Questions about the Serial Tutorial

Post by morseworld » May 27th, 2013, 10:13 pm

Can you post a link to the Serial Tutorial?

leictreonaic
Posts: 23
Joined: April 24th, 2013, 12:17 am

Re: Questions about the Serial Tutorial

Post by leictreonaic » May 27th, 2013, 11:25 pm

morseworld wrote:Can you post a link to the Serial Tutorial?
http://embeddedmicro.com/tutorials/the-mojo/hello-world

leictreonaic
Posts: 23
Joined: April 24th, 2013, 12:17 am

Re: Questions about the Serial Tutorial

Post by leictreonaic » May 30th, 2013, 8:42 pm

Could someone please explain the

Code: Select all

localparam STATE_SIZE
from the Hello World tutorial. Specifically what it is doing in the line

Code: Select all

 reg [STATE_SIZE-1:0] state_d, state_q;

Xark
Posts: 14
Joined: May 6th, 2013, 8:29 pm

Re: Questions about the Serial Tutorial

Post by Xark » May 31st, 2013, 1:05 am

Hello,

I believe STATE_SIZE is the number of bits needed to store the "state" of the simple state machine used in the tutorial.

Since it is so simple, and there are only two states (IDLE = 0 and PRINT_MESSAGE = 1) you are correct, it only needs 1 bit for "[reg 0:0] state_d, state_d" (which is a 1 bit register, not zero). Because there are only two states, defining the state this way may seem a bit "overkill", but it makes it easy to add additional states later (and then just adjust STATE_SIZE as needed, based on the total number of states). I also think this is a common style or (idiom) in Verilog for a state machine (which typically have more than two states). For example, if you look inside the Mojo base project "serial_rx.v" file you can see the same idiom used for a slightly more complex state machine (with 4 states).

I agree, rom_data in "message_printer.v" looks to be unused.

Hope this helps.

embmicro
Site Admin
Posts: 834
Joined: March 24th, 2013, 12:45 pm

Re: Questions about the Serial Tutorial

Post by embmicro » June 17th, 2013, 4:08 pm

Thanks for catching that rom_data doesn't need to be there. I fixed the tutorial.

Everything said about the way the states are encoded looks correct to me! Using this style also helps the tools to recognize you are writing a state machine and they will perform optimizations when they can.

Post Reply