data/full_repos/permissive/159096530/HPS_CONTROL_FPGA_LED/heartbeat.v
data/verilator_xmls/f61e4f50-a19c-4e1f-a413-06d27ff5fa7b.xml
module heartbeat(
output [31:0] output_reset,
input clk_50Mhz,
input [31:0] rst,
output gpio_out100hz,
output hbeat_out,
input [31:0] beat,
input e_stop
);


	reg [17:0] count_reg = 0;
	reg out_100hz = 0;
	

	reg beat_last = 0; 
	reg initial_loop = 1;
	reg beat_check = 0;
	reg [7:0] counter = 150;
	reg [31:0] temp_rst = 32'hFFFFFFFF;

	assign output_reset = temp_rst;
	assign gpio_out100hz = out_100hz;
	assign hbeat_out = beat_check;

	

	always @(posedge clk_50Mhz) 
	begin
		if (count_reg < 2499) begin
			count_reg <= count_reg + 18'h1;
		end 
		else begin
			count_reg <= 0;
			out_100hz <= ~out_100hz;
		end
	end
	


	always @(posedge out_100hz) 
	begin
		if ((beat_last != beat[0]) && (initial_loop == 0)) begin
			counter <= 0;
			beat_check <= !beat_check;

			if (e_stop == 1)
				temp_rst <= 32'hFFFFFFFF;
			else
				temp_rst <= 0|rst;
		end
		else begin
			counter <= counter + 1;
			if (counter >= 150) begin
				temp_rst <= 32'hFFFFFFFF;
				counter <= 8'h96;
				initial_loop <= 0;
			end
		end
		beat_last <= beat[0];
	end
	
	
endmodule
module heartbeat(
output [31:0] output_reset,
input clk_50Mhz,
input [31:0] rst,
output gpio_out100hz,
output hbeat_out,
input [31:0] beat,
input e_stop
);



	reg [17:0] count_reg = 0;
	reg out_100hz = 0;
	

	reg beat_last = 0; 
	reg initial_loop = 1;
	reg beat_check = 0;
	reg [7:0] counter = 150;
	reg [31:0] temp_rst = 32'hFFFFFFFF;

	assign output_reset = temp_rst;
	assign gpio_out100hz = out_100hz;
	assign hbeat_out = beat_check;

	

	always @(posedge clk_50Mhz) 
	begin
		if (count_reg < 2499) begin
			count_reg <= count_reg + 18'h1;
		end 
		else begin
			count_reg <= 0;
			out_100hz <= ~out_100hz;
		end
	end
	


	always @(posedge out_100hz) 
	begin
		if ((beat_last != beat[0]) && (initial_loop == 0)) begin
			counter <= 0;
			beat_check <= !beat_check;

			if (e_stop == 1)
				temp_rst <= 32'hFFFFFFFF;
			else
				temp_rst <= 0|rst;
		end
		else begin
			counter <= counter + 1;
			if (counter >= 150) begin
				temp_rst <= 32'hFFFFFFFF;
				counter <= 8'h96;
				initial_loop <= 0;
			end
		end
		beat_last <= beat[0];
	end
	
	
endmodule