Skip to content

Commit

Permalink
detect_lowest_high
Browse files Browse the repository at this point in the history
  • Loading branch information
RongyeL committed May 20, 2021
1 parent 8b96963 commit 5d86598
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 12 detect_lowest_high/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# detect_lowest_high <br />
Created : 2021-5-20<br />
Author : Rongye<br />
Description : detect lowest high bit<br />
<br />
**.zip is the vivado project.**
32 changes: 32 additions & 0 deletions 12 detect_lowest_high/detect_lowest_high.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
`timescale 1ns / 1ps
//==================================================================================================
// Filename : detect_lowest_high .v
// Created On : 2021-05-20
// Version : V 1.0
// Author : Rongye
// Description : detect lowest high bit
// Modification :
//
//==================================================================================================

module DETECT_LOWEST_HIGH(
// INPUTS
Din, // 128bits
// OUTPUTS
Dout // 8 bits, MSB = 1 =>none of 1
);
input [127:0] Din;
output [7:0] Dout;

reg [7:0] Dout;

integer i;
always@(*)begin
Dout = 8'b1000_0000;
for(i=127;i>=0;i=i-1)
if(Din[i]==1'b1)
Dout = i;
else
Dout = Dout;
end
endmodule
Binary file added 12 detect_lowest_high/detect_lowest_high.zip
Binary file not shown.
57 changes: 57 additions & 0 deletions 12 detect_lowest_high/detect_tb.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
`timescale 1ns / 1ps
`define Clock 20 // clock cycle
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2021/05/20 09:42:55
// Design Name:
// Module Name: DETECT_tb
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////


module DETECT_tb;
// INPUTS
reg [127:0] Din; // posedge active
// OUTPUTS
wire [7:0] Dout; // 8 bits

DETECT_LOWEST_HIGH DETECT_LOWEST_HIGH_inst (
.Din (Din ),
.Dout (Dout )
);

initial begin
#(`Clock*1);
Din = 128'd1213213; // 100101000001100011101 Dout = 0

#(`Clock*5);
Din = 128'd2223123513; // 10000100100000100010110000111001 Dout = 0

#(`Clock*5);
Din = 128'd2; // 10 Dout = 1

#(`Clock*5);
Din = 128'd4; // 100 Dout = 2

#(`Clock*5);
Din = 128'd8; // 1000 Dout = 3

#(`Clock*5);
Din = 128'd4444; // 1000101011100 Dout = 2

$stop;
end
endmodule

Binary file added 12 detect_lowest_high/sim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5d86598

Please sign in to comment.