📄 radio_pll.c
字号:
/***************************************************************************
Project : TDA7540 Jig board
Compiler : ST7 HiCross C (HiWARE)
Module : Radio_pll.c
Version : V 1.0
Created :
Author : Jerry HE / ST-ShenZhen
Description
- PLL main routine
Modified
- Jan.24th,2005
***************************************************************************/
#include "system.h"
/**************************************************************************/
/* The pll functions */
/**************************************************************************/
void Radio_FreqToPC(void);
unsigned char Radio_PLL_FMISet(void);
unsigned char Radio_PLL_AMISet(void);
void PllRegisterRefresh(void);
void Radio_PLL_RegisterSet(void);
void Radio_PLL_DisableIFCnt(void);
void Radio_PLL_EnableIFCnt(void);
void Get_MultiPointValue(void);
void Load_EEPROM_Value(unsigned char);
/**************************************************************************/
/* Declare the variables */
/**************************************************************************/
unsigned int T_radio_pll_pc;
/*--------------------------------------------------------------------------
Routine : PllRegisterRefresh
Input :
Output :
Description
- refresh the pll register which related to pll change
--------------------------------------------------------------------------*/
void PllRegisterRefresh()
{
Radio_FreqToPC();
radio_pll_cpump &= 0xF0;
if(radio_band < MW1) /*if in FM mode */
radio_pll_cpump |= Radio_PLL_FMISet();
else
radio_pll_cpump |= Radio_PLL_AMISet();
WriteTunerRegister(PLL_AREA);
F_TunerDispReq =1;
//here display flag should set to 1
}
/*--------------------------------------------------------------------------
Routine : PllRegisterAllRefresh
Input :
Output :
Description
- refresh all pll register
--------------------------------------------------------------------------*/
void PllRegisterAllRefresh()
{
Radio_PLL_RegisterSet();
Radio_FreqToPC();
WriteTunerRegister(PLL_AREA);
WriteTunerRegister(IF_AREA);
WriteTunerRegister(VCO_AREA);
F_TunerDispReq =1;
//here display flag should be set to 1...
}
/*--------------------------------------------------------------------------
Routine : Get_MultiPointValue
Input :
Output :
Description
- Multi point auto alignment value load
--------------------------------------------------------------------------*/
void Get_MultiPointValue()
{
if(radio_band != FM1)
return;
if(F_OnePointAlign == 1)
multi_point.current_point = M92_M104;
else
{
if((radio_pll_freq>=FM87_5MHZ)&&(radio_pll_freq<FREQ_92))
{
multi_point.current_point = M87_M92;
}
if((radio_pll_freq>=FREQ_92)&&(radio_pll_freq < FREQ_104))
{
multi_point.current_point = M92_M104;
}
if((radio_pll_freq>FREQ_104)&&(radio_pll_freq <FM108MHZ))
{
multi_point.current_point = M104_M108;
}
}
if((multi_point.current_point !=multi_point.backup_point)||\
(multi_point.refresh == 1))
{
multi_point.refresh = 0;
switch(multi_point.current_point)
{
case M87_M92:
radio_tun_tunvolt2 = Eep_TV2_Point1;
break;
case M92_M104:
radio_tun_tunvolt2 = Eep_TV2_Point2;
break;
case M104_M108:
radio_tun_tunvolt2 = Eep_TV2_Point3;
break;
}
WriteTunerRegister(TUNVOLT_AREA);
}
multi_point.backup_point = multi_point.current_point;
}
/*--------------------------------------------------------------------------
Routine : Load_EEPROM_Value
Input :
Output :
Description
- load multi auto alignment value due to frequency change
--------------------------------------------------------------------------*/
void Load_EEPROM_Value(unsigned char point)
{
switch(point)
{
case M87_M92:
radio_tun_tunvolt2 = Eep_TV2_Point1;
break;
case M92_M104:
radio_tun_tunvolt2 = Eep_TV2_Point2;
break;
case M104_M108:
radio_tun_tunvolt2 = Eep_TV2_Point3;
break;
}
WriteTunerRegister(TUNVOLT_AREA);
}
/*--------------------------------------------------------------------------
Routine : Radio_FastPLL
Input :
Output :
Description
- Fast PLL change; not load the tv 2
--------------------------------------------------------------------------*/
void Radio_FastPLL()
{
T_radio_pll_pc = (radio_pll_freq << 1)+ radio_pll_offset + MIN_FM_PC;
radio_pll_pcl = T_radio_pll_pc & 0xff;
radio_pll_pch = (T_radio_pll_pc >> 8) & 0xff;
radio_pll_cpump &= 0xF0;
radio_pll_cpump |= PLL_HICURRENT_3MA;
WriteTunerRegister(PLL_AREA);
}
/*--------------------------------------------------------------------------
Routine : Radio_FreqToPC
Input :
Output :
Description
- Calculate the real PC counter value
--------------------------------------------------------------------------*/
void Radio_FreqToPC(void)
{
Get_MultiPointValue();
switch (radio_band)
{
case FM1:
T_radio_pll_pc = (radio_pll_freq << 1)+ radio_pll_offset + MIN_FM_PC;
break;
case MW1:
T_radio_pll_pc = (radio_pll_freq - 0x11);
T_radio_pll_pc = 9 * T_radio_pll_pc + radio_pll_offset;
T_radio_pll_pc += MIN_AM531_PC;
break;
case LW:
T_radio_pll_pc = radio_pll_freq;
T_radio_pll_pc = 9 * T_radio_pll_pc + radio_pll_offset;
T_radio_pll_pc += MIN_LW144_PC;
break;
}
radio_pll_pcl = T_radio_pll_pc & 0xff;
radio_pll_pch = (T_radio_pll_pc >> 8) & 0xff;
}
/*--------------------------------------------------------------------------
Routine : Radio_PLL_RegisterSet
Input :
Output :
Description
- set pll register register
--------------------------------------------------------------------------*/
void Radio_PLL_RegisterSet(void)
{
#if TDA7540_IC
if(radio_band < MW1)
{
radio_tun_vcoplldiv &= 0xC7;
radio_tun_vcoplldiv |= PLL_REFERECE_50KHz; //set pll reference to 50KHz
radio_pll_cpump &= 0x80;
radio_pll_cpump = radio_pll_cpump|PLL_HIGHCURRENT_MODE|PLL_LOWCURRENT_100uA\
|Radio_PLL_FMISet();
radio_pll_sampletime&= 0x48;
radio_pll_sampletime = radio_pll_sampletime | PLL_LOCK_ENABLE | PLL_IFC_FMMODE \
|PLL_TSAMPLE_FM5_12_AM32;
radio_pll_ewcentre = PLL_IFC_CENTER_10_7MHZ | PLL_IFC_EW_FM12_5_AM2K;
}
else
{
radio_tun_vcoplldiv &= 0xC7;
radio_tun_vcoplldiv |= PLL_REFERECE_10KHz;
radio_pll_cpump &= 0x80;
radio_pll_cpump = radio_pll_cpump | PLL_HIGHCURRENT_MODE | PLL_LOWCURRENT_50uA\
|Radio_PLL_AMISet();
radio_pll_sampletime&= 0x48;
radio_pll_sampletime = radio_pll_sampletime | PLL_LOCK_ENABLE | PLL_IFC_AM450K\
|PLL_TSAMPLE_FM5_12_AM32;
radio_pll_ewcentre = PLL_IFC_CENTER_450KHZ| PLL_IFC_EW_FM12_5_AM2K;
}
#endif
}
/*--------------------------------------------------------------------------
Routine : Radio_PLL_FMISet
Input :
Output :
Description
- set the am charge pump current
--------------------------------------------------------------------------*/
unsigned char Radio_PLL_FMISet(void)
{
if (radio_pll_freq < FM94_5MHZ)
return (PLL_HICURRENT_1_5mA);
if (radio_pll_freq < FM98_6MHZ)
return (PLL_HICURRENT_3MA);
if (radio_pll_freq < FM106_9MHZ)
return (PLL_HICURRENT_4_5mA);
return (PLL_HICURRENT_6MA);
}
/*--------------------------------------------------------------------------
Routine : Radio_PLL_AMISet
Input :
Output :
Description
- set am charge pump current
--------------------------------------------------------------------------*/
unsigned char Radio_PLL_AMISet(void)
{
return(((radio_pll_freq+64)>>4) & 0x0F);
}
/*--------------------------------------------------------------------------
Routine : Radio_Tun_SeekOn
Input :
Output :
Description
- radio seek on
--------------------------------------------------------------------------*/
void Radio_Tun_SeekOn(void)
{
if (F_SEEKON==0)
{
F_SEEKON=1;
radio_pll_cpump |= PLL_FMSEEK_ON;
WriteTunerRegister(CPUMP_AREA);
}
}
/*--------------------------------------------------------------------------
Routine : Radio_Tun_SeekOff
Input :
Output :
Description
- radio seek off
--------------------------------------------------------------------------*/
void Radio_Tun_SeekOff(void)
{
if (F_SEEKON==1)
{
F_SEEKON=0;
F_TunerDispReq=1;
Radio_PLL_DisableIFCnt();
radio_pll_cpump &= 0x7F;
radio_pll_cpump |= PLL_FMSEEK_OFF;
WriteTunerRegister(CPUMP_AREA);
}
}
/*--------------------------------------------------------------------------
Routine : Radio_PLL_EnableIFCnt
Input :
Output :
Description
- Enable the IF counter
--------------------------------------------------------------------------*/
void Radio_PLL_EnableIFCnt(void)
{
radio_pll_sampletime &= 0xF7;
radio_pll_sampletime |= PLL_IFC_ENABLE;
WriteTunerRegister(IF_SAMPLE_AREA);
}
/*--------------------------------------------------------------------------
Routine : Radio_PLL_DisableIFCnt
Input :
Output :
Description
- disable the IF counter
--------------------------------------------------------------------------*/
void Radio_PLL_DisableIFCnt(void)
{
radio_pll_sampletime &= 0xF7;
radio_pll_sampletime |= PLL_IFC_DISABLE;
WriteTunerRegister(IF_SAMPLE_AREA);
}
/*************************************************************************************************
ROUTINE NAME :Radio_PLL_FreqDec
INPUT :Max_freq, Min_freq
OUTPUT :
DESCRIPTION :frequency increment by 1 step (auto mode)
COMMENTS
**************************************************************************************************/
void Radio_PLL_FreqInc(unsigned char Max_freq, unsigned char Min_freq)
{
radio_pll_offset = 0;
radio_pll_freq ++;
if (radio_pll_freq > Max_freq)
{
radio_pll_freq = Min_freq;
}
}
/*************************************************************************************************
ROUTINE NAME :Radio_PLL_FreqDec
INPUT :Max_freq, Min_freq
OUTPUT :
DESCRIPTION :frequency decrement by 1 step (auto mode)
COMMENTS
**************************************************************************************************/
void Radio_PLL_FreqDec(unsigned char Max_freq, unsigned char Min_freq)
{
radio_pll_offset = 0;
if (radio_pll_freq == Min_freq)
{
radio_pll_freq = Max_freq;
return;
}
radio_pll_freq --;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : TUN_EvalGetSMeter
INPUT/OUTPUT : None / Measured SMeter.
DESCRIPTION : Measure the SMeter level and return its value.
COMMENTS : For Diagnostic mode.
-----------------------------------------------------------------------------*/
unsigned char Radio_EvalGetSMeter (void)
{
//unsigned char temp_val1,temp_val2;
unsigned int iTemp_val;
unsigned char temp_val2;
unsigned char i;
iTemp_val = 0;
for (i=0; i<5; i++)
{
temp_val2 = ADC_GetValue(SMETER)>>1;
iTemp_val += (int) temp_val2;
}
temp_val2 = iTemp_val / 5;
return(temp_val2);
}
/*** (c) 2005 STMicroelectronics ****************** END OF FILE ***/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -