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...
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?
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...
Hello, Im having trouble understanding the graphing/chart section of this lesson. Is there anyone who can...
Hello, Im having trouble understanding the graphing/chart section of this lesson. Is there anyone who can help me understand? Goods A B C D E F Capital 5 4 3 2 1 0 Consumer 0 5 9 12 14 15 (presentation as a table rather than as a graph) 1. Using the above PPTable, if the economy is producing at alternative D, the opportunity cost of producing one more unit of capital is A. 1 unit of consumer goods. B....
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator...
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator is 0 it throws the ZeroDenominatorException and the catch catches to guarantee that the denominator is never 0. /** * The main class is the driver for my Rational project. */ public class Main { /** * Main method is the entry point to my code. * @param args The command line arguments. */ public static void main(String[] args) { int numerator, denominator =...
I have an unexpected indent with my python code. please find out whats wrong with my...
I have an unexpected indent with my python code. please find out whats wrong with my code and run it to show that it works here is the code : def main(): lis = inputData() customerType = convertAcct2String(lis[0]) bushCost = getBushCost(lis[0],int(lis[1],10)) flowerCost = getFlowerBedCost(int(lis[2],10),int(lis[3],10)) fertiCost = getFertilCost(int(lis[4],10)) totalCost = calculateBill(bushCost,fertiCost,flowerCost) printReciept(customerType,totalCost,bushCost,fertiCost,flowerCost) def inputData(): account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage = input("Please enter values").split() return [account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage] def convertAcct2String(accountType): if accountType== "P": return "Preferred" elif accountType == "R": return "Regular" elif accountType == "N": return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT