adf4153(7317).c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /******************************************************************************
  2. * @file ADF4153.c
  3. * @brief Implementation of ADF4153 Driver for Microblaze processor.
  4. * @author Istvan Csomortani (istvan.csomortani@analog.com)
  5. *
  6. *******************************************************************************
  7. * Copyright 2013(c) Analog Devices, Inc.
  8. *
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * - Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. * - Neither the name of Analog Devices, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. * - The use of this software may or may not infringe the patent rights
  23. * of one or more patent holders. This license does not release you
  24. * from the requirement that you obtain separate licenses from these
  25. * patent holders to use this software.
  26. * - Use of the software either in source or binary form, must be run
  27. * on or directly connected to an Analog Devices Inc. component.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
  30. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
  31. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  32. * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  36. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. ******************************************************************************/
  41. /*****************************************************************************/
  42. /****************************** Include Files ********************************/
  43. /*****************************************************************************/
  44. #include "adf4153.h"
  45. #include <math.h>
  46. typedef struct _adf4153_st{
  47. unsigned long long PFD_Value;
  48. uint16_t MOD_Value;
  49. uint16_t FRAC_Value;
  50. uint16_t INT_Value;
  51. float N_Value;
  52. }adf4153_st;
  53. /*
  54. #define ROUNDING(x, dig) ( floor((x) * pow(float(10), dig) + 0.5f) / pow(float(10), dig) )
  55. double Rounding( double x, int digit )
  56. {
  57. return ( floor( (x) * pow( float(10), digit ) + 0.5f ) / pow( float(10), digit ) );
  58. }
  59. */
  60. void ADF4153_Freq_Calc(unsigned long long Freq,unsigned long long REFin,uint8_t R_Counter,uint32_t chspacing){
  61. adf4153_st temp_adf4153;
  62. temp_adf4153.PFD_Value = REFin / (R_Counter * 1000);
  63. temp_adf4153.MOD_Value = temp_adf4153.PFD_Value / chspacing;
  64. temp_adf4153.FRAC_Value = ((Freq* temp_adf4153.MOD_Value) / (REFin / R_Counter));
  65. temp_adf4153.INT_Value = Freq / temp_adf4153.PFD_Value;
  66. temp_adf4153.N_Value = ((float)(Freq / 1000) / (float)(temp_adf4153.PFD_Value / 1000) / 1000);
  67. printf("temp_adf4153.N_Value : %x : %f ",temp_adf4153.N_Value,temp_adf4153.N_Value);
  68. printf("temp_adf4153.MOD_Value : %x : %d ",temp_adf4153.MOD_Value,temp_adf4153.MOD_Value);
  69. for(uint8_t i = 0; i < 12; i++){
  70. if(temp_adf4153.MOD_Value & 0x800){
  71. printf("1");
  72. }else{
  73. printf("0");
  74. }
  75. temp_adf4153.MOD_Value = temp_adf4153.MOD_Value << 1;
  76. }
  77. printf("\r\n");
  78. printf("temp_adf4153.FRAC_Value : %x : %d\r\n",temp_adf4153.FRAC_Value,temp_adf4153.FRAC_Value);
  79. for(uint8_t i = 0; i < 12; i++){
  80. if(temp_adf4153.FRAC_Value & 0x800){
  81. printf("1");
  82. }else{
  83. printf("0");
  84. }
  85. temp_adf4153.FRAC_Value = temp_adf4153.FRAC_Value << 1;
  86. }
  87. printf("\r\n");
  88. printf("temp_adf4153.INT_Value : %x : %d\r\n",temp_adf4153.INT_Value,temp_adf4153.INT_Value);
  89. for(uint8_t i = 0; i < 9; i++){
  90. if(temp_adf4153.INT_Value & 0x100){
  91. printf("1");
  92. }else{
  93. printf("0");
  94. }
  95. temp_adf4153.INT_Value = temp_adf4153.INT_Value << 1;
  96. }
  97. printf("\r\n");
  98. }
  99. void ADF_Module_Ctrl(PLL_Setting_st pll,uint32_t R0,uint32_t R1,uint32_t R2,uint32_t R3){
  100. R3 = R3 & 0x0007FF;
  101. R2 = R2 & 0x00FFFF;
  102. R1 = R1 & 0xFFFFFF;
  103. R0 = R0 & 0xFFFFFF;
  104. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  105. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  106. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  107. /* R3 Ctrl */
  108. for(int i =0; i < 11; i++){
  109. if(R3 & 0x000700)
  110. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  111. else
  112. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  113. HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_SET);
  114. HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_RESET);
  115. R3 = ((R3 << 1) & 0x00000FFF);
  116. }
  117. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  118. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  119. /* R2 Ctrl */
  120. for(int i =0; i < 16; i++){
  121. if(R2 & 0x008000)
  122. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  123. else
  124. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  125. HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_SET);
  126. HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_RESET);
  127. R2 = ((R2 << 1) & 0x00FFFF);
  128. }
  129. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  130. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  131. /* R1 Ctrl */
  132. for(int i =0; i < 24; i++){
  133. if(R1 & 0x800000)
  134. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  135. else
  136. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  137. HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_SET);
  138. HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_RESET);
  139. R1 = ((R1 << 1) & 0xFFFFFF);
  140. }
  141. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  142. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  143. /* R0 Ctrl */
  144. for(int i =0; i < 24; i++){
  145. if(R0 & 0x800000)
  146. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  147. else
  148. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  149. HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_SET);
  150. HAL_GPIO_WritePin(PLL_CLK_GPIO_Port, PLL_CLK_Pin, GPIO_PIN_RESET);
  151. R0 = ((R0 << 1) & 0xFFFFFF);
  152. }
  153. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  154. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  155. }