// Streaming edge detector: RGB in, Sobel magnitude and edge bit out, // one pixel per clock. Output pixel n of a frame belongs to input pixel n // and holds the Sobel result centred one line up and one pixel left. // Latency: 6 clocks (1 gray + 3 window + 2 Sobel). `timescale 1ns / 1ps module sobel_pipeline #( parameter int W = 640, parameter int H = 480, parameter int THRESH = 400 ) ( input logic clk, input logic rst, input logic in_valid, input logic in_sof, input logic [7:0] r, input logic [7:0] g, input logic [7:0] b, output logic out_valid, output logic out_sof, output logic [7:0] mag, output logic edge_out ); logic g_valid, g_sof, w_valid, w_sof, w_ok; logic [7:0] gray; logic [2:0][2:0][7:0] win; rgb_to_gray u_gray (.clk(clk), .rst(rst), .in_valid(in_valid), .in_sof(in_sof), .r(r), .g(g), .b(b), .out_valid(g_valid), .out_sof(g_sof), .gray(gray)); window3x3 #(.W(W), .H(H)) u_win (.clk(clk), .rst(rst), .in_valid(g_valid), .in_sof(g_sof), .pix(gray), .win_valid(w_valid), .win_sof(w_sof), .win_ok(w_ok), .win(win)); sobel #(.THRESH(THRESH)) u_sobel (.clk(clk), .rst(rst), .win_valid(w_valid), .win_sof(w_sof), .win_ok(w_ok), .win(win), .out_valid(out_valid), .out_sof(out_sof), .mag(mag), .edge_out(edge_out)); endmodule