/****************************************************************************** * @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; uint16_t FRAC_Value; uint16_t INT_Value; }adf4153_st; void ADF4153_Freq_Calc(unsigned long long Freq,unsigned long long REFin,uint8_t R_Counter,uint32_t chspacing){ adf4153_st temp_adf4153; temp_adf4153.PFD_Value = REFin / R_Counter; temp_adf4153.MOD_Value = temp_adf4153.PFD_Value / chspacing; temp_adf4153.FRAC_Value = (double)(Freq / temp_adf4153.PFD_Value) * temp_adf4153.MOD_Value; temp_adf4153.INT_Value = Freq / temp_adf4153.PFD_Value; printf("temp_adf4153.MOD_Value : %x : ",temp_adf4153.MOD_Value); for(uint8_t i = 0; i < 12; i++){ if(temp_adf4153.MOD_Value & 0x800){ printf("1"); }else{ printf("0"); } temp_adf4153.MOD_Value = temp_adf4153.MOD_Value << 1; } printf("\r\n"); printf("temp_adf4153.FRAC_Value : %f\r\n",temp_adf4153.FRAC_Value); for(uint8_t i = 0; i < 12; i++){ if(temp_adf4153.FRAC_Value & 0x800){ printf("1"); }else{ printf("0"); } temp_adf4153.FRAC_Value = temp_adf4153.FRAC_Value << 1; } printf("\r\n"); printf("temp_adf4153.INT_Value : %x\r\n",temp_adf4153.INT_Value); for(uint8_t i = 0; i < 9; i++){ if(temp_adf4153.INT_Value & 0x100){ printf("1"); }else{ printf("0"); } temp_adf4153.INT_Value = temp_adf4153.INT_Value << 1; } printf("\r\n"); } 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_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET); /* R3 Ctrl */ for(int i =0; i < 11; i++){ if(R3 & 0x000700) HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET); else HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_RESET); R3 = ((R3 << 1) & 0x00000FFF); } 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_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET); else HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_RESET); R2 = ((R2 << 1) & 0x00FFFF); } 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_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET); else HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_RESET); R1 = ((R1 << 1) & 0xFFFFFF); } 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_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET); else HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_RESET); R0 = ((R0 << 1) & 0xFFFFFF); } 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); }