Below you can see a Mealy and Moore design code as well as simulation (test bench) code. Can you write note on side of code illustrating what the line represents and explain how the two codes are behaving differently?    Mealy: Design source code: module mealy #Example of where the notes should go to represent how the lines are behaving ( input shift_start, input shift_stop, input rst, input clk, input d, output reg [7:0] q );   parameter Idle  =2'd0; parameter Start =2'd1; parameter Run   =2'd2; parameter Stop  =2'd3;   reg [1:0] state; reg [4:0] delay_cnt;   always @(posedge clk or negedge rst) begin     if(!rst)     begin         state <= Idle;         delay_cnt <= 0;         q <= 0;     end     else     case(state)         Idle : begin                 if(shift_start)                     state <= Start;                 end         Start : begin                  if(delay_cnt ==5'd99)                  begin                     delay_cnt <= 0;                     state <= Run;                  end                  else                     delay_cnt <= delay_cnt + 1'b1;                  end         Run : begin                 if(shift_stop)                     state <= Stop;                 else                     q <= {q[6:0], d};               end         Stop : begin                 q <= 0;                 state <= Idle;                 end     default: state <= Idle;     endcase  end endmodule               Simulation code: module fsm_tb(); reg shift_start; reg shift_stop; reg rst; reg clk; reg d; wire [7:0] q;   initial begin     rst = 0;     clk = 0;     d = 0;     #200 rst = 1;     forever     begin         #({$random}%100)         d = ~d;     end end   initial begin     shift_start = 0;     shift_stop = 0;      #300  shift_start = 1;      #1000 shift_start = 0;           shift_stop = 1;     #50   shift_start = 0; end   always #10 clk = ~ clk;   mealy t0 (     .shift_start(shift_start),     .shift_stop(shift_stop),     .rst(rst),     .clk(clk),     .d(d),     .q(q) ); endmodule   Moore design code: module fsm_moore ( input shift_start, input shift_stop, input rst, input clk, input d, output reg [7:0] q ); parameter Idle = 2'd0 ; //Idle state parameter Start = 2'd1 ; //Start state parameter Run = 2'd2 ; //Run state parameter Stop = 2'd3 ; //Stop state reg [1:0] current_state ; //statement reg [1:0] next_state ; reg [4:0] delay_cnt ; //delay counter //First part: statement transition always @(posedge clk or negedge rst) begin if (!rst) current_state <= Idle ; else current_state <= next_state ; end //Second part: combination logic, judge statement transition   always @(*) begin case(current_state) Idle : begin if (shift_start) next_state <= Start ; else next_state <= Idle ; end Start : begin if (delay_cnt == 5'd99) next_state <= Run ; else next_state <= Start ; end Run : begin if (shift_stop) next_state <= Stop ; else next_state <= Run ; end Stop : next_state <= Idle ; default: next_state <= Idle ; endcase end //Last part: output data always @(posedge clk or negedge rst) begin if (!rst) delay_cnt <= 0 ; else if (current_state == Start) delay_cnt <= delay_cnt + 1'b1 ; else delay_cnt <= 0 ; end always @(posedge clk or negedge rst) begin if (!rst) q <= 0 ; else if (current_state == Run) q <= {q[6:0], d} ; else q <= 0 ; end endmodule   Simulation: module moore_tb(); reg shift_start; reg shift_stop; reg rst; reg clk; reg d; wire [7:0] q;   initial begin     rst = 0;     clk = 0;     d = 0;     #200 rst = 1;     forever     begin         #({$random}%100)         d = ~d;     end end   initial begin     shift_start = 0;     shift_stop = 0;      #300  shift_start = 1;      #1000 shift_start = 0;           shift_stop = 1;     #50   shift_start = 0; end   always #10 clk = ~ clk;   mealy t0 (     .shift_start(shift_start),     .shift_stop(shift_stop),     .rst(rst),     .clk(clk),     .d(d),     .q(q) ); endmodule

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Below you can see a Mealy and Moore design code as well as simulation (test bench) code.

Can you write note on side of code illustrating what the line represents and explain how the two codes are behaving differently? 

 

Mealy:

Design source code:

module mealy #Example of where the notes should go to represent how the lines are behaving

(

input shift_start,

input shift_stop,

input rst,

input clk,

input d,

output reg [7:0] q

);

 

parameter Idle  =2'd0;

parameter Start =2'd1;

parameter Run   =2'd2;

parameter Stop  =2'd3;

 

reg [1:0] state;

reg [4:0] delay_cnt;

 

always @(posedge clk or negedge rst)

begin

    if(!rst)

    begin

        state <= Idle;

        delay_cnt <= 0;

        q <= 0;

    end

    else

    case(state)

        Idle : begin

                if(shift_start)

                    state <= Start;

                end

        Start : begin

                 if(delay_cnt ==5'd99)

                 begin

                    delay_cnt <= 0;

                    state <= Run;

                 end

                 else

                    delay_cnt <= delay_cnt + 1'b1;

                 end

        Run : begin

                if(shift_stop)

                    state <= Stop;

                else

                    q <= {q[6:0], d};

              end

        Stop : begin

                q <= 0;

                state <= Idle;

                end

    default: state <= Idle;

    endcase 

end

endmodule

 

 

 

 

 

 

 

Simulation code:

module fsm_tb();

reg shift_start;

reg shift_stop;

reg rst;

reg clk;

reg d;

wire [7:0] q;

 

initial

begin

    rst = 0;

    clk = 0;

    d = 0;

    #200 rst = 1;

    forever

    begin

        #({$random}%100)

        d = ~d;

    end

end

 

initial

begin

    shift_start = 0;

    shift_stop = 0; 

    #300  shift_start = 1; 

    #1000 shift_start = 0;

          shift_stop = 1;

    #50   shift_start = 0;

end

 

always #10 clk = ~ clk;

 

mealy t0

(

    .shift_start(shift_start),

    .shift_stop(shift_stop),

    .rst(rst),

    .clk(clk),

    .d(d),

    .q(q)

);

endmodule

 

Moore design code:

module fsm_moore

(

input shift_start,

input shift_stop,

input rst,

input clk,

input d,

output reg [7:0] q

);

parameter Idle = 2'd0 ; //Idle state

parameter Start = 2'd1 ; //Start state

parameter Run = 2'd2 ; //Run state

parameter Stop = 2'd3 ; //Stop state

reg [1:0] current_state ; //statement

reg [1:0] next_state ;

reg [4:0] delay_cnt ; //delay counter

//First part: statement transition

always @(posedge clk or negedge rst)

begin

if (!rst)

current_state <= Idle ;

else

current_state <= next_state ;

end

//Second part: combination logic, judge statement transition

 

always @(*)

begin

case(current_state)

Idle : begin

if (shift_start)

next_state <= Start ;

else

next_state <= Idle ;

end

Start : begin

if (delay_cnt == 5'd99)

next_state <= Run ;

else

next_state <= Start ;

end

Run : begin

if (shift_stop)

next_state <= Stop ;

else

next_state <= Run ;

end

Stop : next_state <= Idle ;

default: next_state <= Idle ;

endcase

end

//Last part: output data

always @(posedge clk or negedge rst)

begin

if (!rst)

delay_cnt <= 0 ;

else if (current_state == Start)

delay_cnt <= delay_cnt + 1'b1 ;

else

delay_cnt <= 0 ;

end

always @(posedge clk or negedge rst)

begin

if (!rst)

q <= 0 ;

else if (current_state == Run)

q <= {q[6:0], d} ;

else

q <= 0 ;

end

endmodule

 

Simulation:

module moore_tb();

reg shift_start;

reg shift_stop;

reg rst;

reg clk;

reg d;

wire [7:0] q;

 

initial

begin

    rst = 0;

    clk = 0;

    d = 0;

    #200 rst = 1;

    forever

    begin

        #({$random}%100)

        d = ~d;

    end

end

 

initial

begin

    shift_start = 0;

    shift_stop = 0; 

    #300  shift_start = 1; 

    #1000 shift_start = 0;

          shift_stop = 1;

    #50   shift_start = 0;

end

 

always #10 clk = ~ clk;

 

mealy t0

(

    .shift_start(shift_start),

    .shift_stop(shift_stop),

    .rst(rst),

    .clk(clk),

    .d(d),

    .q(q)

);

endmodule

Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education