Re: Concat with a constant

Christopher Felton <[email protected]>
Newsgroups gmane.comp.python.myhdl
Message-ID <[email protected]>
On 5/22/2015 7:07 AM, Henry Gomersall wrote:
> Is there some neat way to concatenate a signal with a constant?
>

You can't simply concatenate with a constant that
is a Python `int` because it doesn't have a bit
length that MyHDL uses, the constant would need to
be an `intbv` or `bool`.

http://docs.myhdl.org/en/latest/manual/reference.html?highlight=concat#myhdl.concat

If we had initial values you could use constants
assigned outside the generators (see below).  The
best approach I can think of is to assign the constant
to a variable and then concat.

     # MYHDL
     def m_concat_const(x, y):
        # CONST1 will not work because initial values
        # is not enabled ...
        CONST1 = intbv(10, min=0, max=137)
        CONST2 = 5

        @always_comb
        def rtl():
            const2 = intbv(5, min=0, max=8)  # or intbv(CONST2 ...)?
            y.next = concat(x[4:0], CONST1, const2)
        return rtl


     # Converted VHDL
     M_CONCAT_CONST_RTL: process (x) is
         variable CONST1: unsigned(7 downto 0);
         variable const2: unsigned(2 downto 0);
     begin
         const2 := to_unsigned(5, 3);
         y <= resize(unsigned'(x & CONST1 & const2), 12);
     end process M_CONCAT_CONST_RTL;


If you want to concat outside of a generator (elaboration)
then you would want to review the thread @josyb
referenced.

You can use ConcatSignal where one of the signals is
simply assigned to the constant:

     Sig1 = ...
     Sig2 = ...
     Sig3 = ConcatSignal(Sig1, Sig2)

     @always_comb
     def assign():
         Sig2.next = CONSTANT

Hope that helps,
Chris


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.