module HVCounterBit (PCLK, n_PCLK, CLR, RES, cin, val, n_val, cout);

	input PCLK;
	input n_PCLK;
	input CLR;
	input RES;
	input cin;
	output val;
	output n_val;
	output cout;

	wire keep_latch_q;

	dlatch keep_latch (.d(cin ? val : n_val), .en(n_PCLK), .q(keep_latch_q) );
	dlatch out_latch (.d(PCLK ? ~(keep_latch_q | CLR) : val), .en(1'b1), .nq(n_val) );

	assign val = ~(n_val | RES);
	assign cout = ~(n_val | ~cin);

endmodule // HVCounterBit