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.

Always @ flop holding value when else is not specified

Status
Not open for further replies.

stanford

Full Member level 2
Joined
Feb 16, 2014
Messages
132
Helped
4
Reputation
8
Reaction score
6
Trophy points
1,298
Activity points
2,223
Let's say we have a flop declared like this. When we = 0, it is assumed that ram will hold its value, and when we = 1, the value will update to din. If we don't specify what happens with else, why does this construct implicitly loop the flop output into the input of the mux even though we haven't told it to?

Code:
always @ (posedge clk) begin
   if (we)
         ram[address] <= din;
end

Is below what the tool assumes it to be?

Code:
always @ (posedge clk) begin
   if (we)
         ram[address] <= din;
   else
         ram <= ram;
end
 

Yes, the tools assume the second code.

The same is true in VHDL.

we acts as an enable for the assignment statement so the assignment only occurs if that "enable" is high otherwise there is no assignment made, i.e. the value is not updated.

In the case of a RAM there is no feedback around a FF. The RAM cell at the address never gets written in the first place. It's more than likely if you add a explicit ram <= ram; assignment you'll end up not synthesizing RAM but will instead end up with a FF based memory.
 

Both are functionally identical but I'd say the first is the most accurate and the best coding style.

When there is no write enable there is no write. Ram doesn't get re-written to ram it just doesn't get written at all.

When writing synchronous flip-flops the style in the first example is fine and good.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top