0% found this document useful (0 votes)
22 views7 pages

Viza 3

Uploaded by

sashabaws
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Viza 3

Uploaded by

sashabaws
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Viza 3

Student: Petreanu Marius

Grupa: 4LF701

//
============================================================================
// Ver :| Author :| Mod. Date :| Changes Made:
// V1.1 :| Petreanu Marius :| 01/06/2023:| Added Verilog file
//
============================================================================

//=======================================================
// This code is generated by Terasic System Builder
//=======================================================

`define ENABLE_ADC_CLOCK
`define ENABLE_CLOCK1
`define ENABLE_CLOCK2
`define ENABLE_SDRAM
`define ENABLE_HEX0
`define ENABLE_HEX1
`define ENABLE_HEX2
`define ENABLE_HEX3
`define ENABLE_HEX4
`define ENABLE_HEX5
`define ENABLE_KEY
`define ENABLE_LED
`define ENABLE_SW
`define ENABLE_VGA
`define ENABLE_ACCELEROMETER
`define ENABLE_ARDUINO
`define ENABLE_GPIO

module DE10_LITE_Golden_Top(

//////////// ADC CLOCK: 3.3-V LVTTL //////////


`ifdef ENABLE_ADC_CLOCK
input ADC_CLK_10,
`endif
//////////// CLOCK 1: 3.3-V LVTTL //////////
`ifdef ENABLE_CLOCK1
input MAX10_CLK1_50,
`endif
//////////// CLOCK 2: 3.3-V LVTTL //////////
`ifdef ENABLE_CLOCK2
input MAX10_CLK2_50,
`endif

//////////// SDRAM: 3.3-V LVTTL //////////


`ifdef ENABLE_SDRAM
output [12:0] DRAM_ADDR,
output [1:0] DRAM_BA,
output DRAM_CAS_N,
output DRAM_CKE,
output DRAM_CLK,
output DRAM_CS_N,
inout [15:0] DRAM_DQ,
output DRAM_LDQM,
output DRAM_RAS_N,
output DRAM_UDQM,
output DRAM_WE_N,
`endif

//////////// SEG7: 3.3-V LVTTL //////////


`ifdef ENABLE_HEX0
output [7:0] HEX0,
`endif
`ifdef ENABLE_HEX1
output [7:0] HEX1,
`endif
`ifdef ENABLE_HEX2
output [7:0] HEX2,
`endif
`ifdef ENABLE_HEX3
output [7:0] HEX3,
`endif
`ifdef ENABLE_HEX4
output [7:0] HEX4,
`endif
`ifdef ENABLE_HEX5
output [7:0] HEX5,
`endif

//////////// KEY: 3.3 V SCHMITT TRIGGER //////////


`ifdef ENABLE_KEY
input [1:0] KEY,
`endif

//////////// LED: 3.3-V LVTTL //////////


`ifdef ENABLE_LED
output [9:0] LEDR,
`endif

//////////// SW: 3.3-V LVTTL //////////


`ifdef ENABLE_SW
input [9:0] SW,
`endif

//////////// VGA: 3.3-V LVTTL //////////


`ifdef ENABLE_VGA
output [3:0] VGA_B,
output [3:0] VGA_G,
output VGA_HS,
output [3:0] VGA_R,
output VGA_VS,
`endif
//////////// Accelerometer: 3.3-V LVTTL //////////
`ifdef ENABLE_ACCELEROMETER
output GSENSOR_CS_N,
input [2:1] GSENSOR_INT,
output GSENSOR_SCLK,
inout GSENSOR_SDI,
inout GSENSOR_SDO,
`endif

//////////// Arduino: 3.3-V LVTTL //////////


`ifdef ENABLE_ARDUINO
inout [15:0] ARDUINO_IO,
inout ARDUINO_RESET_N,
`endif

//////////// GPIO, GPIO connect to GPIO Default: 3.3-V LVTTL //////////


`ifdef ENABLE_GPIO
inout [35:0] GPIO
`endif
);

//=======================================================
// REG/WIRE declarations
//=======================================================

localparam DIGITS = 6;
//localparam WIDTH = $clog2(10**DIGITS - 1),
localparam WIDTH = 20;
//=======================================================
// REG/WIRE declarations
//=======================================================

//=======================================================
// Structural coding
//=======================================================

logic [DIGITS*4-1:0] bcd ;


logic [5:0][7:0] hex;
logic [DIGITS*4-1:0] result;

assign {HEX5, HEX4, HEX3, HEX2, HEX1,HEX0} = hex;

initial begin
integer i; // Declare 'i' as an integer variable
result[0] = 1'b0; // First position set to 0

for (i = 1; i < DIGITS*4; i = i + 1)


result[i] = 4'b1111;
end
bin_to_bcd #(
DIGITS,
WIDTH
) bin_to_bcd_inst0(
.bin_i (result),
.bcd_o ( bcd )
);

acumulator #( .WIDTH(WIDTH)
) acumulator_inst (
.clk_i ( MAX10_CLK1_50),
.rst_n ( KEY[1]),
.add_ni (KEY[0]),
.number_i(SW),
.result_o(result)

);

genvar i;
generate
for (i=0 ; i<DIGITS; i++) begin : GEN_7SEG
bin_to_7seg bin_to_7seg_inst0(
.bin_i(bcd[4*i+3 -: 4]),
.seg7_o(hex[i])
);

end
endgenerate

endmodule

module bin_to_bcd #(
DIGITS = 2,
WIDTH = $clog2(10**DIGITS - 1)
) (
input[WIDTH -1:0] bin_i,
output reg [DIGITS-1:0][3:0] bcd_o
);

always @(*) begin


integer i;
reg [WIDTH-1:0] tmp;
tmp = bin_i;
for (i = 0; i < DIGITS; i++) begin
if (tmp == 0 && i == 0)
bcd_o[i] = tmp;
else if (tmp == 0)
begin
bcd_o[i] = 4'b1111;
end
else
begin
bcd_o[i] = tmp%10;
end
tmp /= 10;
end
end

endmodule

module acumulator #(
WIDTH = 20
) (
input clk_i,
input rst_n,
input add_ni,
input [WIDTH-1:0] number_i,
output [WIDTH-1:0] result_o
);

logic add_nd;

always @(posedge clk_i or negedge rst_n) begin


if(!rst_n) begin
add_nd <= 1'b1;
end else begin
add_nd <= add_ni;
end

end

always @(posedge clk_i or negedge rst_n) begin

if(!rst_n)
result_o <= 'b0;
else if(add_nd && !add_ni)
result_o <= result_o + number_i;
end
endmodule
module bin_to_7seg (
input [3:0] bin_i,
output reg [7:0] seg7_o
);

always @(*) begin

case (bin_i)

0: seg7_o = 8'b11000000;
1: seg7_o = 8'b11111001;
2: seg7_o = 8'b10100100;
3: seg7_o = 8'b10110000;
4: seg7_o = 8'b10011001;
5: seg7_o = 8'b10010010;
6: seg7_o = 8'b10000010;
7: seg7_o = 8'b11111000;
8: seg7_o = 8'b10000000;
9: seg7_o = 8'b10010000;
default: seg7_o = 8'hFF;

endcase;

end
endmodule

You might also like