How to implement a pipeline...??? Please help

Ritchy lelis ritchy_gato at hotmail.com
Mon Aug 30 16:51:34 CEST 2010


On 26 Ago, 08:52, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Tue, 24 Aug 2010 22:21:34 -0700 (PDT), Ritchy lelis
> <ritchy_g... at hotmail.com> declaimed the following in
> gmane.comp.python.general:
>
> > hi friend Dennis Lee Bieber
>
> > I have watching your code sujestion and now i can understand more of
> > what you have there..
>
>         Take warning -- I think I had a major flaw in the summation part of
> the logic... It's probably easier just to use a list of lists (one list
> per stage, and each list as long as the number of stages) and sum the
> diagonal
>
>         result = sum([list_of_lists[i][i] for i in range(number_of_stages)])
>
> > i would like to show you them but i need to now if you still
> > interested in the challenge it self and also in helping me with your
> > extraordinary tips.
>
> > Can i count on your help? I hope so gratefully.
>
>         My apologies... much more help and I'll have done the work for you
> (though I'm still perplexed at simulating a hardware A/D converter when
> the input is already a floating point digital, and the output is integer
> digital)
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfr... at ix.netcom.com    HTTP://wlfraed.home.netcom.com/


My apologies... much more help and I'll have done the work for you

           Until now you were the only person who helped me so far...
your help has served a lot.
           Already learned a lot with you so please do not stop
helping me.

To show you that you have not done it alone, i'll show you that i have
made some arrangements.

About the pipeline Class still have some errors and i'm working on it.
Hope this link help.

http://www.eetimes.com/design/automotive-design/4010021/SIGNAL-CHAIN-BASICS-Part-8--Flash-and-Pipeline-Converter-Operation-Explored

though I'm still perplexed at simulating a hardware A/D converter when
> the input is already a floating point digital, and the output is integer
> digital

    I believe that de residuals that we're getting at the output,
already are the wave forms that we should get if we had a Oscilloscope
and analyzing the behavior of a A/D hardware and the digital parts is
to quantify the analog input ie first we analyze and translate the
analog input to a known residue and then quantifies to the digital
output.

I already initialized the "non linear" issues with the Class
Calculate, and after this we will start to see how A/D converter
really works.
I would love you to help me at this one to

Class Calculate:

1 - http://www.national.com/appinfo/adc/files/ABCs_of_ADCs.pdf

2 - http://www.atmel.com/dyn/resources/prod_documents/doc2559.pdf

And now my new arrangements:

# -*- coding: cp1252 -*-
#######################################ADC#####################################

##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Incluir as
Bibliotecas>>>>>>>>>>>>>>>>>>>>>>>>
import matplotlib.pyplot as plt
import numpy as np
from numpy.random import *
from numpy.fft import *
from pylab import *
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLASS
ADC>>>>>>>>>>>>>>>>>>>>>>>>>>>>
class ADC(object):

           def __init__(self, Inc, V_in, V_ref, Cs, Cf):

                      ##Guarda o número de estágio e a tensão de
referência
                      ## Stores the number of stage and reference
voltage
                      self.Inc = Inc
                      self.V_ref = V_ref
                      self.Cs = Cs
                      self.Cf = Cs

                      ##calcula os limiares da tensão do comparador
                      ##calculates the threshold voltage of the
comparator
                      self.V_H = self.V_ref * 0.25
                      self.V_L = -self.V_H
                      self.V_in = V_in

                      #define dois array de "Inc" elementos todos a
uns e zeros respectivamente
                      ##sets two array "Inc" elements all the ones and
zeros respectively
                      self.ones = np.ones(Inc, dtype=np.float)
                      self.zeros = np.zeros(Inc, dtype=np.float)

           ##função flash 1.5 bit
           ##1.5 bit flash function
           def flash1b5(self):

                      # calcula as posições onde a tensão de entrada
excede o limiar alto
                      ## calculates the positions where the input
voltage exceeds the high threshold
                      highBits = np.where(self.V_in > self.V_H,
self.ones, self.zeros)

                      # calcula as posições onde a tensão de entrada é
menor que o limiar baixo
                      ## calculates the positions where the input
voltage is less than the low threshold
                      lowBits = np.where(self.V_in < self.V_L,
self.ones, self.zeros)

                      # calcula as posições onde a tensão de entrada é
maior que o limiar baixo e não excede o limiar alto
                      ## calculates the positions where the input
voltage is greater than the low threshold and does not exceed the high
threshold
                      midleBits = np.where(highBits + lowBits == 0,
self.ones, self.zeros)

                      # "digital" output pode ser obtido somando 1 e o
highBits e subtraindo lowBits
                      ## "Digital" output can be obtained by adding
and subtracting 1 and highBits lowBits
                      self.digital_out = 1 + highBits + -lowBits


                      # calcular residuo
                      ## Calculate residue
                      self.residuals = (((1+self.Cs/self.Cf)*
self.V_in) -((self.Cs/self.Cf) * self.V_ref)) * highBits + ((1+self.Cs/
self.Cf)* self.V_in )* midleBits + (((1+self.Cs/self.Cf)* self.V_in) +
                                                    ((self.Cs/
self.Cf)* self.V_ref)) * lowBits

                      # retorno da saida digital e do residuo
                      ## return of the digital output and the residue
                      out = [self.digital_out, self.residuals]
                      return out

           ##função flash 2 bit
           ## 2 bit flash function
           def flash2b(self):


                      # calcula as posições onde a tensão de entrada
excede o limiar alto
                      ## calculates the positions where the input
voltage exceeds the high threshold
                      # (2X the threshold of the 1.5B stages)
                      highBits1 = np.where(self.V_in > 2*self.V_H,
[3], self.zeros)

                      # calcula as posições onde a tensão de entrada
está entre zero e o limiar alto
                      ## calculates the positions where the input
voltage is between zero and the high threshold
                      if any(self.V_in <= 2*self.V_H) and
any(self.V_in > 0.0):
                             highBits2 = np.where((self.V_in <=
2*self.V_H) & (self.V_in > 0.0), [2], self.zeros)

                      # calcula as posições onde a tensão de entrada
está entre zero e o limiar baixo
                      ## calculates the positions where the input
voltage is between zero and low threshold
                      if any(self.V_in <= 0.0) and any(self.V_in >
2*self.V_L):
                             lowBits1 = np.where((self.V_in <= 0.0) &
(self.V_in > 2*self.V_L), self.ones,self.zeros)

                      # calcula as posições onde a tensão de entrada é
menor que o limiar baixo
                      ## calculates the positions where the input
voltage is less than the low threshold
                      lowBits2 = np.where(self.V_in <=  2*self.V_L,
self.zeros, self.zeros)

                      # "digital" output pode ser obtido somando todas
as posiçoes desta forma.
                      ## "Digital" output can be obtained by adding
all the positions in this way
                      self.digital_out = lowBits2 + lowBits1 +
highBits2+ highBits1

                      # retorno da saida digital
                      ## Digital output return
                      out = [self.digital_out]
                      return out

           ##função flash 2.5 bit
           ## 2.5 bit flash function
           def flash2b5(self):

                      ## calculates the positions where the input
voltage exceeds the high threshold
                      highBits1 = np.where(self.V_in > (self.V_H*5/2),
self.ones, self.zeros)

                      ## calculates the positions where the input
voltage is between zero and the high threshold

                      if any(self.V_in <= (self.V_H*5/2)) and
any(self.V_in >=(self.V_H*3/2)):
                                 highBits2 = np.where((self.V_in <=
(self.V_H*5/2)) &
                                                      (self.V_in
>=(self.V_H*3/2)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_H*3/2)) and
any(self.V_in >=(self.V_H*1/2)):
                                 highBits3 = np.where((self.V_in <=
(self.V_H*3/2)) &
                                                      (self.V_in
>=(self.V_H*1/2)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_H*1/2)) and
any(self.V_in >=(self.V_L*1/2)):
                                 midleBits = np.where((self.V_in <=
(self.V_H*1/2)) &
                                                      (self.V_in
>=(self.V_L*1/2)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_L*1/2)) and
any(self.V_in >=(self.V_L*3/2)):
                                 lowBits1 =  np.where((self.V_in <=
(self.V_L*1/2)) &
                                                      (self.V_in
>=(self.V_L*3/2)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_L*3/2)) and
any(self.V_in >=(self.V_L*5/2)):
                                 lowBits2 =  np.where((self.V_in <=
(self.V_L*3/2)) &
                                                      (self.V_in
>=(self.V_L*5/2)), self.ones, self.zeros)

                    ## calculates the positions where the input
voltage is less than the low threshold
                      lowBits3 = np.where(self.V_in < (self.V_L*5/2),
self.ones, self.zeros)

                    ## Calculate residue 2.5 Bit
                      self.residuals = ((4*self.V_in -
3*self.V_ref)*highBits1 + (4*self.V_in - 2*self.V_ref) * highBits2 +
                                        (4*self.V_in - self.V_ref) *
highBits3 + (4 * self.V_in) * midleBits + (4*self.V_in + self.V_ref) *
lowBits1 +
                                        (4*self.V_in + 2*self.V_ref) *
lowBits2 + (4*self.V_in + 3*self.V_ref) * lowBits3)

                    ## Residue output return
                      out = [self.residuals]
                      return out

##
##
           ##função flash 3 Bit
           ## 3 Bit flash function
           def flash3b(self):

                      ## calculates the positions where the input
voltage exceeds the high threshold
                      highBits1 = np.where(self.V_in > (self.V_H*3),
[7], self.zeros)

                      ## calculates the positions where the input
voltage is between zero and the high threshold
                      if any(self.V_in <= (self.V_H*3)) and
any(self.V_in >=self.V_H*2):
                                 highBits2 = np.where((self.V_in <=
(self.V_H*3)) &
                                                      (self.V_in
>=(self.V_H*2)), [6], self.zeros)

                      if any(self.V_in <= (self.V_H*2)) and
any(self.V_in >=(self.V_H)):
                                 highBits3 = np.where((self.V_in <=
(self.V_H*2)) &
                                                      (self.V_in
>=(self.V_H)), [5], self.zeros)

                      if any(self.V_in <= (self.V_H)) and
any(self.V_in >=0.0):
                                 highBits4 =  np.where((self.V_in <=
(self.V_H)) &
                                                      (self.V_in
>=0.0), [4], self.zeros)

                      if any(self.V_in <= 0.0) and any(self.V_in >=
(self.V_L)):
                                 lowBits1 =  np.where((self.V_in <=
0.0) &
                                                      (self.V_in >=
(self.V_L)), [3], self.zeros)

                      if any(self.V_in <= (self.V_L)) and
any(self.V_in >=(self.V_L*2)):
                                 lowBits2 =  np.where((self.V_in <=
(self.V_L)) &
                                                      (self.V_in
>=(self.V_L*2)), [2], self.zeros)

                      if any(self.V_in <= (self.V_L*2)) and
any(self.V_in >=(self.V_L*3)):
                                 lowBits3 =  np.where((self.V_in <=
(self.V_L*2)) &
                                                      (self.V_in
>=(self.V_L*3)), [1], self.zeros)

                      ## calculates the positions where the input
voltage is less than the low threshold
                      lowBits4 = np.where(self.V_in < (self.V_L*3),
self.zeros, self.zeros)

                      ## "Digital" output can be obtained by adding
all the positions in this way
                      self.digital_out = lowBits4 + lowBits3 +
lowBits2 + lowBits1 + highBits4 + highBits3 + highBits2  +highBits1

                      # retorno da saida digital
                      ## Digital output return
                      out = [self.digital_out]
                      return out
##
##
           ##função flash 3.5 bit
           ## 3.5 Bit flash function
           def flash3b5(self):

                      ## calculates the positions where the input
voltage exceeds the high threshold
                      highBits1 = np.where(self.V_in >
(self.V_H*13/4), self.ones, self.zeros)

                      ## calculates the positions where the input
voltage is between zero and the high threshold
                      if any(self.V_in <= (self.V_H*13/4)) and
any(self.V_in >=(self.V_H*11/4)):
                                 highBits2 = np.where((self.V_in <=
(self.V_H*13/4)) &
                                                      (self.V_in
>=(self.V_H*11/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_H*11/4)) and
any(self.V_in >=(self.V_H*9/4)):
                                 highBits3 = np.where((self.V_in <=
(self.V_H*11/4)) &
                                                      (self.V_in
>=(self.V_H*9/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_H*9/4)) and
any(self.V_in >=(self.V_H*7/4)):
                                 highBits4 = np.where((self.V_in <=
(self.V_H*9/4)) &
                                                      (self.V_in
>=(self.V_H*7/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_H*7/4)) and
any(self.V_in >=(self.V_H*5/4)):
                                 highBits5 = np.where((self.V_in <=
(self.V_H*7/4)) &
                                                      (self.V_in
>=(self.V_H*5/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_H*5/4)) and
any(self.V_in >=(self.V_H*3/4)):
                                 highBits6 = np.where((self.V_in <=
(self.V_H*5/4)) &
                                                      (self.V_in
>=(self.V_H*3/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_H*3/4)) and
any(self.V_in >=(self.V_H*1/4)):
                                 highBits7 = np.where((self.V_in <=
(self.V_H*3/4)) &
                                                      (self.V_in
>=(self.V_H*1/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_H*1/4)) and
any(self.V_in >=(self.V_L*1/4)):
                                 midleBits = np.where((self.V_in <=
(self.V_H*1/4)) &
                                                      (self.V_in
>=(self.V_L*1/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_L*1/4)) and
any(self.V_in >=(self.V_L*3/4)):
                                 lowBits1 =  np.where((self.V_in <=
(self.V_L*1/4)) &
                                                      (self.V_in
>=(self.V_L*3/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_L*3/4)) and
any(self.V_in >=(self.V_L*5/4)):
                                 lowBits2 =  np.where((self.V_in <=
(self.V_L*3/4)) &
                                                      (self.V_in
>=(self.V_L*5/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_L*5/4)) and
any(self.V_in >=(self.V_L*7/4)):
                                 lowBits3 =  np.where((self.V_in <=
(self.V_L*5/4)) &
                                                      (self.V_in
>=(self.V_L*7/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_L*7/4)) and
any(self.V_in >=(self.V_L*9/4)):
                                 lowBits4 =  np.where((self.V_in <=
(self.V_L*7/4)) &
                                                      (self.V_in
>=(self.V_L*9/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_L*9/4)) and
any(self.V_in >=(self.V_L*11/4)):
                                 lowBits5 =  np.where((self.V_in <=
(self.V_L*9/4)) &
                                                      (self.V_in
>=(self.V_L*11/4)), self.ones, self.zeros)

                      if any(self.V_in <= (self.V_L*11/4)) and
any(self.V_in >=(self.V_L*13/4)):
                                 lowBits6 =  np.where((self.V_in <=
(self.V_L*11/4)) &
                                                      (self.V_in
>=(self.V_L*13/4)), self.ones, self.zeros)

                     ## calculates the positions where the input
voltage is less than the low threshold
                      lowBits7 = np.where(self.V_in < (self.V_L*13/4),
self.ones, self.zeros)

                    ## Calculate residue 3.5 Bit
                      self.residuals = ((8*self.V_in - 7*self.V_ref)
*highBits1 + (8*self.V_in - 6*self.V_ref)* highBits2 +
                                        (8*self.V_in -
5*self.V_ref)*highBits3 + (8*self.V_in - 4*self.V_ref) * highBits4 +
                                        (8*self.V_in - 3*self.V_ref) *
highBits5 + (8*self.V_in - 2*self.V_ref) * highBits6 +
                                        (8*self.V_in - self.V_ref) *
highBits7 + (8 * self.V_in) * midleBits +
                                        (8*self.V_in + self.V_ref) *
lowBits1 + (8*self.V_in + 2*self.V_ref) * lowBits2 +
                                        (8*self.V_in + 3*self.V_ref) *
lowBits3 + (8*self.V_in + 4*self.V_ref) * lowBits4 +
                                        (8*self.V_in + 5*self.V_ref) *
lowBits5 + (8*self.V_in + 6*self.V_ref) * lowBits6 +
                                        (8*self.V_in + 7*self.V_ref) *
lowBits7 )

                    ## Residue output return
                      out = [self.residuals]
                      return out
##
##
##           ##função Pipeline
##           def pipeline(self):

##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLASS
CALCULATE>>>>>>>>>>>>>>>>>>>>>>>>>>>>
##class calculate(ADC):
##
##           def __init__ (self):
##
##
##           def AC_Errors(self):
##
##
##           def Offset_Errors(self):
##
##
##           def plot_fft(self):
##
##
##           def DNL_INL(self):



##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>SIMULAÇÃO>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
##
if __name__=='__main__':

           V_in = np.linspace(-1, 1, 10000)

           F1B5 = ADC(10000, V_in, 1, 2, 2).flash1b5()
           F2B = ADC(10000, V_in, 1, 2, 2).flash2b()
           F2B5 = ADC(10000, V_in, 1, 2, 2).flash2b5()
           F3B5 = ADC(10000, V_in, 1, 2, 2).flash3b5()
           F3B = ADC(10000, V_in, 1, 2, 2).flash3b()

           fig1 = figure(1,figsize=(8,5))
           ax1 = fig1.add_subplot(111, autoscale_on=True)
           ax1.plot(V_in, F1B5[1], lw = 1, color='b')
           grid(True); xlabel('IN'); ylabel('OUT'); title('RESIDUALS
1B5')

           fig2 = figure(2,figsize=(8,5))
           ax2 = fig2.add_subplot(111, autoscale_on=False,xlim=(-1,1),
ylim=(-1,3))
           ax2.plot(V_in, F1B5[0], lw=1, color='r')
           grid(True); xlabel('IN'); ylabel('OUT'); title('DIGITAL OUT
1B5')

           fig3 = figure(3,figsize=(8,5))
           ax3 = fig3.add_subplot(111, autoscale_on=False,xlim=(-1,1),
ylim=(-1,4))
           ax3.plot(V_in, F2B[0], lw=1, color='g')
           grid(True); xlabel('IN'); ylabel('OUT'); title('DIGITAL OUT
2B')

           fig4 = figure(4,figsize=(8,5))
           ax4 = fig4.add_subplot(111, autoscale_on=True)
           ax4.plot(V_in, F2B5[0], lw=1, color='y')
           grid(True); xlabel('IN'); ylabel('OUT'); title('RESIDUALS
2B5')

           fig5 = figure(5,figsize=(8,5))
           ax5 = fig5.add_subplot(111, autoscale_on=False,xlim=(-1,1),
ylim=(-1,8))
           ax5.plot(V_in, F3B[0], lw=1, color='brown')
           grid(True); xlabel('IN'); ylabel('OUT'); title('DIGITAL OUT
3B')

           fig6 = figure(6,figsize=(8,5))
           ax6 = fig6.add_subplot(111, autoscale_on=False,
xlim=(-1,1), ylim=(-1,1))
           ax6.plot(V_in, F3B5[0], lw=1, color='purple')
           grid(True); xlabel('IN'); ylabel('OUT'); title('RESIDUALS
3B5')

           plt.show()

Ps: How can i put my messages just for you to read it like you always
do?



More information about the Python-list mailing list