disadvantages of inferring latches

Some points:

Most Xilinx FPGA's have the ability to configure the fabric flops as a gated latch rather than an edge-triggered flop. These are quite robust latches and work as you might expect a gated latch to work. Xilinx's own XST synthesis is happy to infer them for you (with warnings, because as mentioned elsewhere, latch inference is often unintentional).

Even these beautiful hard gated latches will have problems if your code generates the enable signal using a combinatorial decode of several synchronous signals. Furthermore, the gate input needs to come from the clock pin of the slice. Since the gate signal is rarely a system clock line, you often lose a lot of slice logic because it cannot get another clock routed to the same slice. Probably not a big issue if you use a latch here or there in an otherwise synchronous design, but it makes a mostly asynchronous design very large in terms of slice footprint.

The same parts will fail miserably if you try to build asynchronous sequential logic using just the LUTs. One reason is that you cannot prevent the tools from removing coverage terms, short of directly instantiating the LUTs with your own INIT attributes (LUT contents).

Xilinx *does* guarantee that a LUT with one input switching will not glitch going from a 1 to a 1 or a 0 to a 0. There are no guarantees when multiple inputs switch mostly because it is impossible to route such that they switch at exactly the same time.

The timing analyzer also tends to be overly conservative when determining timing through a transparent latch. One of the points of the latch is that it can add to setup time at the next flop by passing through the input while the gate is "open." The tools however will look at the gate enable path as a worse case rather than the data, and in some cases falsely state that your timing will not work. This leads to a lot of hand analysis of the timing.

In general, the Xilinx tools are very solid and give reliable results when your design is completely synchronous.

--
Gabor
Reply to
GaborSzakacs
Loading thread data ...

I think that actually answered my question - it could be either depending on how you wanted it to work.

So basically, a register latches on a clock edge.

Suppose we have a memory mapped segment on a CPU that "goes to" a register bank in an FPGA. Are those bits latches/latched or not, or are they a mix?

--
Les Cargill
Reply to
Les Cargill

(snip on latch vs. register)

(snip)

In computer designs from the 1950's and 1960's, everything was latch, and they still worked. It takes a lot more transistors to make an edge-triggered master-slave FF, and transistors were expensive!

One interesting latch design from the 1960's is the Earle latch:

formatting link

As noted, in many cases you can combine two levels of logic with the logic of the latch. In a pipelined processor, that can make a big difference in how much logic you get at each stage, or at least did before the fast transistors that we have today.

-- glen

Reply to
glen herrmannsfeldt

I'm still not grasping the question. The issue of being memory mapped is not related to whether the memory is implemented as latches or registers. There are at least two issues here.

One is how you code the "memory". If you code it as a latch it will be a latch. The other is how such logic is actually implemented in the FPGA. If you just code memory (all such memory and other storage elements in an FPGA are edge triggered and so really are registers technically) how do they actually implement the memory in the FPGA? I don't know for sure. I see mention of 6 transistor RAM being the standard elements in processors for static memory, I expect that is also what they use for FPGA memories (not the registers used in the logic fabric). Then they likely fake the interface to work like a register or actually put registers in the address/data path and synthesize the timing controls for the RAM array invisibly to the user.

I remember when they stopped providing static RAM from the LUTs and made it edge sensitive. They had too many users who sucked at designing with async memory (which works like latches) and so just made it look like sync memory (which looks like registers). The info they provided basically said this was async memory with a faked out interface and they synthesized the write strobe for you.

Lol, I hope that isn't too confusing.

--

Rick
Reply to
rickman

No, not really. All they did was to make the clocking more complicated, unless they were using dynamic latches (capacitors) to store the digital value for a very short time resulting in a minimum clock rate.

To use latches you have to have at least two non-overlapping clocks and two sets of latches. That is exactly what an edge triggered FF is, two latches with non-overlapping clocks allowing the input to be held by the first latch and then before the gate opens again the value is stored into a second latch. The output changes when the second latch gate opens but at that point the input is already isolated so it appears as if the input is "clocked" into the register on the edge.

These early machines either used dynamic storage (which is *very* simple) or they were just splitting the register into two halves (each a latch) one on each clock phase (sometimes three or even four).

Yep

--

Rick
Reply to
rickman

(snip, I wrote)

Many of the early microprocessers used dynamic logic.

Also, some systems used dynamic shift registers for storage.

Don Lancaster's TV typewriter (the display part of a video terminal) uses 512 bit MOS shift registers to store the screen data.

Yes, but you can do:

(logic) (phase A latch) (logic) (phase B latch) ...

I never did figure out what to do with four phases, though.

-- glen

Reply to
glen herrmannsfeldt

Yes and the two latches is equivalent to a single register in terms of functionality and complexity. It doesn't save any timing. It just requires that you distribute two clock phases.

I expect this was mostly used with dynamic storage since that is always latches and not registers.

I can't say, but I still have a TMS9900 SBC with a four phase clock. I was rummaging in the basement the other day and found a TMS9995 CPU board I had built too. I don't think I ever got that one doing anything useful. I see it is hooked up to an old LCD display that came out of UPS trucks way back when.

I have enough old junk that I could start my own computer museum. But I already threw out my LSI-11, some 15 or more years ago. It was a heathkit with 8" floppy drives. I think that is why I ditched it. While an SBC is always relevant what am I going to do with RT-11 on floppy disks?

--

Rick
Reply to
rickman

(snip)

formatting link

-- glen

Reply to
glen herrmannsfeldt

The point of this thread isn't really that there's an inherent problem with latches. The issue is that FPGA's aren't designed to create asynchronous sequential logic. Folding a bunch of

2-input gates from your RTL into a LUT results in a huge change in the timing characteristics of the logic. Any structure that doesn't already exist in the slice or logic cell gets converted into LUTs. Trying to build an edge-triggered D flop from LUTs will fail just as miserably as an attempt to create latches that way. The older TI TTL catalogs had a schematic representation of a 7474 flip-flop that consists of 6 3-input NAND gates. Code that up in an FPGA and see what happens...
--
Gabor
Reply to
GaborSzakacs

?????? ??? ???, 17 ??????? 2014 11:17:04 UTC+2, ? ?? ronhk25:

t's very important avoiding them. I wonder what are the technical risks res ulting by using latches. As far as I understand, the main problem is that F PGAs don't have built in hard latches so the synthesizer has to implement i t from logic blocks and then the race condition in the resulting logic is h ard/impossible to be analyzed.

atches which shall be considered?

Thank you all for your answers! I would like to clarify- I didn't mean to combinatorial state machines, I m eant to a "multi-process synchronous state machine" while the output signal s and the next state are assigned in an asynchronic process and the current state is assigned in a synchronous process, i understand that this kind of state machine is defined as synchronous state machine. I'm not experienced with that kind of state machines as in the past I have always used one clo cked process in my state machines but in my new job I'm obliged to use the HDL designer graphical tool which generates those "multi-process synchronou s state machine". Now, as i wrote, the output signals are assigned in an as ynchronous process and in some states i want that some of the outputs will keep their last assigned value. In synchronous process this is not a problem since a flip flop is used but in asynchronous process an inferred latches might be created.

Those unintended latches made me open this thread, what are your recommenda tions to this issue?

Reply to
ronhk25

(snip, I wrote)

(snip)

I am at least slightly interested (though I might never get around to) recreating old designs in FPGA logic. Hardware emulation is just a little bit different from software emulation.

I believe it will also fail if you build it out of TTL gates.

Some of the schematics in the TTL data book are written with transistors, others with gates. Even so, I don't believe that all that are written with gates can be implemented with actual separate TTL gates. And yes, not in an FPGA, either.

-- glen

Reply to
glen herrmannsfeldt

No it won't. It will just be really slow compared to an actual

74xx74 chip of the same TTL family. Unlike the FPGA where the gates get lumped together into LUTs, the TTL 3-input NAND gates will be wired just like the diagram and keep the causality relationship between inputs and outputs. You can also make a working flip-flop using FPGA LUTs as individual 3-input NAND gates, but the tools will force you to instantiate the LUTs to prevent their being combined during optimization.

Reply to
GaborSzakacs

Assuming you really want to start editing the output of the generated code, the way to make this work is to feed the current state into the next state. i.e. anything on the right side of your assignments in the async process needs to come from the synchronous process. If something needs to keep its current value, then you need to assign it to the flop (in the other process) that holds that previous value. Assigning it to itself creates a gated latch.

--
Gabor
Reply to
GaborSzakacs

If your output has state that means it is part of the state logic rather than the output. If you need to "hold" an output while the rest of the state machine has moved on, you are not separating the state from the output.

I believe this is the difference between a Mealy and a Moore machine. In the Moore machine the output is only a function of state. In a Mealy machine the output is a function of both the state and the input. But in neither case is the output a function of the output.

So if you are getting latches in your output combinatorial logic it is because you either didn't code it correctly or you didn't specify it correctly.

Then there is a type of machine where the outputs are also registered rather than being pure combinatorial logic. In this case the logic can be coded in a synchronous process and no latch will be generated regardless.

--

Rick
Reply to
rickman

Right!

NO, that is great. I appreciate you taking the time - it's just something I always wondered. And right now, I am doing a project where it made me wonder more - how do you you make sure the interface is stable? I ended up basically burying it in a device driver so that at least CPU interrupts were off.

This isn't an FPGA; it's a simulated FPGA. So I can read or write to the "memory" atomically. I was gonna do it with a mechanism like System V shared memory, but I wasn't sure this had the right ... atomicity of read/write. It smelt like a Heisenbug waiting to happen.

Apologies for the inability to actually ask the question properly - but I think the salient distinction is "edge triggered" vs. "level sensitive". The rest follows from that.

--
Les Cargill
Reply to
Les Cargill

Ok, glad I could help.

--

Rick
Reply to
rickman

I'm surprised at that statement. Have you never used a counter or anything else related to a clock or flip-flop?

Perhaps the secret with any HDL is to consider how code will be implemented in the hardware?

--
Mike Perkins 
Video Solutions Ltd 
www.videosolutions.ltd.uk
Reply to
Mike Perkins

Rick was using the fairly common distinction of a "latch" to mean a transparent latch with a level-sensitive gate, and a "register" or "flip-flop" to mean a storage element that's edge sensitive.

Sorry to be curt, but this thread has spun far too far off into semantics, and finally just resolved with people agreeing. We can't go back down that rabbit hole, all the rabbits have rabies and halitosis.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com 
Email address domain is currently out of order.  See above to fix.
Reply to
Rob Gaddi

It may be a common distinction among many, but latches in FPGA parlance is generally any circuit or code that retains a signal (or level). Intended or otherwise.

I also accept that transparent latches are not used as often as any other type of 'latch', but there are times when it prudent to use a "Write Enable" in its intended manner.

--
Mike Perkins 
Video Solutions Ltd 
www.videosolutions.ltd.uk
Reply to
Mike Perkins

Can you tell us about the last time you used a latch rather than a register?

--

Rick
Reply to
rickman

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.