# How-to ? : Internal signals of same type than external ones

**URL:** <https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147>\
**Category:** Support\
**Created:** [January 12, 2017, 9:16am UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147 "2017-01-12T09:16:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [January 12, 2017, 9:16am UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147/1 "2017-01-12T09:16:12Z")

</div>

I have written a “deglitch” component that I’d like to be “universal” : The component should be able to interface with boolean or bit-vector signals.

```python
class deglitch():This text will be hidden
    def __init__ (self, deglitch_delay, initial_output=None):
        self.deglitch_delay = deglitch_delay
        self.initial_output = initial_output

    @block
    def inst(self, i_Clk, i_Data, o_Data):

        DataSync = Signal(i_Data.val)
        DataMemo = Signal(i_Data.val)
        Counter = Signal(intbv(0, min=0, max=self.deglitch_delay+1))
        DataOut = Signal(o_Data.val)

        @always_seq(posedge(i_Clk), reset=None)
        def proc():
            DataSync.next = i_Data
            DataMemo.next = DataSync
            
            if DataMemo != DataSync :
                Counter.next = 0
            else :
                if Counter == self.deglitch_delay :
                    Counter.next = 0
                else :
                    Counter.next = Counter + 1
                
                if Counter == self.deglitch_delay-1 :
                    DataOut.next = DataMemo
                    #o_Data.next = DataMemo
            
        @always_comb
        def logic():
            o_Data.next = DataOut
        
        return proc, logic

```

My problem is with internal signals that need to adapt themselves to external signals : DataSync, DataMemo and DataOut type must be the same than i\_Data and o\_Data.  
I tried many syntaxes and ended with “DataSync = Signal(i\_Data.val)”.  
This syntax works with simulation and VHDL conversion.

I’m not very comfortable with this syntax.

1. Is this the right way of writing ?
2. Using this syntax, I can’t specify an initial value for the output. Is there a workaround ?

---

<div class="post-metadata">

**Author:** ![josyb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/josyb/32/5_2.png) [@josyb](https://discourse.myhdl.org/u/josyb)\
**Post date:** [January 12, 2017, 12:02pm UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147/2 "2017-01-12T12:02:36Z")

</div>

Hi DrPi,

I addressed some of this in Discourse: [New, copy, clone or duplicate?](http://discourse.myhdl.org/t/new-copy-clone-or-duplicate/31/12)  
And I have added this copy() function to my _Signal class (in my local MyHDL library) and in my experimental Array() and StructType() classes.  
It exactly achieves what you want 🙂 and I use it all the time.  
My copy() function re-uses the initial value of the original object. I don’t readily see a use for the initial\_output. But the copy() could be easily extended to take this initial\_output argument.  
However, I don’t know if it is a good idea to add extra arguments to the copy() call as this will divert it from the \_copy_() and \__deepcopy_\_() hooks.

Regards,

Josy

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [January 12, 2017, 2:23pm UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147/3 "2017-01-12T14:23:23Z")

</div>

Hi Josyb,

Thanks for remembering me the discussion. It is not clear to me if you modified MyHDL to make copy() work.  
I tried the copy() method but whatever I do, I get the following exception :  
_RuntimeError: maximum recursion depth exceeded while calling a Python object_

Can you provide a small example ?

---

<div class="post-metadata">

**Author:** ![josyb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/josyb/32/5_2.png) [@josyb](https://discourse.myhdl.org/u/josyb)\
**Post date:** [January 12, 2017, 2:26pm UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147/4 "2017-01-12T14:26:35Z")

</div>

I actually modified my local MyHDL \_Signal.py source to provide a copy() member.  
If you call copy() Python will try to do the work for you. I wonder where the recursion comes from.  
I guess you have to live with `newsig = Signal(oldsig.val)` for the time being.

---

<div class="post-metadata">

**Author:** ![josyb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/josyb/32/5_2.png) [@josyb](https://discourse.myhdl.org/u/josyb)\
**Post date:** [January 12, 2017, 2:41pm UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147/5 "2017-01-12T14:41:43Z")

</div>

I read up on ‘New Duplicate Copy Clone’ (google search) and actually clone() might be the best word after all to describe what is going on. It would also avoid any similarities to and confusion with the _built-in copy() and deepcopy()_.

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [January 12, 2017, 2:51pm UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147/6 "2017-01-12T14:51:51Z")

</div>

I’ll stick with `newsig = Signal(oldsig.val)` for now.  
Could you make a Pull-Request on github ?  
Thanks for your help.

---

<div class="post-metadata">

**Author:** ![josyb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/josyb/32/5_2.png) [@josyb](https://discourse.myhdl.org/u/josyb)\
**Post date:** [January 12, 2017, 2:56pm UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147/7 "2017-01-12T14:56:16Z")

</div>

I’d like to have a formal discussion involving @jandecaluwe (and others) before submitting a PR.

---

<div class="post-metadata">

**Author:** ![DrPi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/drpi/32/36_2.png) [@DrPi](https://discourse.myhdl.org/u/DrPi)\
**Post date:** [January 12, 2017, 3:12pm UTC](https://discourse.myhdl.org/t/how-to-internal-signals-of-same-type-than-external-ones/147/8 "2017-01-12T15:12:34Z")

</div>

Ok.  
Please, let me know when you have news on this topic.
