Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16598 Discussions

Cleaning up latch warnings

Altera_Forum
Honored Contributor II
1,060 Views

I am trying to build an SPI interface on a Max II device. I want to latch the shift-register data into my control bits when CS is low, like this: 

 

reg shift = 0; always @(posedge sclk) if (cs) shift <= {shift, sin}; reg run, busy, mode; always @* if (!cs) begin run = shift; busy = shift == 2'b11 || shift == 2'b10; mode = shift == 2'b11; end This code produces exactly the logic I want when I check its output in the RTL viewer. The problem is that my build log is full of warnings like these: 

 

 

--- Quote Start ---  

 

Warning (10240): Verilog HDL Always Construct warning at spi.v(66): inferring latch(es) for variable "run", which holds its previous value in one or more paths through the always construct 

--- Quote End ---  

 

--- Quote Start ---  

Warning: Timing Analysis is analyzing one or more combinational loops as latches 

--- Quote End ---  

I come from a software development background where the goal is to have a warning-free build. Is there any way to tell Quartus, "Yes, I really do want latches here. Please don't warn me about this anymore?" That way, if I really do create an unintended latch later on in the project, the real warning doesn't get lost in the noise. 

 

Maybe latches are frowned upon on these chips, and I should use edge-triggered registers instead? I can get rid of most of them, but there are a few places where I really and truly do need latches to avoid timing glitches.
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
349 Views

 

--- Quote Start ---  

Maybe latches are frowned upon on these chips, and I should use edge-triggered registers instead? 

--- Quote End ---  

You definitely should. Something like: 

reg shift = 0; reg run, busy, mode; always @(posedge sclk) begin if (cs) shift <= {shift, sin}; else begin run = shift; busy = shift == 2'b11 || shift == 2'b10; mode = shift == 2'b11; end end  

will work just fine. As for disabling unwanted messages, you can right-click on a message(s) and select "Suppress selected messages".
0 Kudos
Altera_Forum
Honored Contributor II
349 Views

 

--- Quote Start ---  

As for disabling unwanted messages, you can right-click on a message(s) and select "Suppress selected messages". 

--- Quote End ---  

 

 

Thanks, that is exactly what I was looking for! I also went ahead and replaced some of the latches with registers as you advised.
0 Kudos
Reply