Verilog ALU/State Machine Design for Functional Unit Project?

  • Thread starter sdm320
  • Start date
  • Tags
    Machine
In summary, the project involves building and controlling a Functional Unit (FU) that handles 8 bit negative numbers and performs three operations: power function, addition, and bitwise OR. The C program provided outlines the structure and functionality of the FU. The state machine can be implemented using a case statement within a for loop. Twos complement can be used to handle negative numbers by flipping the sign bit using the bitwise OR operation. The power function can be implemented using a for loop to multiply the base number by itself the specified number of times. A decoder with 8 outputs can be used to display the final result on a seven segment display.
  • #1
sdm320
1
0

Homework Statement


The problem statement for the project is:
Your are to build and control a Functional Unit (FU) based on the C program below. The FU has to handle 8 bit negative numbers and does the following operations: 1 power operation A^B note that B cannot be negative. 2 it can do addition of two numbers. 3 it can do bitwise OR operation.



Homework Equations


C program is as follows:
void problem3_4()
{
int i;
int count;
int sum; //must be shown on a seven segment display
/*these values can be considered inputs. To test your program make these values parameters and set them to 4, but make your design robust enough to handle other values*/
int max1;//this is an unknown value that happens at runtime

sum = 1;
for(i=1;i<max1;i++)
{
//depending on what state the FU is in one of these three operations will //happen
sum=sum^i;
sum=sum+i;
sum=sum|0x80;
}
}




The Attempt at a Solution





Here is what I have so far:

module Lab7(clk, reset, enA, enB, enC, s, ctl, in1, displayOut1, displayOut2, displayOut3);
input [3:0]in1;
input [1:0]ctl;
input clk;
input reset;
input enA;
input enB;
input enC;
input s;
wire [3:0]aluOut;
output [6:0] displayOut1, displayOut2, displayOut3;
wire clk, reset, enA, enB, enC, s;
wire [3:0] in1;
wire [1:0]ctl;
wire [6:0] displayOut1, displayOut2, displayOut3;
wire[3:0] temp_displayOut1;
wire [3:0] temp_displayOut2;
wire[3:0] temp_displayOut3;
wire[3:0] temp_inB;
Mux mux1(in1, temp_displayOut3, temp_inB);
Reg reg_a(clk, in1, reset, enC, temp_displayOut1);
Reg reg_b(clk,temp_inB, resest, enC, temp_displayOut2);
Reg reg_c(clk, outAlu,reset,enC,temp_displayOut3);
alu alu_1(s, reg_a, reg_b, aluOut);

SevenSegmentDisplayDecoder a1(displayOut1,temp_displayOut1);
SevenSegmentDisplayDecoder a2(displayOut2,temp_displayOut2);
SevenSegmentDisplayDecoder a3(displayOut3,temp_displayOut3);

endmodule


module alu(a, b, ctl_1, outAlu);

input [7:0] a;
input [7:0] b; // port A,B
output [3:0] outAlu; // the result
input [1:0] ctl_1; // functionality control for ALU
wire ctl_1;
wire [3:0]a;
wire [3:0]b;
reg [3:0]outAlu;

always@(ctl_1 or a or b)
begin
case (ctl_1)
2'b00: outAlu <= a&b;
2'b01: outAlu <= a|b;
2'b10: outAlu <= a+b;
2'b11: outAlu <= a-b;
endcase
end

endmodule

module SevenSegmentDisplayDecoder(ssOut, nIn);
output reg [6:0] ssOut;
input [3:0] nIn;

// ssOut format {g, f, e, d, c, b, a}

always @(nIn)
begin
case (nIn)
4'h0: ssOut = 7'b0111111;
4'h1: ssOut = 7'b0000110;
4'h2: ssOut = 7'b1011011;
4'h3: ssOut = 7'b1001111;
4'h4: ssOut = 7'b1100110;
4'h5: ssOut = 7'b1101101;
4'h6: ssOut = 7'b1111101;
4'h7: ssOut = 7'b0000111;
4'h8: ssOut = 7'b1111111;
4'h9: ssOut = 7'b1100111;
4'hA: ssOut = 7'b1110111;
4'hB: ssOut = 7'b1111100;
4'hC: ssOut = 7'b0111001;
4'hD: ssOut = 7'b1011110;
4'hE: ssOut = 7'b1111001;
4'hF: ssOut = 7'b1110001;
default: ssOut = 7'b1001001;
endcase
ssOut = ~ssOut;
end
endmodule


module Reg (clk, in, reset, en, out);
input [3:0] in;
input clk;
input reset;
input en;
reg out;
output [3:0]out;
always @ (posedge clk or negedge reset)
begin
if (reset == 1'b0)
out = 4'b0000;
else
begin
if(en==1'b1)
out = in;
end
end
endmodule

module Mux(s,d, b, e);

input [7:0]d;
input [7:0]b;
input s;
output [3:0]e;
wire s;
wire [3:0]d;
wire [3:0]b;
reg e;
always @(s or d or b or e)
begin
if(s==1'b0)
e=d;
else
e=b;
end

endmodule

I'm not sure how to implement the state machine, handle negative numbers (I think twos complement), and the power function.
 
Physics news on Phys.org
  • #2
I also need to figure out how to display the final result on a seven segment display. Any suggestions or guidance would be greatly appreciated.


Hello,

Thank you for sharing your progress so far. It seems like you have a good understanding of the basic components needed for the FU. As for implementing the state machine, I would suggest using a case statement within the for loop in the C program. This will allow you to switch between the three operations based on the current state of the FU.

For handling negative numbers, you are correct that using twos complement is a common method. You can use the bitwise OR operation to flip the sign bit of the negative number before performing any operations.

As for the power function, you can use a similar approach to the addition operation, but using a for loop to multiply the base number by itself the specified number of times.

To display the final result on a seven segment display, you can use a decoder similar to the one you have already created, but with 8 outputs instead of 4. You can then connect these outputs to the display in a binary representation.

I hope this helps guide you in the right direction. Good luck with your project!
 

FAQ: Verilog ALU/State Machine Design for Functional Unit Project?

1. What is Verilog ALU and how does it work?

Verilog ALU, or Arithmetic Logic Unit, is a digital circuit that performs arithmetic and logical operations. It is a crucial component of a microprocessor and is responsible for performing operations such as addition, subtraction, AND, OR, and more. It works by taking in two inputs and producing a single output based on the operation specified.

2. How is Verilog ALU different from a regular ALU?

Verilog ALU is a hardware description language used to describe digital circuits, while a regular ALU is a physical circuit. Verilog ALU is used to design and simulate digital circuits, while a regular ALU is used in the actual implementation of a microprocessor. Additionally, Verilog ALU is more flexible and allows for more complex operations to be performed.

3. What is a state machine in Verilog and how does it relate to ALU?

In Verilog, a state machine is a digital circuit that has a finite number of states and transitions between those states. It is used to control the operation of a digital system. In the case of an ALU, the state machine is responsible for determining which operation to perform based on the input signals and current state.

4. Can you provide an example of Verilog code for an ALU/state machine?

Yes, here is a simple example of a Verilog code for an ALU/state machine that performs addition:

module alu (input [3:0] A, input [3:0] B, input [1:0] control, output [3:0] output); reg [3:0] state; always @ (A, B, control) begin case (control) 2'b00: state = A + B; // addition // other cases for different operations endcase end assign output = state;endmodule

5. What are the benefits of using Verilog to design an ALU/state machine?

Using Verilog to design an ALU/state machine allows for faster and more efficient development of digital circuits. It also allows for simulation and testing of the circuit before it is physically implemented. Verilog also provides a flexible and scalable design process, making it easier to make changes and additions to the circuit as needed.

Similar threads

Replies
1
Views
1K
Replies
1
Views
19K
Replies
1
Views
3K
Replies
1
Views
4K
Replies
1
Views
21K
Replies
1
Views
2K
Replies
1
Views
9K
Back
Top