/****************************************************************************** * @file ADF4153.c * @brief Implementation of ADF4153 Driver for Microblaze processor. * @author Istvan Csomortani (istvan.csomortani@analog.com) * ******************************************************************************* * Copyright 2013(c) Analog Devices, Inc. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of Analog Devices, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * - The use of this software may or may not infringe the patent rights * of one or more patent holders. This license does not release you * from the requirement that you obtain separate licenses from these * patent holders to use this software. * - Use of the software either in source or binary form, must be run * on or directly connected to an Analog Devices Inc. component. * * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************/ /*****************************************************************************/ /****************************** Include Files ********************************/ /*****************************************************************************/ #include "adf4153.h" typedef struct _adf4153_st{ unsigned long long PFD_Value; uint16_t MOD_Value; uint32_t FRAC_Value; uint16_t INT_Value; double N_Value; }adf4153_st; uint32_t pow2(uint32_t val,int32_t val2){ for(uint8_t i = 0; i < val2 - 1; i++){ val = val * val; } return val; } double round_up( double value, int pos ) { double temp; temp = value * pow2( 10, pos ); // �썝�븯�뒗 �냼�닔�젏 �옄由ъ닔留뚰겮 10�쓽 �늻�듅�쓣 �븿 temp = (int)(temp + 0.5); // 0.5瑜� �뜑�븳�썑 踰꾨┝�븯硫� 諛섏삱由쇱씠 �맖 temp *= pow2( 10, -pos ); // �떎�떆 �썝�옒 �냼�닔�젏 �옄由ъ닔濡� return temp; } double N_Reg_Value_Calc(double val){ return val / 1000; } uint32_t N_Divider_Reg_Create(uint16_t _FRAC,uint16_t _INT,uint8_t _FASTLOCK){ uint32_t ret = 0; uint32_t shift_bit = 0x01; uint8_t control_bit = 0; uint8_t i = 0; printf("FRAC : %d INT : %d \r\n",_FRAC,_INT); for(i = 0; i < 2; i++){ if(control_bit & 0x01) ret += shift_bit << i; control_bit = control_bit >> 1; } printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret); for(i = 2; i < 14; i++){ if(_FRAC & 0x01) ret += shift_bit << i; _FRAC = _FRAC >> 1; } printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret); for(i = 14; i < 22; i++){ if(_INT & 0x01) ret += shift_bit << i; _INT = _INT >> 1; } printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret); if(_FASTLOCK & 0x01) ret += shift_bit << i; printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret); return ret; } uint32_t R_Divider_Reg_Create(uint16_t _MOD,uint8_t _RCOUNTER,uint8_t _PRESCALER,uint8_t _RESERVED,uint8_t _MUXOUT,uint8_t LOAD_CONTROL){ uint32_t ret = 0; uint32_t shift_bit = 0x01; uint8_t control_bit = 1; uint8_t i = 0; printf("_MOD : %d INT : %d \r\n",_MOD,_RCOUNTER); printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret); for(i = 0; i < 2; i++){ if(control_bit & 0x01) ret += shift_bit << i; control_bit = control_bit >> 1; } printf("\r\nLINE : %d ret : %x\r\n",__LINE__,ret); for(i = 2; i < 14; i++){ if(_MOD & 0x01) ret += shift_bit << i; _MOD = _MOD >> 1; } for(i = 14; i < 18; i++){ if(_RCOUNTER & 0x01) ret += shift_bit << i; _RCOUNTER = _RCOUNTER >> 1; } if(_PRESCALER & 0x01) ret += shift_bit << i++; if(_RESERVED & 0x01) ret += shift_bit << i++; for(i = 19; i < 22; i++){ if(_MUXOUT & 0x01) ret += shift_bit << i; _MUXOUT = _MUXOUT >> 1; } if(LOAD_CONTROL & 0x01) ret += shift_bit << i++; return ret; } void ADF4153_Freq_Calc(unsigned long long Freq,unsigned long long REFin,uint8_t R_Counter,uint32_t chspacing){ adf4153_st temp_adf4153; double temp = 0; temp_adf4153.PFD_Value = REFin / (R_Counter * 1000); temp_adf4153.MOD_Value = (temp_adf4153.PFD_Value / chspacing) * 1000; temp_adf4153.N_Value = N_Reg_Value_Calc(((double)(Freq / 1000) / (double)(temp_adf4153.PFD_Value / 1000))); temp_adf4153.INT_Value = temp_adf4153.N_Value ; // printf("\r\ntemp_adf4153.N_Value : %f temp_adf4153.INT_Value : %f temp_adf4153.MOD_Value : %f \r\n",temp_adf4153.N_Value,(double)temp_adf4153.INT_Value,(double)temp_adf4153.MOD_Value); temp = temp_adf4153.N_Value - (double)temp_adf4153.INT_Value; // printf("\r\n temp_adf4153.N_Value - (double)temp_adf4153.INT_Value) : %f temp * (double)temp_adf4153.MOD_Value : %f \r\n",temp,temp * (double)temp_adf4153.MOD_Value); temp_adf4153.FRAC_Value = (float)temp * temp_adf4153.MOD_Value; printf("\r\ntemp_adf4153.N_Value : %x : %f ",temp_adf4153.N_Value,((double)(Freq / 1000) / (double)(temp_adf4153.PFD_Value / 1000)) / 1000); printf("temp_adf4153.MOD_Value : %x : %d \r\n",temp_adf4153.MOD_Value,temp_adf4153.MOD_Value); uint16_t tempmod = temp_adf4153.FRAC_Value; for(uint8_t i = 0; i < 12; i++){ if(temp_adf4153.MOD_Value & 0x800){ printf("1"); }else{ printf("0"); } tempmod = tempmod << 1; } printf("\r\n"); printf("temp_adf4153.FRAC_Value : %x : %d\r\n",temp_adf4153.FRAC_Value,temp_adf4153.FRAC_Value); uint16_t tempfrac = temp_adf4153.FRAC_Value; for(uint8_t i = 0; i < 12; i++){ if(tempfrac & 0x800){ printf("1"); }else{ printf("0"); } tempfrac = tempfrac << 1; } printf("\r\n"); printf("temp_adf4153.INT_Value : %x : %d\r\n",temp_adf4153.INT_Value,temp_adf4153.INT_Value); uint16_t tempint = temp_adf4153.INT_Value; for(uint8_t i = 0; i < 9; i++){ if(tempint & 0x100){ printf("1"); }else{ printf("0"); } tempint = tempint << 1; } printf("\r\n"); printf("R0: %x R1: %x \r\n",N_Divider_Reg_Create(temp_adf4153.FRAC_Value,temp_adf4153.INT_Value,0),R_Divider_Reg_Create(temp_adf4153.MOD_Value,R_Counter,1,0,2,0)); // R_Divider_Reg_Create(temp_adf4153.MOD_Value,R_Counter,1,0,1,0); //prescaler 1 : 8/9 0: 4/5 } void ADF_Module_Ctrl(PLL_Setting_st pll,uint32_t R0,uint32_t R1,uint32_t R2,uint32_t R3){ R3 = R3 & 0x0007FF; R2 = R2 & 0x00FFFF; R1 = R1 & 0xFFFFFF; R0 = R0 & 0xFFFFFF; HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET); printf("YJ : R3 : %x ",R3); printf("\r\n"); /* R3 Ctrl */ for(int i =0; i < 11; i++){ if(R3 & 0x000400){ HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET); printf("1"); } else{ HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET); printf("0"); } HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); R3 = (R3 << 1); } printf("\r\n"); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET); /* R2 Ctrl */ for(int i =0; i < 16; i++){ if(R2 & 0x008000){ HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET); printf("1"); } else{ HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET); printf("0"); } HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); R2 = ((R2 << 1) & 0x00FFFF); } printf("\r\n"); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET); /* R1 Ctrl */ for(int i =0; i < 24; i++){ if(R1 & 0x800000){ HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET); printf("1"); } else{ HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET); printf("0"); } HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); R1 = ((R1 << 1) & 0xFFFFFF); } printf("\r\n"); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET); /* R0 Ctrl */ for(int i =0; i < 24; i++){ if(R0 & 0x800000){ HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET); printf("1"); } else{ HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET); printf("0"); } HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); R0 = ((R0 << 1) & 0xFFFFFF); } printf("\r\n"); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET); }