`timescale 1 ns /  1 ps
module big_small_cnt ( 
clk       , 
rst       , 
clk_p     , 
start     , big_cnts  , 
small_cnts) ; 
parameter BIG_LENGTH= 16 'd8; 
parameter SMALL_LENGTH= 8 'd11; 
input clk, rst, clk_p, start; 
output [ 15 : 0 ]  big_cnts; 
output [ 7 : 0 ]  small_cnts; 
reg [ 7 : 0 ]  small_cnts; 
always @ ( posedge clk or posedge rst) 
beginif ( rst) beginsmall_cnts<= 8 'hff; endelse  if ( clk_p) beginif ( start) beginsmall_cnts<= 8 'd0; 	endelse  if ( ( small_cnts== SMALL_LENGTH- 1 ) && ( big_cnts< BIG_LENGTH- 1 ) ) beginsmall_cnts<= 8 'd0; 		endelse  if ( big_cnts<= BIG_LENGTH- 1 ) beginsmall_cnts<= small_cnts + 1 'b1; 			endelse beginsmall_cnts<= small_cnts; 		endendelse beginsmall_cnts<= small_cnts; 			end
end
reg [ 15 : 0 ]  big_cnts; 
always @ ( posedge clk or posedge rst) 
beginif ( rst) beginbig_cnts<= 16 'hffff; endelse  if ( ( start) && ( clk_p) ) beginbig_cnts<= 16 'd0; 	endelse  if ( ( small_cnts== SMALL_LENGTH- 1 ) && ( clk_p) ) beginbig_cnts<= big_cnts +  1 'b1; 		endelse beginbig_cnts<= big_cnts; 			end
end
endmodule`timescale 1 ns /  1 ps
module big_small_cnt ( clk             , rst             , start           , forward_cnts    , backward_cnts   ,  big_cnts        , small_cnts      , small_pulse_start, small_pulse_end, pulse_end
) ; parameter BIG_LENGTH= 16 'd8; 
parameter SMALL_LENGTH= 8 'd8; 
parameter COUNT =  BIG_LENGTH *  SMALL_LENGTH; input clk, rst, start; 
output [ 15 : 0 ]  forward_cnts, backward_cnts; 
output [ 15 : 0 ]  big_cnts; 
output [ 7  : 0 ]  small_cnts; 
output small_pulse_start; 
output small_pulse_end; 
output pulse_end; reg [ 15 : 0 ]  forward_cnts, backward_cnts; 
reg [ 15 : 0 ]  big_cnts; 
reg [ 7 : 0 ]  small_cnts; 
reg small_pulse_start, small_pulse_end, pulse_end; always @ ( posedge clk or posedge rst) 
beginif ( rst) beginforward_cnts<= 16 'hffff; endelse  if ( start) beginforward_cnts<= 16 'd0; 	endelse  if ( big_cnts<= BIG_LENGTH- 1 ) beginforward_cnts<= forward_cnts + 1 'b1; 			endelse beginforward_cnts<= forward_cnts; 		end
endalways @ ( posedge clk or posedge rst) 
beginif ( rst) beginbackward_cnts <=  16 'hffff; endelse  if ( start) beginbackward_cnts <=  COUNT- 1 'b1; 	endelse  if ( big_cnts<= BIG_LENGTH- 1 ) beginbackward_cnts<= backward_cnts- 1 'b1; 			endelse beginbackward_cnts<= backward_cnts; 		end
endalways @ ( posedge clk or posedge rst) 
beginif ( rst) beginsmall_cnts<= 8 'hff; endelse  if ( start) beginsmall_cnts<= 8 'd0; 	endelse  if ( ( small_cnts== SMALL_LENGTH- 1 ) && ( big_cnts< BIG_LENGTH- 1 ) ) beginsmall_cnts<= 8 'd0; 		endelse  if ( big_cnts<= BIG_LENGTH- 1 ) beginsmall_cnts<= small_cnts + 1 'b1; 			endelse beginsmall_cnts<= small_cnts; 		end
endalways @ ( posedge clk or posedge rst) 
beginif ( rst) beginsmall_pulse_start<= 1 'b0; endelse  if ( start) beginsmall_pulse_start<= 1 'b1; endelse  if ( ( small_cnts== SMALL_LENGTH- 1 ) && ( big_cnts< BIG_LENGTH- 1 ) ) beginsmall_pulse_start<= 1 'b1; 	endelse beginsmall_pulse_start<= 1 'b0; 	end
endalways @ ( posedge clk or posedge rst) 
beginif ( rst) beginsmall_pulse_end <=  1 'b0; endelse  if ( start) beginsmall_pulse_end <=  1 'b0; endelse  if ( small_cnts== SMALL_LENGTH- 2 ) beginsmall_pulse_end <= 8 'd1; 		endelse beginsmall_pulse_end <=  1 'b0; end
endalways @ ( posedge clk or posedge rst) 
beginif ( rst) beginbig_cnts<= 16 'hffff; endelse  if ( start) beginbig_cnts<= 16 'd0; 	endelse  if ( small_cnts== SMALL_LENGTH- 1 )  beginbig_cnts<= big_cnts +  1 'b1; 		endelse beginbig_cnts<= big_cnts; 			end
end
always @ ( posedge clk or posedge rst) 
beginif ( rst) beginpulse_end<= 1 'b0; endelse  if ( start) beginpulse_end <=  1 'b0; endelse  if ( ( small_cnts== SMALL_LENGTH- 1 )  &&  ( big_cnts== BIG_LENGTH- 1 ) )  beginpulse_end <=  1 'b1; endelse beginpulse_end <=  1 'b0; end
endendmodule
 
wire [ 15 : 0 ]  forward_cnts, backward_cnts; 
wire [ 15 : 0 ]  big_cnts; 
wire [ 7 : 0 ]  small_cnts; 
wire small_pulse_start, small_pulse_end; 
wire pulse_end; big_small_cnt
# (  . BIG_LENGTH ( 16 'd8) ,  . SMALL_LENGTH ( 16 'd3) ) 
big_small_cnt ( . clk                 ( clk) , . rst                 ( rst) , . start               ( cnts ==  8 'd10) , . forward_cnts        ( forward_cnts) , . backward_cnts       ( backward_cnts) , . big_cnts            ( big_cnts) , . small_cnts          ( small_cnts) , . small_pulse_start   ( small_pulse_start) , . small_pulse_end     ( small_pulse_end) , . pulse_end           ( pulse_end) 
) ;