Author Topic: What does this red bar represent Verilog simulation.  (Read 4238 times)

0 Members and 1 Guest are viewing this topic.

Offline DmeadsTopic starter

  • Regular Contributor
  • *
  • Posts: 166
  • Country: us
  • who needs deep learning when you have 555 timers
What does this red bar represent Verilog simulation.
« on: May 24, 2019, 05:04:26 am »
Hi!

I was trying to make a latch in verilog.

This is my code from eda playground: https://www.edaplayground.com/x/2A7s

What does this red bar mean in the waveform viewer (see pic)? is it the stored bit?

 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11752
  • Country: us
    • Personal site
Re: What does this red bar represent Verilog simulation.
« Reply #1 on: May 24, 2019, 05:22:26 am »
Undefined state. This means that no defined value was assigned to that signal. This is normal for signals to be in this state before the reset.

In real life it will be stuck to some defined value, of course, but it may be random and unpredictable.

The beauty of it for simulation is that undefined value propagates through logic. So if you use that signal in some logic with other defined signals, the result will also be undefined. So if you see this red stuff in your design after a global reset, your reset was not really global :)
« Last Edit: May 24, 2019, 05:24:45 am by ataradov »
Alex
 
The following users thanked this post: Dmeads

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11752
  • Country: us
    • Personal site
Re: What does this red bar represent Verilog simulation.
« Reply #2 on: May 24, 2019, 05:26:26 am »
Also, what you are doing is not going to work in the actual hardware.
Alex
 

Offline DmeadsTopic starter

  • Regular Contributor
  • *
  • Posts: 166
  • Country: us
  • who needs deep learning when you have 555 timers
Re: What does this red bar represent Verilog simulation.
« Reply #3 on: May 24, 2019, 05:36:52 am »
the verilog wont work in the hardware? I know the test bench wont work because that uses non-synthesizable stuff right?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11752
  • Country: us
    • Personal site
Re: What does this red bar represent Verilog simulation.
« Reply #4 on: May 24, 2019, 05:48:36 am »
The main part won't work. You can't just transcribe the circuit from logic gates to Verilog and expect it to work.

Correct way to describe a D-latch would be something like this:
Code: [Select]
`timescale 1ns / 1ps
module d_latch(
  input clk,
  input reset,
  input CE,
  input D,
  output Q,
  output NQ
);

reg        V;

always @(posedge clk or posedge reset)
begin
  if (reset) begin
      V <= 1'b0;
  end else if (CE) begin
      V <= D;
  end
end

assign Q = V;
assign NQ = !V;
 
endmodule

You can adjust the polarity of the reset signal, or remove the clock enable (CE) signal if you want.

But the main thing here is to have a register value ("reg V") that represents the "stored" quantity. In the real world it happens though an essentially analog feedback process, which can't be replicated reliably in digital logic (especially in FPGAs).
« Last Edit: May 24, 2019, 05:51:57 am by ataradov »
Alex
 

Offline DmeadsTopic starter

  • Regular Contributor
  • *
  • Posts: 166
  • Country: us
  • who needs deep learning when you have 555 timers
Re: What does this red bar represent Verilog simulation.
« Reply #5 on: May 24, 2019, 05:56:39 am »
gotcha.

Just learned about Analog feedback processes.

Thanks for the code, I will mess around with it.

Also thanks for all your prior info. Digital logic/verilog/fpga stuff is not required for my major, and Im just learning it because I want to.

You have replied to a bunch of my previous posts, and you give some good feedback. It all helps my learning process.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3246
  • Country: ca
Re: What does this red bar represent Verilog simulation.
« Reply #6 on: May 25, 2019, 04:50:32 pm »
Also, what you are doing is not going to work in the actual hardware.

Not that this is a good idea, but you certainly can build latches from FPGA LUTs configured as NAND gates, and they will work.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11752
  • Country: us
    • Personal site
Re: What does this red bar represent Verilog simulation.
« Reply #7 on: May 25, 2019, 05:36:50 pm »
Not that this is a good idea, but you certainly can build latches from FPGA LUTs configured as NAND gates, and they will work.
But only if you manually instantiate FPGA primitives. No sane synthesizer will implement this exact Verilog code.
Alex
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3246
  • Country: ca
Re: What does this red bar represent Verilog simulation.
« Reply #8 on: May 25, 2019, 06:18:00 pm »
Not that this is a good idea, but you certainly can build latches from FPGA LUTs configured as NAND gates, and they will work.
But only if you manually instantiate FPGA primitives. No sane synthesizer will implement this exact Verilog code.

I'm not an expert in Verilog, but I've tried to create an RS latch with VHDL in Vivado, and it implemented it with two LUTs without problems (except a warning about combinatorial loop):

Code: [Select]
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity top is
  port (
    r_in: in std_logic;
    s_in: in std_logic;
    led_out: out std_logic
  ); 
end top;

architecture bhv of top is

  signal q, nq: std_logic;
     
begin
  led_out <= q;
  q <= not (not s_in and nq); 
  nq <= not (not r_in and q);
end bhv;
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11752
  • Country: us
    • Personal site
Re: What does this red bar represent Verilog simulation.
« Reply #9 on: May 25, 2019, 06:20:36 pm »
Things may have improved. I tried this at the time of ISE, and it errored on combinatorial loops like that. It may have been a more complicated scenario though. I have not tried a simple trigger like that, just by accident as part of a bigger system.
Alex
 

Offline romhunter

  • Regular Contributor
  • *
  • Posts: 104
  • Country: vn
Re: What does this red bar represent Verilog simulation.
« Reply #10 on: May 25, 2019, 07:39:23 pm »
Unrelated contribute though, if you want a latch in Verilog....
Code: [Select]
module SRLatch (
  input set,
  input reset,
  output q
);

  reg latch;
  always @(set or reset)
  begin
    if (set)
      latch <= 1'b1;
    else if (reset)
      latch <= 1'b0;
  end

  assign q = latch;

endmodule

Quartus did throw a warning about a latch, but it IS a latch...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf