\title{Digital Latches with myHDL} \author{Steven K Armour} \maketitle
@book{brown_vranesic_2014, place={New York, NY}, edition={3}, title={Fundamentals of digital logic with Verilog design}, publisher={McGraw-Hill}, author={Brown, Stephen and Vranesic, Zvonko G}, year={2014} }, @book{lameres_2017, title={Introduction to logic circuits & logic design with Verilog}, publisher={springer}, author={LaMeres, Brock J}, year={2017} }
In [1]:
import numpy as np
import pandas as pd
from sympy import *
init_printing()
from myhdl import *
from myhdlpeek import *
import random
#python file of convince tools. Should be located with this notebook
from sympy_myhdl_tools import *
Latches and Flip-Flops are both metastaple logic circuit tobologies in that once loaded with a state they hold that state information till that state is upset by a new state or a reset command. But the diffrance between the two is that Flip-Flops are clock controlled devices built upon Latches where as Latches are not clock dependent
Need Help Getting this Latch via Combo Cirucits working geting AlwayCombError in using out signal as argument in out signals next state out
In [ ]:
In [2]:
def SRLatch(S_in, rst, Q_out, Qn_out):
@always_comb
def logic():
if S_in and rst==0:
Q_out.next=1
Qn_out.next=0
elif S_in==0 and rst:
Q_out.next=0
Qn_out.next=1
elif S_in and rst:
Q_out.next=0
Qn_out.next=0
return logic
In [3]:
S_in, rst, Q_out, Qn_out=[Signal(bool(0)) for _ in range(4)]
Peeker.clear()
Peeker(S_in, 'S_in'); Peeker(rst, 'rst')
Peeker(Q_out, 'Q_out'); Peeker(Qn_out, 'Qn_out')
DUT=SRLatch(S_in=S_in, rst=rst, Q_out=Q_out, Qn_out=Qn_out)
inputs=[S_in, rst]
sim=Simulation(DUT, Combo_TB(inputs), *Peeker.instances()).run()
Peeker.to_wavedrom(start_time=0, stop_time=2*2**len(inputs), tock=True,
title='SRLatch Behavioral simulation',
caption=f'after clock cycle {2**len(inputs)-1} ->random input')
In [4]:
MakeDFfromPeeker(Peeker.to_wavejson(start_time=0, stop_time=2**len(inputs) -1))
Out[4]:
In [5]:
toVerilog(SRLatch, S_in, rst, Q_out, Qn_out)
#toVHDL(SRLatch, S_in, rst, Q_out, Qn_out)
_=VerilogTextReader('SRLatch')
The following shows the Xilinx's Vivado 2016.1 RTL generated schematic of our Behaviorla SRLatch from the synthesised verilog code. We can see that the systhizied version is quite apstract from fig lakdfjkaj.
In [6]:
def GSRLatch(S_in, rst, ena, Q_out, Qn_out):
@always_comb
def logic():
if ena:
if S_in and rst==0:
Q_out.next=1
Qn_out.next=0
elif S_in==0 and rst:
Q_out.next=0
Qn_out.next=1
elif S_in and rst:
Q_out.next=0
Qn_out.next=0
else:
pass
return logic
In [7]:
S_in, rst, ena, Q_out, Qn_out=[Signal(bool(0)) for _ in range(5)]
Peeker.clear()
Peeker(S_in, 'S_in'); Peeker(rst, 'rst'); Peeker(ena, 'ena')
Peeker(Q_out, 'Q_out'); Peeker(Qn_out, 'Qn_out')
DUT=GSRLatch(S_in=S_in, rst=rst, ena=ena, Q_out=Q_out, Qn_out=Qn_out)
inputs=[S_in, rst, ena]
sim=Simulation(DUT, Combo_TB(inputs), *Peeker.instances()).run()
Peeker.to_wavedrom(start_time=0, stop_time=2*2**len(inputs), tock=True,
title='GSRLatch Behavioral simulation',
caption=f'after clock cycle {2**len(inputs)-1} ->random input')
In [8]:
MakeDFfromPeeker(Peeker.to_wavejson(start_time=0, stop_time=2**len(inputs) -1))
Out[8]:
In [9]:
toVerilog(GSRLatch, S_in, rst, ena, Q_out, Qn_out)
#toVHDL(GSRLatch, S_in, rst,ena, Q_out, Qn_out)
_=VerilogTextReader('GSRLatch')
The following shows the Xilinx's Vivado 2016.1 RTL generated schematic of our Behaviorla Gated SRLatch from the synthesised verilog code. We can see that the systhizied version is quite apstract from fig lakdfjkaj.
In [10]:
def DLatch(D_in, ena, Q_out, Qn_out):
#Normal Qn_out is not specifed since a not gate is so easily implimented
@always_comb
def logic():
if ena:
Q_out.next=D_in
Qn_out.next=not D_in
return logic
In [11]:
D_in, ena, Q_out, Qn_out=[Signal(bool(0)) for _ in range(4)]
Peeker.clear()
Peeker(D_in, 'D_in'); Peeker(ena, 'ena')
Peeker(Q_out, 'Q_out'); Peeker(Qn_out, 'Qn_out')
DUT=DLatch(D_in=D_in, ena=ena, Q_out=Q_out, Qn_out=Qn_out)
inputs=[D_in, ena]
sim=Simulation(DUT, Combo_TB(inputs), *Peeker.instances()).run()
Peeker.to_wavedrom(start_time=0, stop_time=2*2**len(inputs), tock=True,
title='DLatch Behavioral simulation',
caption=f'after clock cycle {2**len(inputs)-1} ->random input')
In [12]:
MakeDFfromPeeker(Peeker.to_wavejson(start_time=0, stop_time=2**len(inputs) -1))
Out[12]:
In [13]:
toVerilog(DLatch, D_in, ena, Q_out, Qn_out)
#toVHDL(DLatch,D_in, ena, Q_out, Qn_out)
_=VerilogTextReader('DLatch')
The following shows the Xilinx's Vivado 2016.1 RTL generated schematic of our myHDL Dlatch with a exsplisit $\bar{Q}$ verilog code. Note that becouse $\bar{Q}$ is not normal declared in HDL code Vivado produced two RTL DLatchs and used a NOT Gate to acount for the negated output