PLL 是一种集成了锁相环、鉴相器、振荡器为一体的频率合成芯片,
以LMX2541为例,它是一款小数分频的频率合成器,输出频率31.6MHz~4GHz,
具有非常好的相位噪声和杂散指标。采用SPI控制驱动程序如下:
#include "PLL_Thread.h"
#include "DrvSPI.h"
const int16_t OffSetArray[] = {8000, 7500, 7300, 5000, 4000, 2500, 0, -2500, -4000, -5000, -7300, -7500, -
8000};
//寄存器0
volatile TRegister_R0 Register_R0_TX; //Register_R0_RX,
//寄存器1
volatile TRegister_R1 Register_R1_TX; //Register_R1_RX,
//寄存器2
volatile TRegister_R2 Register_R2_TX; //Register_R2_RX,
//寄存器4
volatile TRegister_R4 Register_R4_TX; //Register_R4_RX,
//Register_R2.Map.default0 = Register_R2_default;
// Register_R2.Map.PLL_DEN = PLL_DEN_RX_VALUE;
// LMX2541_Set_Register(Register_R2.Value,LMX2541_REG2);
//寄存器6 extern
volatile TRegister_R6 Register_R6;
//
寄存器8
//TRegister_R8 Register_R8;
//
寄存器9
//TRegister_R9 Register_R9;
//
寄存器12
//TRegister_R12 Register_R12;
//
寄存器13
//TRegister_R13 Register_R13;
void IniSPI(void);
//void IniLMX2541_GPIO(void);
void IniLMX2541_Ctrl_GPIO(void);
void IniLMX2541(void);
void LMX2541_Set_Register(uint32_t Register_Value,TLMX2541_REG Register_Addr);
void LMX2541_Write_Data(uint32_t Value);
uint8_t LMX2541_Modify_FRE(uint32_t Fre_Value,uint8_t OffSet);
uint8_t LMX2541_Modify_RFGain(uint8_t Gain_Value);
void LMX2541_Modify_LoopFilter(TLMX2541_RES RES_R3,TLMX2541_RES RES_R4,TLMX2541_CAP3 CAP_C3,TLMX2541_CAP4 CAP_C4,uint8_t vco_div_value);
void PTT_SW(uint8_t ptt);
void EINT1_Callback(void);
void GPIO_GPAB_Callbackfunc(uint32_t portA,uint32_t portB);
//void GPIO_GPCDE_Callbackfunc(uint32_t portC,uint32_t portD,uint32_t portE);
//void LMX2541_Modify_PLL (uint8_t PLL_R,uint32_t PLL_N, uint32_t PLL_NUM, uint32_t PLL_DEN);
void IniSPI(void)
{
/* Configure SPI0 related multi-function pins */
DrvGPIO_InitFunction(E_FUNC_SPI0);
/* Configure SPI0 as a master, 32-bit transaction */
DrvSPI_Open(eDRVSPI_PORT0,eDRVSPI_MASTER,eDRVSPI_TYPE1,32);
/* Disable the automatic slave select function of SS0. */
DrvSPI_DisableAutoSS(eDRVSPI_PORT0);
/* Set the active level of slave select. */
DrvSPI_SetSlaveSelectActiveLevel(eDRVSPI_PORT0, eDRVSPI_ACTIVE_LOW_FALLING);
DrvSPI_Set2BitTransferMode(eDRVSPI_PORT0,FALSE);
/* The transfer order of SPI0 is MSB first */
DrvSPI_SetEndian(eDRVSPI_PORT0, eDRVSPI_MSB_FIRST);
/* SPI clock rate 1M */
DrvSPI_SetClockFreq(eDRVSPI_PORT0,1000000, 0);
}
/*
函数名称:IniLMX2541_Ctrl_GPIO
函数功能:初始化控制LMX2541 相关引脚功能
入口函数:无
出口函数:无
返回值:无
*/
void IniLMX2541_Ctrl_GPIO(void)
{
// DrvGPIO_Open(E_GPA,3, E_IO_OUTPUT); //SYTEST
// DrvGPIO_Open(E_GPA,11, E_IO_INPUT);
// DrvGPIO_Open(E_GPB,3, E_IO_OUTPUT); //VCTL
//IniSPI();
// DrvGPIO_Open(E_GPC,0, E_IO_OUTPUT); //LE
// DrvGPIO_Open(E_GPC,1, E_IO_OUTPUT); //CLK
// DrvGPIO_Open(E_GPC,7, E_IO_INPUT); //SYSLOCK_STU
// DrvGPIO_Open(E_GPE,0, E_IO_OUTPUT); //RFEN
// DrvGPIO_Open(E_GPE,1, E_IO_OUTPUT); //DATA_PLL
// DrvGPIO_Open(E_GPE,2, E_IO_OUTPUT); //CLK_PLL
// DrvGPIO_Open(E_GPE,3, E_IO_OUTPUT); //EN_PLL
//
// SYTEST(SYNCLOCK); //默认为频合正常
//DrvGPIO_EnableInt(E_GPB,2, E_IO_BOTH_EDGE,E_MODE_EDGE); //打开LOCK中断
//DrvGPIO_SetIntCallback(GPIO_GPAB_Callbackfunc, GPIO_GPCDE_Callbackfunc);
//DrvGPIO_EnableEINT1(E_IO_BOTH_EDGE, E_MODE_EDGE,EINT1_Callback);
}
/******************************************
********初始化送数IO口********************
******************************************/
//void IniLMX2541_GPIO(void)
//{
// DrvGPIO_Open(E_GPE,3, E_IO_OUTPUT); //EN_PLL
// DrvGPIO_Open(E_GPE,2, E_IO_OUTPUT); //CLK_PLL
// DrvGPIO_Open(E_GPE,1, E_IO_OUTPUT); //DATA_PLL
//}
/*
函数名称:IniLMX2541
函数功能:初始化LMX2541 相关寄存器
入口函数:无
出口函数:无
返回值:无
*/
void IniLMX2541(void)
{
//寄存器2
TRegister_R2 Register_R2;
//寄存器3
TRegister_R3 Register_R3;
//寄存器4
// TRegister_R4 Register_R4;
//寄存器5
TRegister_R5 Register_R5;
//寄存器7
TRegister_R7 Register_R7;
TRegister_R8 Register_R8;
TRegister_R9 Register_R9;
TRegister_R12 Register_R12;
TRegister_R13 Register_R13;
IniLMX2541_Ctrl_GPIO(); //初始化控制LMX2541的寄存器引脚
RFEN_PLL(0); //关闭射频输出
//初始化寄存器7
Register_R7.Map.default0 = Register_R7_default;
LMX2541_Set_Register(Register_R7.Value,LMX2541_REG7);
//初始化寄存器13
Register_R13.Map.default0 = Register_R13_default;
Register_R13.Map.VCO_DIV_OPT = 0;
LMX2541_Set_Register(Register_R13.Value,LMX2541_REG13);
//初始化寄存器12
Register_R12.Map.default0 = Register_R12_default;
LMX2541_Set_Register(Register_R12.Value,LMX2541_REG12);
//初始化寄存器9
Register_R9.Map.default0 = Register_R9_default;
LMX2541_Set_Register(Register_R9.Value,LMX2541_REG9);
//初始化寄存器8
Register_R8.Map.default0 = Register_R8_default;
Register_R8.Map.AC_TEMP_COMP = 5;
LMX2541_Set_Register(Register_R8.Value,LMX2541_REG8);
//初始化寄存器6
Register_R6.Map.default0 = Register_R6_default;
// Register_R6.Map.VCOGAIN = 12;
Register_R6.Map.OUTTERM = 12;
Register_R6.Map.DIVGAIN = 12;
Register_R6.Map.RFOUT = 1; //射频开关由RFoutEN控制
Register_R6.Map.Addr = LMX2541_REG6;
LMX2541_Write_Data(Register_R6.Value);
//初始化寄存器5
Register_R5.Map.default0 = Register_R5_default;
Register_R5.Map.FL_CPG = 0;
Register_R5.Map.FL_RF_LF = 0;
Register_R5.Map.FL_R3_LF = 0;
Register_R5.Map.FL_TOC = 0; //禁用FastLock
LMX2541_Set_Register(Register_R5.Value,LMX2541_REG5);
//初始化寄存器4(环路滤波器)
// LMX2541_Modify_LoopFilter(LMX2541_RES_1k,LMX2541_RES_200,LMX2541_CAP3_20,LMX2541_CAP4_100,20);
//初始化寄存器3
Register_R3.Map.FSK = 0; //禁用FSK
Register_R3.Map.default0 = Register_R3_default;
Register_R3.Map.DLOCK = 0; //锁定时间为13.5ns
Register_R3.Map.CPT = 0; //禁止使用3态
Register_R3.Map.DITH = 3; //禁止使用抖动
Register_R3.Map.ORDER = 3; //使用小数分频
Register_R3.Map.FDM = 1; //使用小数分频时,分子和分母都是22bit
Register_R3.Map.OSC_2X = 0; //不使用双倍晶振
Register_R3.Map.CPP = 0; //全功能模式下,电荷泵极性为负极
Register_R3.Map.MUX = 8;
Register_R3.Map.CPG = 15; //选择最大的充电泵电流 1600uA
Register_R3.Map.XO = 0;
Register_R3.Map.POWERDOWN = 0; //不关闭器件
Register_R3.Map.MODE = 0; //全功能模式
// Register_R3.Map.Addr = LMX2541_REG3;
LMX2541_Set_Register(Register_R3.Value,LMX2541_REG3);
//初始化寄存器2
Register_R2.Map.default0 = Register_R2_default;
Register_R2.Map.PLL_DEN = PLL_DEN_MAX_VALUE;
LMX2541_Set_Register(Register_R2.Value,LMX2541_REG2);
//初始化寄存器1
//Register_R1_RX.Map.Addr = LMX2541_REG1; //地址
//Register_R1_RX.Map.default0 = Register_R1_default;
Register_R1_TX.Map.Addr = LMX2541_REG1; //地址
Register_R1_TX.Map.default0 = Register_R1_default;
//初始化寄存器0
//Register_R0_RX.Map.Addr = LMX2541_REG0; //地址
Register_R0_TX.Map.Addr = LMX2541_REG0; //地址
}
/*
函数名称:LMX2541_Set_Register
函数功能:设置寄存器的值
入口函数:
Register_Value:寄存器的值;
Register_Addr:寄存器地址,该值可以为:LMX2541_REG0,LMX2541_REG1,LMX2541_REG2,LMX2541_REG3,LMX2541_REG4,
LMX2541_REG5,LMX2541_REG6,LMX2541_REG7,LMX2541_REG8,LMX2541_REG9,
LMX2541_REG12,LMX2541_REG13
出口函数:无
返回值:无
*/
void LMX2541_Set_Register(uint32_t Register_Value,TLMX2541_REG Register_Addr)
{
uint32_t SendData = 0;
SendData = Register_Value & 0xFFFFFFF0;
SendData += Register_Addr;
LMX2541_Write_Data(SendData);
}
/*
函数名称:LMX2541_Write_Data
函数功能:发送数据到LMX2541
入口函数:
Value:要发送到LMX2541的值;
出口函数:无
返回值:无
*/
//void LMX2541_Write_Data(uint32_t Value)
//{
// DrvSPI_ClrSS(eDRVSPI_PORT0, eDRVSPI_SS0); //set high
// DrvSPI_SetSS(eDRVSPI_PORT0, eDRVSPI_SS0); //set low
// DrvSPI_SingleWrite(eDRVSPI_PORT0,&Value);
// while(DrvSPI_IsBusy(eDRVSPI_PORT0));
// DrvSPI_ClrSS(eDRVSPI_PORT0, eDRVSPI_SS0); //set high
// DrvSPI_SetSS(eDRVSPI_PORT0, eDRVSPI_SS0); //set low
//}
void LMX2541_Write_Data(uint32_t Value)
{
uint8_t i;
EN_PLL(1);
delay(5); //set high
EN_PLL(0); //set low
delay(5);
for(i=0;i<32;i++)
{
CLK_PLL(0);
delay(5);
if((Value&0x80000000)==0x80000000)
{
DATA_PLL(1);
}
else
{
DATA_PLL(0);
}
delay(5);
CLK_PLL(1);
delay(5);
Value=Value<<1;
}
CLK_PLL(0);
delay(5);
EN_PLL(1); //set high
delay(5);
EN_PLL(0); //set low
delay(5);
RFEN_PLL(1);
delay(5);
}
/*
函数名称:LMX2541_Modify_FRE
函数功能:修改LMX2541的输出频率
入口函数:
出口函数:无
返回值:
1:频率设置成功
0:频率设置失败
*/
uint8_t LMX2541_Modify_FRE(const uint32_t Fre_Value,const uint8_t OffSet_subscript)
{
uint8_t ModValue = 0,VCO_DIV_TX = 0; //VCO_DIV_RX = 0,
uint16_t PLL_CNT_N = 0;
uint32_t VCO_OUT = 0,PLL_CNT_NUM = 0;
float point = 0.0;
uint32_t RealFre_Tx = 0; //RealFre_Rx = 0,
if((Fre_Value>MAXFRE)||(Fre_Value<MINFRE)||(Fre_Value%5 != 0)||(OffSet_subscript>12))
{
return 0; //频率值或频偏值超出范围
}
ModValue = Fre_Value%100;
if((ModValue == 20)||(ModValue == 45)||(ModValue == 70)||(ModValue == 95))
{
return 0;
}
if(Fre_Value%25 == 0)
{
RealFre_Tx = Fre_Value * 1000;
}
else
{
RealFre_Tx *= 1000;
if( OffSet_subscript>12 )
{
return 0;
}
}
//RealFre_Rx = RealFre_Tx + 35250000;
RealFre_Tx += 35250000;
RealFre_Tx += OffSetArray[OffSet_subscript];
//计算接收频率值
//VCO_DIV_RX = VCO_MAX_VALUE/RealFre_Rx; //计算VCO_DIV
//VCO_OUT = RealFre_Rx * VCO_DIV_RX; //计算VCO的值
PLL_CNT_N = VCO_OUT / FPD_VALUE; //计算N值
point = ((float)(VCO_OUT % FPD_VALUE)/FPD_VALUE); //计算小数值
PLL_CNT_NUM = point * PLL_DEN_MAX_VALUE; //计算分子值
// Register_R0_RX.Map.PLL_NUM_L = PLL_CNT_NUM & 0x0000ffff; //PLL_NUM低16位
// Register_R0_RX.Map.PLL_N_L = PLL_CNT_N & 0x00000fff; //PLL_N低12位
//Register_R1_RX.Map.default0 = Register_R1_default;
// Register_R1_RX.Map.PLL_NUM_H = ((PLL_CNT_NUM >> 16)&0x0000003f); //PLL_NUM高6位
// Register_R1_RX.Map.PLL_N_H = ((PLL_CNT_N >> 12)&0x0000003f); //PLL_N高6位
// Register_R1_RX.Map.PLL_R = PLL_R_VALUE; //PLL_R
//Register_R1_RX.Map.Addr = LMX2541_REG1; //地址
//Register_R4_RX.Map.VCO_DIV = VCO_DIV_RX;
//计算发射机频率
VCO_DIV_TX = VCO_MAX_VALUE/RealFre_Tx; //计算VCO_DIV
VCO_OUT = RealFre_Tx * VCO_DIV_TX; //计算VCO的值
PLL_CNT_N = VCO_OUT / FPD_VALUE; //计算N值
point = ((float)(VCO_OUT % FPD_VALUE)/FPD_VALUE); //计算小数值
PLL_CNT_NUM = point * PLL_DEN_MAX_VALUE; //计算分子值
Register_R0_TX.Map.PLL_NUM_L = PLL_CNT_NUM & 0x0000ffff; //PLL_NUM低16位
Register_R0_TX.Map.PLL_N_L = PLL_CNT_N & 0x00000fff; //PLL_N低12位
//Register_R1_TX.Map.default0 = Register_R1_default;
Register_R1_TX.Map.PLL_NUM_H = ((PLL_CNT_NUM >> 16)&0x0000003f); //PLL_NUM高6位
Register_R1_TX.Map.PLL_N_H = ((PLL_CNT_N >> 12)&0x0000003f); //PLL_N高6位
Register_R1_TX.Map.PLL_R = PLL_R_VALUE; //PLL_R
//Register_R1_TX.Map.Addr = LMX2541_REG1; //地址
Register_R4_TX.Map.VCO_DIV = VCO_DIV_TX;
Register_R6.Map.RFOUT = 0;
LMX2541_Write_Data(Register_R6.Value); //关闭射频输出
// RFEN_PLL(0); //关闭射频输出
LMX2541_Modify_LoopFilter(LMX2541_RES_1k,LMX2541_RES_200,LMX2541_CAP3_20,LMX2541_CAP4_100,VCO_DIV_TX);
// LMX2541_Write_Data(Register_R1_TX.Value); //修改R1的值
// LMX2541_Write_Data(Register_R0_TX.Value); //修改R0的值
// LMX2541_Modify_LoopFilter(LMX2541_RES_1k,LMX2541_RES_200,LMX2541_CAP3_20,LMX2541_CAP4_100,VCO_DIV_RX);
LMX2541_Write_Data(Register_R4_TX.Value); //修改R4的值
LMX2541_Write_Data(Register_R1_TX.Value); //修改R1的值
LMX2541_Write_Data(Register_R0_TX.Value); //修改R0的值
// RFEN_PLL(1); //打开射频输出
Register_R6.Map.RFOUT = 2;
LMX2541_Write_Data(Register_R6.Value); //打开射频输出
//VCTL(FOUT_RX);
//RFEN_PLL(FOUT_TX);
return 1;
}
/*
函数名称:LMX2541_Modify_RFGain
函数功能:修改LMX2541的输出增益
入口函数:
Gain_Value:输出的增益值,取值范围为0~15
出口函数:无
返回值:
1:修改成功
0:修改失败
*/
uint8_t LMX2541_Modify_RFGain(uint8_t Gain_Value)
{
if(Gain_Value<16)
{
// Register_R6.Map.RFOUT = 0; //关闭射频输出
// LMX2541_Write_Data(Register_R6.Value);
Register_R6.Map.OUTTERM = Gain_Value;
// Register_R6.Map.DIVGAIN = 12;
// Register_R6.Map.RFOUT = 1; //打开射频输出
LMX2541_Write_Data(Register_R6.Value);
return 1;
}
else
{
return 0;
}
}
/*
函数名称:LMX2541_Modify_LoopFilter
函数功能:修改LMX2541内部环路滤波器的参数
入口函数:
RES_R3:电阻R3的阻值,该值可以为 LMX2541_RES_200,LMX2541_RES_1k,LMX2541_RES_2k,LMX2541_RES_4k,LMX2541_RES_16k,分别对应的阻值为
200,1k,2k,4k,16k
RES_R4:电阻R4的阻值,该值可以为 LMX2541_RES_200,LMX2541_RES_1k,LMX2541_RES_2k,LMX2541_RES_4k,LMX2541_RES_16k,分别对应的阻值为
200,1k,2k,4k,16k
CAP_C3:电阻C3的电容值,该值可以为 LMX2541_CAP3_0,LMX2541_CAP3_1,LMX2541_CAP3_5,LMX2541_CAP3_6,LMX2541_CAP3_10,LMX2541_CAP3_11,
LMX2541_CAP3_15,LMX2541_CAP3_16,LMX2541_CAP3_20,LMX2541_CAP3_21,LMX2541_CAP3_25,LMX2541_CAP3_26,
LMX2541_CAP3_30,LMX2541_CAP3_31,LMX2541_CAP3_35,LMX2541_CAP3_36
对应的电容值为(pF): 0,1,5,6,10,11,
15,16,20,21,25,26,
30,31,35,36
CAP_C4:电阻C4的电容值,该值可以为 LMX2541_CAP4_0=0,LMX2541_CAP4_5,LMX2541_CAP4_20,LMX2541_CAP4_25,LMX2541_CAP4_40,LMX2541_CAP4_45,
LMX2541_CAP4_60,LMX2541_CAP4_65,LMX2541_CAP4_100,LMX2541_CAP4_105,LMX2541_CAP4_120,LMX2541_CAP4_125,
LMX2541_CAP4_140,LMX2541_CAP4_145,LMX2541_CAP4_160,LMX2541_CAP4_165
对应的电容值为(pF): 0,5,20,25,40,45,
60,65,100,105,120,125,
140,145,160,165
vco_div_value:VCO的分频值 0~63
出口函数:无
返回值:无
*/
void LMX2541_Modify_LoopFilter(TLMX2541_RES RES_R3,TLMX2541_RES RES_R4,TLMX2541_CAP3 CAP_C3,TLMX2541_CAP4 CAP_C4,uint8_t vco_div_value)
{
//接收寄存器4
// Register_R4_RX.Map.C4_LF = CAP_C4;
// Register_R4_RX.Map.C3_LF = CAP_C3;
// Register_R4_RX.Map.R4_LF = RES_R4;
// Register_R4_RX.Map.R3_LF = RES_R3;
// Register_R4_RX.Map.VCO_DIV = vco_div_value;
// Register_R4_RX.Map.OSC_FREQ = OSC_FREQ_VALUE;
// Register_R4_RX.Map.Addr = LMX2541_REG4;
//发射寄存器4
Register_R4_TX.Map.C4_LF = CAP_C4;
Register_R4_TX.Map.C3_LF = CAP_C3;
Register_R4_TX.Map.R4_LF = RES_R4;
Register_R4_TX.Map.R3_LF = RES_R3;
Register_R4_TX.Map.VCO_DIV = vco_div_value;
Register_R4_TX.Map.OSC_FREQ = OSC_FREQ_VALUE;
Register_R4_TX.Map.Addr = LMX2541_REG4;
// LMX2541_Write_Data(Register_R4.Value); //修改环路滤波器的值
}
/*
函数名称:PTT_SW
函数功能:收发频率切换
入口函数:ptt,收发状态 1:收状态 ; 0:发状态
出口函数:无
返回值:无
*/
void PTT_SW(uint8_t ptt)
{
// Register_R6.Map.RFOUT = 0;
// LMX2541_Write_Data(Register_R6.Value); //关闭射频输出
if(ptt)
{
RFEN_PLL(1); //关闭射频输出 PTT反相
}
else
{
RFEN_PLL(0); //打开射频输出
}
/*
if((ptt)||(VOP_ERR)) //收状态
{
LMX2541_Write_Data(Register_R4_RX.Value); //修改R4的值
LMX2541_Write_Data(Register_R1_RX.Value); //修改R1的值
LMX2541_Write_Data(Register_R0_RX.Value); //修改R0的值
//VCTL(FOUT_RX);
//RFEN_PLL(FOUT_RX);
}
else //发状态
{
LMX2541_Write_Data(Register_R4_TX.Value); //修改R4的值
LMX2541_Write_Data(Register_R1_TX.Value); //修改R1的值
LMX2541_Write_Data(Register_R0_TX.Value); //修改R0的值
//VCTL(FOUT_TX);
//RFEN_PLL(FOUT_TX);
}
*/
// Register_R6.Map.RFOUT = 1;
// LMX2541_Write_Data(Register_R6.Value); //打开射频输出
}
/*
函数名称:EINT1_Callback
函数功能:PTT中断回调函数
入口函数:param:无意义
出口函数:无
返回值:无
*/
void EINT1_Callback(void)
{
// PTT_SW(PTT_STU);
}
/*
函数名称: GPIO_GPAB_Callbackfunc
函数功能:锁定指示中断
入口函数:
portA:端口A的中断引脚指示
portB:端口B的中断引脚指示
出口函数:无
返回值:无
*/
void GPIO_GPAB_Callbackfunc(uint32_t portA,uint32_t portB)
{
// if(portB & (1<<2))
// {
// if(LOCK_STU)
// {
// SYTEST(SYNCLOCK); //频合锁定
// Register_R6.Map.RFOUT = 1;
// LMX2541_Write_Data(Register_R6.Value); //打开射频输出
// }
// else
// {
// SYTEST(SYNCUNLOCK); //频合失锁
// Register_R6.Map.RFOUT = 0;
// LMX2541_Write_Data(Register_R6.Value); //关闭射频输出
// }
// }
}
void LMX2541_Set_Register_R0(uint32_t Register_Value)
{
DrvSPI_ClrSS(eDRVSPI_PORT0, eDRVSPI_SS0); //set high
DrvSPI_SetSS(eDRVSPI_PORT0, eDRVSPI_SS0); //set low
DrvSPI_SingleWrite(eDRVSPI_PORT0,&Register_Value);
while(DrvSPI_IsBusy(eDRVSPI_PORT0));
DrvSPI_ClrSS(eDRVSPI_PORT0, eDRVSPI_SS0);
DrvSPI_SetSS(eDRVSPI_PORT0, eDRVSPI_SS0);
}
/*
函数名称: GPIO_GPCDE_Callbackfunc
函数功能:无
入口函数:
portC:端口C的中断引脚指示
portD:端口D的中断引脚指示
portE:端口E的中断引脚指示
出口函数:无
返回值:无
*/
//void GPIO_GPCDE_Callbackfunc(uint32_t portC,uint32_t portD,uint32_t portE)
//{
//
//}
void PLL_control_entry(void *parameter)
{
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
rt_enter_critical();
DrvGPIO_DisableEINT0();
DrvGPIO_DisableEINT0();
DrvGPIO_Open(E_GPC, 0, E_IO_OUTPUT);
DrvGPIO_Open(E_GPC, 1, E_IO_OUTPUT);
DrvGPIO_Open(E_GPC, 3, E_IO_OUTPUT);
DrvGPIO_Open(E_GPD, 15, E_IO_INPUT);
IniLMX2541();
LMX2541_Modify_FRE(118000,6);
/* 调度器解锁 */
rt_exit_critical();
DrvGPIO_EnableEINT0(E_IO_BOTH_EDGE, E_MODE_EDGE,
PTT_Mic_Callback);
DrvGPIO_EnableEINT1(E_IO_BOTH_EDGE, E_MODE_EDGE,
PTT_Rem_Callback);
while(1)
{
rt_thread_delay(200);
}
}
头文件如下
#ifndef PLL_THREAD_H
#define PLL_THREAD_H
#include "stdint.h"
#include "DrvGPIO.h"
#include "Globe_Value.h"
#include "GPIO_Irq_Thread.h"
#include <rtthread.h>
typedef enum {LMX2541_REG0=0,LMX2541_REG1,LMX2541_REG2,LMX2541_REG3,LMX2541_REG4,
LMX2541_REG5,LMX2541_REG6,LMX2541_REG7,LMX2541_REG8,LMX2541_REG9,
LMX2541_REG12=12,LMX2541_REG13=13}TLMX2541_REG;
typedef enum {LMX2541_RES_200=0,LMX2541_RES_1k,LMX2541_RES_2k,LMX2541_RES_4k,LMX2541_RES_16k}TLMX2541_RES;
typedef enum {LMX2541_CAP3_0=0,LMX2541_CAP3_1,LMX2541_CAP3_5,LMX2541_CAP3_6,LMX2541_CAP3_10,LMX2541_CAP3_11,
LMX2541_CAP3_15,LMX2541_CAP3_16,LMX2541_CAP3_20,LMX2541_CAP3_21,LMX2541_CAP3_25,LMX2541_CAP3_26,
LMX2541_CAP3_30,LMX2541_CAP3_31,LMX2541_CAP3_35,LMX2541_CAP3_36}TLMX2541_CAP3;
typedef enum {LMX2541_CAP4_0=0,LMX2541_CAP4_5,LMX2541_CAP4_20,LMX2541_CAP4_25,LMX2541_CAP4_40,LMX2541_CAP4_45,
LMX2541_CAP4_60,LMX2541_CAP4_65,LMX2541_CAP4_100,LMX2541_CAP4_105,LMX2541_CAP4_120,LMX2541_CAP4_125,
LMX2541_CAP4_140,LMX2541_CAP4_145,LMX2541_CAP4_160,LMX2541_CAP4_165}TLMX2541_CAP4;
//寄存器0
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t PLL_N_L:12; //PLL_N低12位
uint32_t PLL_NUM_L:16; //PLL_NUM低16位
}Map;
uint32_t Value;
}TRegister_R0;
//寄存器1
typedef union {
struct {
uint32_t Addr:4; //地址
uint32_t PLL_R:12; //PLL_R
uint32_t PLL_N_H:6; //PLL_N高6位
uint32_t PLL_NUM_H:6; //PLL_NUM高6位
uint32_t default0:4;
}Map;
uint32_t Value;
}TRegister_R1;
//寄存器2
typedef union {
struct {
uint32_t Addr:4; //地址
uint32_t PLL_DEN:22; //PLL_DEN高6位
uint32_t default0:6;
}Map;
uint32_t Value;
}TRegister_R2;
//寄存器3
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t MODE:2;
uint32_t POWERDOWN:1;
uint32_t XO:1;
uint32_t CPG:5;
uint32_t MUX:4;
uint32_t CPP:1;
uint32_t OSC_2X:1;
uint32_t FDM:1;
uint32_t ORDER:3;
uint32_t DITH:2;
uint32_t CPT:1;
uint32_t DLOCK:3;
uint32_t default0:2;
uint32_t FSK:1;
}Map;
uint32_t Value;
}TRegister_R3;
//寄存器4
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t OSC_FREQ:8;
uint32_t VCO_DIV:6;
uint32_t R3_LF:3;
uint32_t R4_LF:3;
uint32_t C3_LF:4;
uint32_t C4_LF:4;
}Map;
uint32_t Value;
}TRegister_R4;
//寄存器5
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t FL_TOC:14;
uint32_t FL_R3_LF:3;
uint32_t FL_RF_LF:3;
uint32_t FL_CPG:5;
uint32_t default0:3;
}Map;
uint32_t Value;
}TRegister_R5;
//寄存器6
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t RFOUT:2;
uint32_t DIVGAIN:4;
uint32_t OUTTERM:4;
uint32_t VCOGAIN:4;
uint32_t default0:14;
}Map;
uint32_t Value;
}TRegister_R6;
//寄存器7
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t default0:28;
}Map;
uint32_t Value;
}TRegister_R7;
//寄存器8
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t AC_TEMP_COMP:5;
uint32_t default0:23;
}Map;
uint32_t Value;
}TRegister_R8;
//寄存器9
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t default0:28;
}Map;
uint32_t Value;
}TRegister_R9;
//寄存器12
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t default0:28;
}Map;
uint32_t Value;
}TRegister_R12;
//寄存器13
typedef union {
struct{
uint32_t Addr:4; //地址
uint32_t VCO_DIV_OPT:3;
uint32_t default0:25;
}Map;
uint32_t Value;
}TRegister_R13;
#define Register_R1_default 0
#define Register_R2_default 1
#define Register_R3_default 0
#define Register_R5_default 5
#define Register_R6_default 7
#define Register_R7_default 1
#define Register_R8_default 0x88E7
#define Register_R9_default 0x2800140
#define Register_R12_default 1
#define Register_R13_default 1
#define VCO_MAX_VALUE 4000000000 //VCO的最大值
#define FPD_VALUE 1600000//400000 //鉴相频率值
#define PLL_DEN_MAX_VALUE 4194303 //分母的最大值
//#define PLL_DEN_CNT_VALUE 73100 //用于计算的 N值的分母
//#define PLL_DEN_RX_VALUE 365500 分母 5*73100
//#define PLL_DEN_TX_VALUE 146200 分母 2*73100
#define PLL_R_VALUE 8//32
//#define VCO_DIV_RX_VALUE 20
//#define VCO_DIV_TX_VALUE 25
#define OSC_FREQ_VALUE 13 //参考源的频率值(MHz)
#define FOUT_RX 1
#define FOUT_TX 0
#define SYNCLOCK 0 //频合锁定
#define SYNCUNLOCK 1 //频合失锁
#define MAXFRE 143975 //允许的最大频率值(kHz)
#define MINFRE 118000 //允许的最小频率值(kHz)
#define PLL_DIS DrvGPIO_SetBit(E_GPD, 7)
#define PLL_EN DrvGPIO_ClrBit(E_GPD, 7)
#define PLL_CLK_HIGH DrvGPIO_SetBit(E_GPD, 14)
#define PLL_CLK_LOW DrvGPIO_ClrBit(E_GPD, 14)
#define PLL_DATA_HIGH DrvGPIO_SetBit(E_GPD, 15)
#define PLL_DATA_LOW DrvGPIO_ClrBit(E_GPD, 15)
#define PLL_RF_EN DrvGPIO_SetBit(E_GPC, 5)
#define PLL_RF_DIS DrvGPIO_ClrBit(E_GPC, 5)
#define RFEN_PLL(x) ((x)?(GPIOC->DOUT |= 1<<5):(GPIOC->DOUT &= ~(1<<5)))
#define DATA_PLL(x) ((x)?(GPIOC->DOUT |= 1<<3):(GPIOC->DOUT &= ~(1<<3)))
#define CLK_PLL(x) ((x)?(GPIOC->DOUT |= 1<<1):(GPIOC->DOUT &= ~(1<<1)))
#define EN_PLL(x) ((x)?(GPIOC->DOUT |= 1<<0):(GPIOC->DOUT &= ~(1<<0)))
extern void PLL_control_entry(void *parameter);
#endif