dsp/tb_pycheck.py
def fraction_to_ph_acc(rational_fraction, bits_h=20, bits_l=12):
    '''
    Converts a rational fraction [num/den] to what is needed by dsp/ph_acc.v

    The function determines the fixed point phase step that an FGPA phase
    generator rotates by every clock cycle (of the sampling clock). The
    rotation is implemented as an adder. The frequency being generated is a
    `rational_fraction` of the ADC clock frequency. The ADC Clock takes a
    full 2*pi phase step, where as the generated phase step takes a
    `rational_fraction` of the phase step.

    Args:
        :param rational_fraction: (num, den) A ratio of the ADC Clock frequency
        :param bits_h: The resolution of the main counter that generates phase.
        :param bits_l: Resolution of a helper counter that compensates for the
                       residue of the coarse counter
    Returns:
        :return step_h: Coarse representation of the `rational_fraction`

    num, den = rational_fraction
    Determine coarse_step by scaling the rational_fraction to bits_h resolution
    Determine fine_step by taking the residue from the coarse step and scaling
    to bits_l resolution
    modulo, is residue from the fine_step that is added to the counter when it
    overflows
    '''
    # _fs stands for _full_scale
    coarse_fs, fine_fs = 2**bits_h, 2**bits_l
    num, den = rational_fraction

    # Scale the rational fraction to coarse full scale and compute the residue
    step_h = int(coarse_fs * num / den)
    residue_coarse = (num * coarse_fs) % den

    # acc_multiplier holds the smallest fine scale step per clock cycle
    acc_multiplier = int(fine_fs / den)
    step_l = residue_coarse * acc_multiplier

    modulo = fine_fs - acc_multiplier * den
    return step_h, step_l, modulo

    Converts a rational fraction [num/den] to what is needed by dsp/ph_acc.v

    The function determines the fixed point phase step that an FGPA phase
    generator rotates by every clock cycle (of the sampling clock). The
    rotation is implemented as an adder. The frequency being generated is a
    `rational_fraction` of the ADC clock frequency. The ADC Clock takes a
    full 2*pi phase step, where as the generated phase step takes a
    `rational_fraction` of the phase step.

    Args:
        :param rational_fraction: (num, den) A ratio of the ADC Clock frequency
        :param bits_h: The resolution of the main counter that generates phase.
        :param bits_l: Resolution of a helper counter that compensates for the
                       residue of the coarse counter
    Returns:
        :return step_h: Coarse representation of the `rational_fraction`

    num, den = rational_fraction
    Determine coarse_step by scaling the rational_fraction to bits_h resolution
    Determine fine_step by taking the residue from the coarse step and scaling
    to bits_l resolution
    modulo, is residue from the fine_step that is added to the counter when it
    overflows
    
Converts a rational fraction [num/den] to what is needed by dsp/ph_acc.v
The function determines the fixed point phase step that an FGPA phase
generator rotates by every clock cycle (of the sampling clock). The
rotation is implemented as an adder. The frequency being generated is a
`rational_fraction` of the ADC clock frequency. The ADC Clock takes a
full 2*pi phase step, where as the generated phase step takes a
`rational_fraction` of the phase step.
Converts a rational fraction [ num / den ] to what is needed by dsp / ph_acc . v The function determines the fixed point phase step that an FGPA phase generator rotates by every clock cycle ( of the sampling clock ) . The rotation is implemented as an adder . The frequency being generated is a ` rational_fraction ` of the ADC clock frequency . The ADC Clock takes a full 2 * pi phase step where as the generated phase step takes a ` rational_fraction ` of the phase step .
def fraction_to_ph_acc(rational_fraction, bits_h=20, bits_l=12):
    coarse_fs, fine_fs = 2**bits_h, 2**bits_l
    num, den = rational_fraction
    step_h = int(coarse_fs * num / den)
    residue_coarse = (num * coarse_fs) % den
    acc_multiplier = int(fine_fs / den)
    step_l = residue_coarse * acc_multiplier
    modulo = fine_fs - acc_multiplier * den
    return step_h, step_l, modulo
def fraction_to_ph_acc ( rational_fraction , bits_h = 20 , bits_l = 12 ) : coarse_fs , fine_fs = 2 ** bits_h , 2 ** bits_l num , den = rational_fraction step_h = int ( coarse_fs * num / den ) residue_coarse = ( num * coarse_fs ) % den acc_multiplier = int ( fine_fs / den ) step_l = residue_coarse * acc_multiplier modulo = fine_fs - acc_multiplier * den return step_h , step_l , modulo
Converts a rational fraction [num/den] to what is needed by dsp/ph_acc.v
The function determines the fixed point phase step that an FGPA phase
generator rotates by every clock cycle (of the sampling clock).
Converts a rational fraction [ num / den ] to what is needed by dsp / ph_acc . v The function determines the fixed point phase step that an FGPA phase generator rotates by every clock cycle ( of the sampling clock ) .
'''
    Converts a rational fraction [num/den] to what is needed by dsp/ph_acc.v

    The function determines the fixed point phase step that an FGPA phase
    generator rotates by every clock cycle (of the sampling clock). The
    rotation is implemented as an adder. The frequency being generated is a
    `rational_fraction` of the ADC clock frequency. The ADC Clock takes a
    full 2*pi phase step, where as the generated phase step takes a
    `rational_fraction` of the phase step.

    Args:
        :param rational_fraction: (num, den) A ratio of the ADC Clock frequency
        :param bits_h: The resolution of the main counter that generates phase.
        :param bits_l: Resolution of a helper counter that compensates for the
                       residue of the coarse counter
    Returns:
        :return step_h: Coarse representation of the `rational_fraction`

    num, den = rational_fraction
    Determine coarse_step by scaling the rational_fraction to bits_h resolution
    Determine fine_step by taking the residue from the coarse step and scaling
    to bits_l resolution
    modulo, is residue from the fine_step that is added to the counter when it
    overflows
    ''' # _fs stands for _full_scale # Scale the rational fraction to coarse full scale and compute the residue # acc_multiplier holds the smallest fine scale step per clock cycle
:return step_h: Coarse representation of the `rational_fraction`
: return step_h : Coarse representation of the ` rational_fraction `
rational_fraction
bits_h
bits_l
param bits_l: Resolution of a helper counter that compensates for the
residue of the coarse counter
param bits_l : Resolution of a helper counter that compensates for the residue of the coarse counter