Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Output Pins stuck at VCC? Code issue?

Status
Not open for further replies.

digi001

Full Member level 5
Joined
Apr 5, 2011
Messages
244
Helped
22
Reputation
44
Reaction score
21
Trophy points
1,298
Activity points
2,904
I am looking to latch an enable signal only when my fpga is addressed correctly and recieves a specific code. But i am having issues getting this to work. Is my code correct?

Here is my verilog:



module fpga_enable_version(xint,cs,rd,we,address,enable_o ut);

input cs;
input rd;
input we;
input [3:0]address;
output enable_out;
inout [15:0]xint;

reg enable_reg;

initial
begin
enable_reg=1'b0;
end

assign enable_out = enable_reg;


always @ (*)
begin
if (address==4'b0010 && cs==0 && we==0 && xint==16'b0000111100001111)
begin
enable_reg <= 1;
end
end


endmodule
 

Hi there,
I used Altera Quartus to draw the schematicd for your code. It looks as follows.
3_1318407065.png


---------- Post added at 10:19 ---------- Previous post was at 10:13 ----------

You should change your code to have some sequential element.

Code:
initial
begin
    enable_reg=1'b0;
end

assign enable_out = enable_reg;

always @ (negedge cs)
begin
   if (address==4'b0010 )
   begin
     enable_reg <= 1;
   end
end


---------- Post added at 10:22 ---------- Previous post was at 10:19 ----------

and the output will be
41_1318407743.png
 
  • Like
Reactions: digi001

    digi001

    Points: 2
    Helpful Answer Positive Rating
Yes! This is exactly what I tried yesterday and it works.

But i'm still not sure why I cant just have asynchronous logic that is triggered off the WRITE signal going low.
 

you can. But in your code enable_out goes to one and then never changes to zero. Hence why the output is always one.
 

But that is the functionality of a latch. Upon a certain condition...it goes to 1 and then never again goes to zero, except maybe a reset or something.

---------- Post added at 10:07 ---------- Previous post was at 10:06 ----------

sameh, how did you generate those pictures from Quartus?
 

Apart from the question if the design makes much sense, we should clarify why the synchronous implementation can be synthesiszed but the asynchronous can't. It's in fact not obvious at first sight. In my opinion, it has to do with the fact that the initial block can be only synthesized for synchronous logic respectively hardware registers.

It's implemented as power on reset of the FPGA. But the asynchronous latch can be only implemented as logic loop and in this case hasn't access to the interna POR signal. If you add however an explicite reset signal and wire it to the latch, then the latch can be synthesized.

Code:
if (reset ==1'b1)
  enable_reg <= 0;
else if (address==4'b0010 && cs==0 && we==0 && xint==16'b0000111100001111)
  enable_reg <= 1;

As an additional comment, IEEE Std 1364.1 that tries to standardize the synthesizable subset of the Verilog language tells:
The initial statement shall be supported only for ROM modeling as described in 5.6.2. It shall be ignored in all other contexts.
In so far the present practice to implement initial blocks as register power-up state is not complying to the new standard. It will be possibly kept as an option by those synthesis tools that supported it previously. But it emphasizes that you should better use explicite reset conditions.
 
Last edited:
You bring up a good point FvM. Does this also apply to register initialization?

I use a lot of this:

Code:
reg enable_reg = 0;

That way, after configuration I'm sure of the register state, without having to explicitely mess with power on reset signals. Your post now has me wondering if that's a good way to go about it. It seem to work just fine with ISE 10.x through 13.x so far (both synthesis and simulation), but maybe I am missing some of the finer details here...
 
  • Like
Reactions: digi001

    digi001

    Points: 2
    Helpful Answer Positive Rating
Initializers for registers work fine in most tools as far as I'm aware of. They surely work in Altera Quartus and I think Xilinx ISE as well, an dthere should be no functional difference between initial blocks and register definitions with initial value. I quoted 1364-1 mainly to show, that's it's not an obvious feature in synthesized logic. If tool designers intend to achieve compliance with IEEE 1364-1, they'll possibly provide a virtual POR signal that can be used to perform register resets. For th etime being, everything can be expected to work as we're knownt to.
 
  • Like
Reactions: digi001

    digi001

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top