Question

In: Electrical Engineering

Having trouble with the verilog code. Also think my ASM chart may be wrong so some...

Having trouble with the verilog code. Also think my ASM chart may be wrong so some help with that would be great as well thanks. Not sure if the question is linked but its a textbook question. Digital design 6th edition chapter 8 question 10.Link:  https://www.chegg.com/homework-help/Digital-Design-6th-edition-chapter-8-problem-10P-solution-9780134529561

Solutions

Expert Solution

//

//verilog model for given moore state machine
module moore_fsm # (
//parameter declarations for states
parameter S0 = 2'b00 ,
S1 = 2'b01 ,
S2 = 2'b10 ,
S3 = 2'b11
)(
//input port declarations
input CLK, // clock input
input Resetn, //Asynchronous active low reset input
input x,y,//binary data input
  
//output port declarations
output [1:0] out // state machine output
);
  
//internal register declarations for states
reg [1:0] current_state, next_state; // current state and next state
  
// sequential logic for present satte of the Moore FSM
always @(posedge CLK)
begin
if(Resetn==0)
current_state <= S0;// when reset=0, reset the state of the FSM to "S0" State
else
current_state <= next_state; // otherwise, next state
end
  
// combinational logic of the Moore FSM
// to determine next state
always @(current_state,x,y)
begin
case(current_state)
S0:begin
if(x==1)
next_state <= S1;
else
next_state <= S0;
end
S1:begin
if(y==1)
next_state <= S3;
else
next_state <= S2;
end
S2:begin
case ({x,y})
2'b00 : next_state <= S0;
2'b01 : next_state <= S0;
2'b10 : next_state <= S2;
2'b11 : next_state <= S3;
endcase
end
S3:begin
case ({x,y})
2'b00 : next_state <= S2;
2'b01 : next_state <= S3;
2'b10 : next_state <= S0;
2'b11 : next_state <= S0;
endcase   
end

endcase
end

// combinational logic to determine the output
// of the Moore FSM, output only depends on current state

assign out = current_state ;

endmodule
  
//testbench

// veriog testbench code for guven moore state machine
module test_fsm ;
  
//inputs
reg CLK;
reg Resetn;
reg x,y;
  
//outputs
wire [1:0] out;
  
//instantiate DUT od moore FSM
moore_fsm DUT ( .CLK(CLK),.Resetn(Resetn),.x(x),.y(y),.out(out));
  
//clock geneartion
initial begin
CLK = 0;
forever #5 CLK = ~CLK;
end
  
//reset generation
initial begin
Resetn = 0;
#10 Resetn =1 ;
end
  
//binary data input generation
initial begin
$dumpfile("dump.vcd");
$dumpvars;
x = 0;y=0; #10;
x = 0;y=1; #10;
x = 1;y=0; #10;   
x = 0;y=1; #10;
x = 1;y=1; #10;
x = 0;y=1; #10;
x = 1;y=0; #10;
x = 1;y=0; #10;
x = 1;y=0; #10;
x = 1;y=1; #10;
x = 0;y=1; #10;
x = 1;y=0; #10;
x = 0;y=1; #10;
x = 1;y=0; #10;
x = 0;y=1; #10;
x = 0;y=0; #10;
x = 1;y=0; #10;
x = 1;y=1; #10;
x = 0;y=1; #10;
$finish;
end
  
  
endmodule

// I added resetn input port just as a safety when module implemented in hardware

//simulated wavform


Related Solutions

I'm having trouble with validating this html code. Whenever I used my validator, it says I...
I'm having trouble with validating this html code. Whenever I used my validator, it says I have a stray end tag: (tbody) from line 122 to 123. It's the last few lines. Thanks and Ill thumbs up whoever can help solve my problem. Here's my code: <!DOCTYPE html> <html lang="en"> <head> <title>L7 Temperatures Fields</title> <!--    Name:    BlackBoard Username:    Filename: (items left blank for bb reasons    Class Section: (blank)    Purpose: Making a table to demonstrate my...
Hey! I'm having trouble answering this for my assignment. Thank you so much in advance. 1)...
Hey! I'm having trouble answering this for my assignment. Thank you so much in advance. 1) Which type of vessels, arteries or veins, has more muscle fibers? What is the functional significance of this? 2a) In general, we have no conscious control over smooth muscle or cardiac muscle function, whereas we can consciously control to some extent all skeletal muscles. Can you consciously control your breathing? What does this tell you about the muscle type of the diaphragm? 2b) What...
Im having trouble turning my words and calculations into tables and graphs for my research methods...
Im having trouble turning my words and calculations into tables and graphs for my research methods paper. I need 2 tables and 1 graph. Table 1 - should show that out of 17,425 respondents 43% resported being in business for 3+ years. 33% reported being in business for 1-2 years and 24% respondents being on business for 0-1 years Table 2 - should show marketing method preference. 43% respondent with both online and relationship marketing methods. the 33% group respondent...
I'm having trouble understanding the following code (a snippet of a code). What does it do?...
I'm having trouble understanding the following code (a snippet of a code). What does it do? The whole code is about comparing efficiencies of different algorithms. def partition(list,first,last): piv = list[first] lmark = first+1 rmark = last done = False while not done: while lmark <= rmark and list[lmark]<=piv: lmark=lmark+1 while list[rmark]>=piv and rmark>=lmark: rmark=rmark-1 if rmark<lmark: done = True else: temp = list[lmark] list[lmark]=list[rmark] list[rmark]=temp temp = list[first] list[first]=list[rmark] list[rmark]=temp return rmark
Hello, having some trouble with my case studies. Case Study 3 Acute Care Mrs Fox Case...
Hello, having some trouble with my case studies. Case Study 3 Acute Care Mrs Fox Case Scenario: Acute Care Mrs. Fox, a 40-year-old wife and mother of 2, was involved in a massive motor vehicle accident on the Sawmill Parkway in which her car struck the center divider and flipped twice. A good Samaritan immediately dialed 911. First responders found the patient unconscious with severe injuries but were able to safely transport her to St. John’s Riverside Hospital. Upon arrival...
Having some trouble with my case study questions please. “Aaaargh!” Susan Pohl, Family Nurse Practitioner, felt...
Having some trouble with my case study questions please. “Aaaargh!” Susan Pohl, Family Nurse Practitioner, felt extremely frustrated as she left Room 12. She had just spent the last 30 minutes with Lydia Lopez-Rivera, a developmentally disabled, 30-weeks-pregnant, 19-year-old Latina. “What’s wrong, Susan?” asked Bernie Candales-Mitterman, the group’s social worker.“I’ve just spent the last half-hour with Lydia Lopez—you know, the pregnant girl. I’m just so upset! She’s missed several appointments, even though I had the nurses call her. She was...
Sherald is having trouble finding a procedural code in the Alphabetic Index for removal of a...
Sherald is having trouble finding a procedural code in the Alphabetic Index for removal of a cataract. What are some options and/or alternative ways she can perform an Alphabetic Index search?
I am having trouble with a C++ code that I'm working on. It is a spell...
I am having trouble with a C++ code that I'm working on. It is a spell checker program. It needs to compare two arrays, a dictionary, and an array with misspelled strings that are compared to the strings in the dictionary. the strings that are in the second array that is not in the Dictionary are assumed to be misspelled. All of the strings in the dictionary are lowercase without any extra characters so the strings that are passed into...
Having Trouble with this C++ assignment THe places that are marked // TODO is where code...
Having Trouble with this C++ assignment THe places that are marked // TODO is where code should be filled in at Header (myQueue.h) #ifndef _MYQUEUE_H_ #define _MYQUEUE_H_ using namespace std; template class myQueue { public:    myQueue(int maxSz);    ~myQueue();    void enqueue(T item);    T dequeue(); int currentSize(); bool isEmpty(); bool isFull(); private:    T *contents; /*Dynamic initiate (C++ keyword new) the holder array*/    int front,rear; /*Index in the array of the front and rear element*/    int...
Having trouble finding the answer. My answer is it is not significantly different 2. Consider a...
Having trouble finding the answer. My answer is it is not significantly different 2. Consider a population of lizards living on an island. We believe that they may be members of a species called Tribolonotus gracilis. The mean length of Tribolonotus gracilis is known to be 8cm. The following length values (cm) were obtained for a sample of individuals from the island: 11.3,11.5, 9.2, 11, 6.9, 8.9, 6.9, 11.3 Do these lizards have sizes that are consistent with their being...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT