Soft power/reset problem

Topics relating to PALs, CPLDs, FPGAs, and other PLDs used for the support or creation of 65-family processors, both hardware and HDL.
Post Reply
jbaum81
Posts: 25
Joined: 02 Jun 2021

Soft power/reset problem

Post by jbaum81 »

Good morning all,

Currently working with an ATF1508AS-7AX100 coding in Verilog on Quartus II 13.0 configured for a Max7000s EPM7128STC100-7.

The problem I'm running into is with my soft power/reset circuit. The reset works perfectly both with button interaction and power on reset. The problem is that the power signal either immediately shuts off, or doesn't come on at all when the commented line of the current code is enabled. I've broken it out to it's own counter and even it's own combinatorial process and even tried being liberal with the begin / end encapsulation all with the same results. I'm really stumped guys, any help would be appreciated.

The goal of this section of code is:
1.) On power up set the power signal to high
2.) on power up hold reset low for 1/10th of a second (8mhz clock)
3.) hold reset low while the button is held high.
4.) hold reset low for 1/10th of a second following a transition of high to low on the button
5.) Set the power signal to low when the button is depressed for 1 second.

Code: Select all

	reg _rst = 0;
	reg _pwrSig = 1;
	reg _pwrBtnLast = 0;
	reg [23:0] _pwrCnt = 0;

	assign pwrSig = (oe && _pwrSig) ? _pwrSig : 1'bz;
	assign rst = (oe && ~_rst) ? 1'b0 : 1'bz;
	
	
	always @(posedge clk) begin
		if (pwrBtn) begin
			_rst <= 0;
			if (~_pwrBtnLast) _pwrCnt <= 0;
			else _pwrCnt <= _pwrCnt + 1;
			//if (_pwrCnt >= 8000000) _pwrSig <= 0;
		end 
		else begin
			if (~_rst) begin
				if (_pwrBtnLast) _pwrCnt <= 0;
				else _pwrCnt <= _pwrCnt + 1;
				if (_pwrCnt >= 800000) _rst <= 1;
			end
		end		
		_pwrBtnLast <=pwrBtn;
	end



below is the full code just in case it's helpful.

Code: Select all

module JB6502ATF1508(
	input clk,
	input oe,
	input rw,
	input pwrBtn,
	input [7:0] adrBusLo,
	input [7:0] adrBusHi,
	input [7:0] datBus,
	output [5:0] rBanks,
	output v0En,
	output v1En,
	output rLow,
	output clkWr,
	output roEn,
	output raEn,
	output hr0En,
	output hr1En,
	output hr2En,
	output hr3En,
	output ioEn,
	inout datDir,
	output srlEn,
	output pwrSig,
	inout rst
	);
	
	wire _roEn;
	assign _roEn = (adrBusHi[7:6] == 2'b11) ? 1'b0 : 1'b1;
	assign roEn = (oe) ? _roEn : 1'bz;
	
	
	wire _hrEn;
	assign _hrEn = (adrBusHi[7:5] == 3'b101) ? 1'b0 : 1'b1;
	wire _hr0En;
	assign _hr0En = (_raBank[7:6] == 2'b00 && ~_hrEn) ? 1'b0 : 1'b1;
	assign hr0En = (oe) ? _hr0En : 1'bz;
	wire _hr1En;
	assign _hr1En = (_raBank[7:6] == 2'b01 && ~_hrEn) ? 1'b0 : 1'b1;
	assign hr1En = (oe) ? _hr1En : 1'bz;
	wire _hr2En;
	assign _hr2En = (_raBank[7:6] == 2'b10 && ~_hrEn) ? 1'b0 : 1'b1;
	assign hr2En = (oe) ? _hr2En : 1'bz;
	wire _hr3En;
	assign _hr3En = (_raBank[7:6] == 2'b11 && ~_hrEn) ? 1'b0 : 1'b1;
	assign hr3En = (oe) ? _hr3En : 1'bz;
	
	
	wire _ioEn;
	assign _ioEn = (adrBusHi == 8'b10011111) ? 1'b0 : 1'b1;
	assign ioEn = (oe) ? _ioEn : 1'bz;
	wire _v0En;
	assign _v0En = (~_ioEn && adrBusLo[7:4] == 4'b0000 ) ? 1'b0 : 1'b1;
	assign v0En = (oe) ? _v0En : 1'bz;
	wire _v1En;
	assign _v1En = (~_ioEn && adrBusLo[7:4] == 4'b0001 ) ? 1'b0 : 1'b1;
	assign v1En = (oe) ? _v1En : 1'bz;
	wire _srlEn;
	assign _srlEn = (~_ioEn && adrBusLo[7:4] == 4'b0110 ) ? 1'b0 : 1'b1;
	assign srlEn = (oe) ? _srlEn : 1'bz;
	assign datDir = (~_ioEn && _srlEn && _v0En && _v1En) ? 1'b0 : 1'bz;
	
	wire _raEn;
	assign _raEn = (_roEn && _hrEn && _ioEn) ? 1'b0 : 1'b1;
	assign raEn = (oe) ? _raEn : 1'bz;
	
	
	wire _rLow;
	assign _rLow = ~rw;
	assign rLow = (oe) ? _rLow : 1'bz;
	
	
	wire _clkWr;
	assign _clkWr = (~rw && clk) ? 1'b0 : 1'b1;
	assign clkWr = (oe) ? _clkWr : 1'bz;
	
	
	reg [7:0] _raBank = 0;
	reg [7:0] _roBank = 0;
	wire [5:0] _rBanks;
	assign _rBanks = (~_hrEn) ? _raBank[5:0] : _roBank[5:0];
	assign rBanks = (oe) ? _rBanks : 1'bz;
	
	always @(negedge clk) begin
		if (~rst)
			_raBank <= 0;
		else if (adrBusHi == 0 && adrBusLo == 0 && ~rw)
			_raBank <= datBus;
	end
	
	always @(negedge clk) begin
		if (~rst)
			_roBank <= 0;
		else if (adrBusHi == 0 && adrBusLo == 1 && ~rw)
			_roBank <= datBus;
	end
	
	
	reg _rst = 0;
	reg _pwrSig = 1;
	reg _pwrBtnLast = 0;
	reg [23:0] _pwrCnt = 0;

	assign pwrSig = (oe && _pwrSig) ? _pwrSig : 1'bz;
	assign rst = (oe && ~_rst) ? 1'b0 : 1'bz;
	
	
	always @(posedge clk) begin
		if (pwrBtn) begin
			_rst <= 0;
			if (~_pwrBtnLast) _pwrCnt <= 0;
			else _pwrCnt <= _pwrCnt + 1;
			if (_pwrCnt >= 8000000) _pwrSig <= 0;
		end 
		else begin
			if (~_rst) begin
				if (_pwrBtnLast) _pwrCnt <= 0;
				else _pwrCnt <= _pwrCnt + 1;
				if (_pwrCnt >= 800000) _rst <= 1;
			end
		end		
		_pwrBtnLast <=pwrBtn;
	end
	

endmodule
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Soft power/reset problem

Post by BigEd »

There could well be a verilog problem, but first off, have you any external debouncing of this button? Have you thought about what will happen if the button does bounce?

What happens if (when) the power counter wraps?

(If synthesis gives you any warnings, try to fix those first. And if you can run in simulation, that often helps.)
User avatar
BillO
Posts: 1038
Joined: 12 Dec 2008
Location: Canada

Re: Soft power/reset problem

Post by BillO »

Have you tried: if (_pwrCnt >= 8000000) _pwrSig = 0;

If I remember my verilog correctly writing it like that will force that line to wait until the state _pwrCnt has been settled. If not just ignore me..
Bill
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Soft power/reset problem

Post by BigEd »

I did once have a link to some handy-dandy rules for using the right kinds of assignments in the right places...

Maybe Nonblocking Assignments in Verilog Synthesis, Coding Styles That Kill! (pdf, 23 pages, 2000, Clifford E Cummings)
Quote:
Before giving further explanation and examples of both blocking and nonblocking assignments,
it would be useful to outline eight guidelines that help to accurately simulate hardware, modeled
using Verilog. Adherence to these guidelines will also remove 90-100% of the Verilog race
conditions encountered by most Verilog designers.
  • Guideline #1: When modeling sequential logic, use nonblocking assignments.
    Guideline #2: When modeling latches, use nonblocking assignments.
    Guideline #3: When modeling combinational logic with an always block, use blocking
    assignments.
    Guideline #4: When modeling both sequential and combinational logic within the same always
    block, use nonblocking assignments.
    Guideline #5: Do not mix blocking and nonblocking assignments in the same always block.
    Guideline #6: Do not make assignments to the same variable from more than one always block.
    Guideline #7: Use $strobe to display values that have been assigned using nonblocking
    assignments.
    Guideline #8: Do not make assignments using #0 delays.
Reasons for these guidelines are given throughout the rest of this paper.
Post Reply