sample and hold without latch infered

Status
Not open for further replies.

hulk789

Junior Member level 3
Joined
Jul 18, 2015
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
211
Code:
always @ (sample,inp) begin
         if(sample==0 ) begin
             vinp=vinp;
         end
         else begin
             vinp=inp;
         end
    end

is it possible to not infer a latch for a sample and hold type of code in synthesis.
 

No. Anything that has memory will infer a latch.
 

is it possible to not infer a latch for a sample and hold type of code in synthesis.

Yes, a flip flop.

Kevin Jennings

- - - Updated - - -

No. Anything that has memory will infer a latch.
You know better than that. Flip flops are memory and they are not a latch (in the context of what a designer would describe and use, not what a flip flop is at the transistor level).

Kevin
 
Anything that has memory will infer a latch.
Should be read "A memory in combinational always block". I guess.

There are some applications where you intentionally infer a latch, e.g. in some cases, a transparent latch is better suited as address register in a multiplexed processor bus than a flip-flop.
 

And the code specified by the OP is a latch


Code Verilog - [expand]
1
2
3
4
5
6
7
8
always @ (sample,inp) begin // combinational code as FvM mentioned
         if(sample==0 ) begin
             vinp=vinp;  // memory as Tricky mentions
         end
         else begin
             vinp=inp;
         end
    end



Without a posedge or negedge sensitivity on a signal the always block will always infer either combinational logic or a latch (if any outputs are fed back or not defined in a branch).
 
Reactions: dpaul

    dpaul

    Points: 2
    Helpful Answer Positive Rating
And the code specified by the OP is a latch
Yes the OP posted code for a latch, but the question the OP posted is can you not infer a latch for a sample and hold. The answer there is yes, use a flip flop.

Kevin
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…