//--------------------------------------------------------------------------------------------------
//
// Title       : PwrCtrl
// Design      : U4
// Author      : mbari###
// Company     : MBARI
//
//-------------------------------------------------------------------------------------------------
//
// File        : c:\Projects\genosensor\2g\CPLDs\Core\U4\src\PwrCtrl.v
// Generated   : Thu Dec 18 09:05:49 2003
// From        : interface description file
// By          : Itf2Vhdl ver. 1.20
//
//-------------------------------------------------------------------------------------------------
//
// Description : 
//
//-------------------------------------------------------------------------------------------------
`timescale 1ps / 1ps

//{{ Section below this comment is automatically maintained
//   and may be overwritten
//{module {PwrCtrl}}
module PwrCtrl ( Enc5ctrl ,Reset ,PWRint ,Home33ctrl ,Enc5FLG ,Mclk ,Home33FLG ,DCORENCPWRr ,DCORENCPWRw ,DCORIFGr ,inDATA ,Enc33ctrl ,outDATA ,Home5ctrl ,Enc33FLG ,DCORIFGw ,Home5FLG );

input DCORIFGr ;
wire DCORIFGr ;
input [3:0] inDATA ;
wire [3:0] inDATA ;
input Reset ;
wire Reset ;
input Enc5FLG ;
wire Enc5FLG ;
input DCORIFGw ;
wire DCORIFGw ;
input Enc33FLG ;
wire Enc33FLG ;
input Home5FLG ;
wire Home5FLG ;
input Mclk ;
wire Mclk ;
input Home33FLG ;
wire Home33FLG ;
input DCORENCPWRr ;
wire DCORENCPWRr ;
input DCORENCPWRw ;
wire DCORENCPWRw ;

output Enc5ctrl ;
wire Enc5ctrl ;
output Enc33ctrl ;
wire Enc33ctrl ;
output [3:0] outDATA ;
wire [3:0] outDATA ;
output Home5ctrl ;
wire Home5ctrl ;
output PWRint ;
wire PWRint ;
output Home33ctrl ;
wire Home33ctrl ;

//}} End of automatically maintained section

// -- Enter your statements here -- //


//assign RDslct = (!AS & RD & !WR & (ADDR == 8'h05));
reg [3:0] ctrlr;
reg DCORIFG;

assign outDATA = (DCORENCPWRr) ? {Enc5FLG, Enc33FLG, Home5FLG, Home33FLG} : 4'bz;
assign Enc5ctrl = !ctrlr[3] | (ctrlr[2] & ctrlr[3]);	   //this is reguired since the register power up low
assign Enc33ctrl = !ctrlr[2] | (ctrlr[2] & ctrlr[3]);     //this will cause the output to begin high and power off!
assign Home5ctrl = !ctrlr[1] | (ctrlr[1] & ctrlr[0]);    //this forces both off if both are tried to turn on
assign Home33ctrl = !ctrlr[0] | (ctrlr[1] & ctrlr[0]);   //not a good condition if both are on at the same time!

always @ (posedge Mclk)
	begin
		if (Reset) DCORIFG <= 1'b0;
		else if (DCORIFGw) DCORIFG <= inDATA[1];
		else DCORIFG <= DCORIFG;
	end							
	
always @ (posedge Mclk or posedge Reset)//added to make reset async to shut off when reset high
	begin
		if (Reset) ctrlr <= 4'b0;
		else if (DCORENCPWRw) ctrlr <= {inDATA[3], inDATA[2], inDATA[1], inDATA[0]};
	end
endmodule
