⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mt_spuravoid.c

📁 microtune 公司 硅高频头 源码
💻 C
📖 第 1 页 / 共 3 页
字号:
                bSpurFound = 1;                break;            }        }        mb = (_f3 - c - nf1) / _f2;        if (ma != mb)        {            const SData_t m = (n<0) ? mb : ma;            const SData_t fspur = (nf1 + m*_f2 - _f3);            const SData_t den = (bIsMyOutput ? n - 1 : n);            if (den == 0)            {                fp_ = (d - fspur)* f_Scale;                fm_ = (fspur - c)* f_Scale;            }            else            {                fp_ = (SData_t) RoundAwayFromZero((-c - fspur)* f_Scale, den);                fm_ = (SData_t) RoundAwayFromZero((fspur +d)* f_Scale, den);            }            if (((UData_t)abs(fm_) >= f_Scale) && ((UData_t)abs(fp_) >= f_Scale))            {                bSpurFound = 1;                break;            }        }    }    /*    **  Verify that fm & fp are both positive    **  Add one to ensure next 1st IF choice is not right on the edge    */    if (fp_ < 0)    {        *fp = -fm_ + 1;        *fm = -fp_ + 1;    }    else if (fp_ > 0)    {        *fp = fp_ + 1;        *fm = fm_ + 1;    }    else    {        *fp = 1;        *fm = abs(fm_) + 1;    }    return bSpurFound;}#endif/********************************************************************************  Name: IsSpurInBand****  Description:    Checks to see if a spur will be present within the IF's**                  bandwidth. (fIFOut +/- fIFBW, -fIFOut +/- fIFBW)****                    ma   mb                                     mc   md**                  <--+-+-+-------------------+-------------------+-+-+-->**                     |   ^                   0                   ^   |**                     ^   b=-fIFOut+fIFBW/2      -b=+fIFOut-fIFBW/2   ^**                     a=-fIFOut-fIFBW/2              -a=+fIFOut+fIFBW/2****                  Note that some equations are doubled to prevent round-off**                  problems when calculating fIFBW/2****  Parameters:     pAS_Info - Avoid Spurs information block**                  fm       - If spur, amount f_IF1 has to move negative**                  fp       - If spur, amount f_IF1 has to move positive****  Global:         None****  Returns:        1 if an LO spur would be present, otherwise 0.****  Dependencies:   None.****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   N/A   11-28-2002    DAD    Implemented algorithm from applied patent******************************************************************************/static UData_t IsSpurInBand(MT_AvoidSpursData_t* pAS_Info,                            UData_t* fm,                            UData_t* fp){    /*    **  Calculate LO frequency settings.    */    UData_t n, n0;    const UData_t f_LO1 = pAS_Info->f_LO1;    const UData_t f_LO2 = pAS_Info->f_LO2;    const UData_t d = pAS_Info->f_out + pAS_Info->f_out_bw/2;    const UData_t c = d - pAS_Info->f_out_bw;    const UData_t f = pAS_Info->f_zif_bw/2;    const UData_t f_Scale = (f_LO1 / (MAX_UDATA/2 / pAS_Info->maxH1)) + 1;    SData_t f_nsLO1, f_nsLO2;    SData_t f_Spur;    UData_t ma, mb, mc, md, me, mf;    UData_t lo_gcd, gd_Scale, gc_Scale, gf_Scale, hgds, hgfs, hgcs;#if MT_TUNER_CNT > 1    UData_t index;    MT_AvoidSpursData_t *adj;#endif    *fm = 0;    /*    ** For each edge (d, c & f), calculate a scale, based on the gcd    ** of f_LO1, f_LO2 and the edge value.  Use the larger of this    ** gcd-based scale factor or f_Scale.    */    lo_gcd = gcd(f_LO1, f_LO2);    gd_Scale = umax((UData_t) gcd(lo_gcd, d), f_Scale);    hgds = gd_Scale/2;    gc_Scale = umax((UData_t) gcd(lo_gcd, c), f_Scale);    hgcs = gc_Scale/2;    gf_Scale = umax((UData_t) gcd(lo_gcd, f), f_Scale);    hgfs = gf_Scale/2;    n0 = uceil(f_LO2 - d, f_LO1 - f_LO2);    /*  Check out all multiples of LO1 from n0 to m_maxLOSpurHarmonic  */    for (n=n0; n<=pAS_Info->maxH1; ++n)    {        md = (n*((f_LO1+hgds)/gd_Scale) - ((d+hgds)/gd_Scale)) / ((f_LO2+hgds)/gd_Scale);        /*  If # fLO2 harmonics > m_maxLOSpurHarmonic, then no spurs present  */        if (md >= pAS_Info->maxH1)            break;        ma = (n*((f_LO1+hgds)/gd_Scale) + ((d+hgds)/gd_Scale)) / ((f_LO2+hgds)/gd_Scale);        /*  If no spurs between +/- (f_out + f_IFBW/2), then try next harmonic  */        if (md == ma)            continue;        mc = (n*((f_LO1+hgcs)/gc_Scale) - ((c+hgcs)/gc_Scale)) / ((f_LO2+hgcs)/gc_Scale);        if (mc != md)        {            f_nsLO1 = (SData_t) (n*(f_LO1/gc_Scale));            f_nsLO2 = (SData_t) (mc*(f_LO2/gc_Scale));            f_Spur = (gc_Scale * (f_nsLO1 - f_nsLO2)) + n*(f_LO1 % gc_Scale) - mc*(f_LO2 % gc_Scale);            *fp = ((f_Spur - (SData_t) c) / (mc - n)) + 1;            *fm = (((SData_t) d - f_Spur) / (mc - n)) + 1;            return 1;        }        /*  Location of Zero-IF-spur to be checked  */        me = (n*((f_LO1+hgfs)/gf_Scale) + ((f+hgfs)/gf_Scale)) / ((f_LO2+hgfs)/gf_Scale);        mf = (n*((f_LO1+hgfs)/gf_Scale) - ((f+hgfs)/gf_Scale)) / ((f_LO2+hgfs)/gf_Scale);        if (me != mf)        {            f_nsLO1 = n*(f_LO1/gf_Scale);            f_nsLO2 = me*(f_LO2/gf_Scale);            f_Spur = (gf_Scale * (f_nsLO1 - f_nsLO2)) + n*(f_LO1 % gf_Scale) - me*(f_LO2 % gf_Scale);            *fp = ((f_Spur + (SData_t) f) / (me - n)) + 1;            *fm = (((SData_t) f - f_Spur) / (me - n)) + 1;            return 1;        }        mb = (n*((f_LO1+hgcs)/gc_Scale) + ((c+hgcs)/gc_Scale)) / ((f_LO2+hgcs)/gc_Scale);        if (ma != mb)        {            f_nsLO1 = n*(f_LO1/gc_Scale);            f_nsLO2 = ma*(f_LO2/gc_Scale);            f_Spur = (gc_Scale * (f_nsLO1 - f_nsLO2)) + n*(f_LO1 % gc_Scale) - ma*(f_LO2 % gc_Scale);            *fp = (((SData_t) d + f_Spur) / (ma - n)) + 1;            *fm = (-(f_Spur + (SData_t) c) / (ma - n)) + 1;            return 1;        }    }#if MT_TUNER_CNT > 1    /*  If no spur found, see if there are more tuners on the same board  */    for (index = 0; index < TunerCount; ++index)    {        adj = TunerList[index];        if (pAS_Info == adj)    /* skip over our own data, don't process it */            continue;        /*  Look for LO-related spurs from the adjacent tuner generated into my IF output  */        if (IsSpurInAdjTunerBand(1,                   /*  check my IF output                     */                                 pAS_Info->f_LO1,     /*  my fLO1                                */                                 adj->f_LO1,          /*  the other tuner's fLO1                 */                                 pAS_Info->f_LO2,     /*  my fLO2                                */                                 pAS_Info->f_out,     /*  my fOut                                */                                 pAS_Info->f_out_bw,  /*  my output IF bandwidth                 */                                 pAS_Info->f_zif_bw,  /*  my Zero-IF bandwidth                   */                                 pAS_Info->maxH2,                                 fp,                  /*  minimum amount to move LO's positive   */                                 fm))                 /*  miminum amount to move LO's negative   */            return 1;        /*  Look for LO-related spurs from my tuner generated into the adjacent tuner's IF output  */        if (IsSpurInAdjTunerBand(0,                   /*  check his IF output                    */                                 pAS_Info->f_LO1,     /*  my fLO1                                */                                 adj->f_LO1,          /*  the other tuner's fLO1                 */                                 adj->f_LO2,          /*  the other tuner's fLO2                 */                                 adj->f_out,          /*  the other tuner's fOut                 */                                 adj->f_out_bw,       /*  the other tuner's output IF bandwidth  */                                 pAS_Info->f_zif_bw,  /*  the other tuner's Zero-IF bandwidth    */                                 adj->maxH2,                                 fp,                  /*  minimum amount to move LO's positive   */                                 fm))                 /*  miminum amount to move LO's negative   */            return 1;    }#endif    /*  No spurs found  */    return 0;}/*********************************************************************************  Name: MT_AvoidSpurs****  Description:    Main entry point to avoid spurs.**                  Checks for existing spurs in present LO1, LO2 freqs**                  and if present, chooses spur-free LO1, LO2 combination**                  that tunes the same input/output frequencies.****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   096   04-06-2005    DAD    Ver 1.11: Fix divide by 0 error if maxH==0.*******************************************************************************/UData_t MT_AvoidSpurs(Handle_t h,                      MT_AvoidSpursData_t* pAS_Info){    UData_t status = MT_OK;    UData_t fm, fp;                     /*  restricted range on LO's        */    pAS_Info->bSpurAvoided = 0;    pAS_Info->nSpursFound = 0;    h;                          /*  warning expected: code has no effect    */    if (pAS_Info->maxH1 == 0)        return MT_OK;    /*    **  Avoid LO Generated Spurs    **    **  Make sure that have no LO-related spurs within the IF output    **  bandwidth.    **    **  If there is an LO spur in this band, start at the current IF1 frequency    **  and work out until we find a spur-free frequency or run up against the    **  1st IF SAW band edge.  Use temporary copies of fLO1 and fLO2 so that they    **  will be unchanged if a spur-free setting is not found.    */    pAS_Info->bSpurPresent = IsSpurInBand(pAS_Info, &fm, &fp);    if (pAS_Info->bSpurPresent)    {        UData_t zfIF1 = pAS_Info->f_LO1 - pAS_Info->f_in; /*  current attempt at a 1st IF  */        UData_t zfLO1 = pAS_Info->f_LO1;         /*  current attempt at an LO1 freq  */        UData_t zfLO2 = pAS_Info->f_LO2;         /*  current attempt at an LO2 freq  */        UData_t delta_IF1;        UData_t new_IF1;        /*        **  Spur was found, attempt to find a spur-free 1st IF        */        do        {            pAS_Info->nSpursFound++;            /*  Raise f_IF1_upper, if needed  */            MT_AddExclZone(pAS_Info, zfIF1 - fm, zfIF1 + fp);            /*  Choose next IF1 that is closest to f_IF1_CENTER              */            new_IF1 = MT_ChooseFirstIF(pAS_Info);            if (new_IF1 > zfIF1)            {                pAS_Info->f_LO1 += (new_IF1 - zfIF1);                pAS_Info->f_LO2 += (new_IF1 - zfIF1);            }            else            {                pAS_Info->f_LO1 -= (zfIF1 - new_IF1);                pAS_Info->f_LO2 -= (zfIF1 - new_IF1);            }            zfIF1 = new_IF1;            if (zfIF1 > pAS_Info->f_if1_Center)                delta_IF1 = zfIF1 - pAS_Info->f_if1_Center;            else                delta_IF1 = pAS_Info->f_if1_Center - zfIF1;        }        /*        **  Continue while the new 1st IF is still within the 1st IF bandwidth        **  and there is a spur in the band (again)        */        while ((2*delta_IF1 + pAS_Info->f_out_bw <= pAS_Info->f_if1_bw) &&              (pAS_Info->bSpurPresent = IsSpurInBand(pAS_Info, &fm, &fp)));        /*        ** Use the LO-spur free values found.  If the search went all the way to        ** the 1st IF band edge and always found spurs, just leave the original        ** choice.  It's as "good" as any other.        */        if (pAS_Info->bSpurPresent == 1)        {            status |= MT_SPUR_PRESENT;            pAS_Info->f_LO1 = zfLO1;            pAS_Info->f_LO2 = zfLO2;        }        else            pAS_Info->bSpurAvoided = 1;    }    status |= ((pAS_Info->nSpursFound << MT_SPUR_SHIFT) & MT_SPUR_CNT_MASK);    return (status);}UData_t MT_AvoidSpursVersion(void){    return (VERSION);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -