Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
minmax Source File
1`timescale 1ns / 1ns
2
3// Simple always-on minmax finder, designed to be applied to ADC inputs.
4// reset is single-cycle, designed such that you can capture the outputs
5// on the same cycle as you apply the reset, resulting in no blind cycles.
6module minmax #(
7 parameter width=14
8) (
9 input clk,
10 input signed [width-1:0] xin,
11 input reset,
12 output signed [width-1:0] xmin,
13 output signed [width-1:0] xmax
14);
15
16reg signed [width-1:0] xin_d=0;
17reg signed [width-1:0] xmin_r={width{1'b1}};
18reg signed [width-1:0] xmax_r={width{1'b0}};
19wire signed [width-1:0] max_plus = {1'b0,{(width-1){1'b1}}};
20always @ (posedge clk) begin
21 xin_d<=xin;
22 xmax_r <= reset ? (xin_d) : (xin_d>xmax_r) ? xin_d : xmax_r;
23 xmin_r <= reset ? (xin_d) : (xin_d<xmin_r) ? xin_d : xmin_r;
24 //xmax_r <= reset ? (~max_plus) : (xin>xmax_r) ? xin : xmax_r;
25 //xmin_r <= reset ? ( max_plus) : (xin<xmin_r) ? xin : xmin_r;
26end
27assign xmax = xmax_r;
28assign xmin = xmin_r;
29
30endmodule