adf4153(6590).c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. typedef struct _adf4153_st{
  46. unsigned long long PFD_Value;
  47. uint16_t MOD_Value;
  48. uint16_t FRAC_Value;
  49. uint16_t INT_Value;
  50. double N_Value;
  51. }adf4153_st;
  52. uint32_t pow2(uint32_t val,int32_t val2){
  53. for(uint8_t i = 0; i < val2 - 1; i++){
  54. val = val * val;
  55. }
  56. return val;
  57. }
  58. double round_up( double value, int pos )
  59. {
  60. double temp;
  61. temp = value * pow2( 10, pos ); // �썝�븯�뒗 �냼�닔�젏 �옄由ъ닔留뚰겮 10�쓽 �늻�듅�쓣 �븿
  62. temp = (int)(temp + 0.5); // 0.5瑜� �뜑�븳�썑 踰꾨┝�븯硫� 諛섏삱由쇱씠 �맖
  63. temp *= pow2( 10, -pos ); // �떎�떆 �썝�옒 �냼�닔�젏 �옄由ъ닔濡�
  64. return temp;
  65. }
  66. double N_Reg_Value_Calc(double val){
  67. return val / 1000;
  68. }
  69. void ADF4153_Freq_Calc(unsigned long long Freq,unsigned long long REFin,uint8_t R_Counter,uint32_t chspacing){
  70. adf4153_st temp_adf4153;
  71. double temp = 0;
  72. temp_adf4153.PFD_Value = REFin / (R_Counter * 1000);
  73. temp_adf4153.MOD_Value = (temp_adf4153.PFD_Value / chspacing) * 1000;
  74. temp_adf4153.N_Value = N_Reg_Value_Calc(((double)(Freq / 1000) / (double)(temp_adf4153.PFD_Value / 1000)));
  75. temp_adf4153.INT_Value = temp_adf4153.N_Value ;
  76. 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);
  77. temp = temp_adf4153.N_Value - (double)temp_adf4153.INT_Value;
  78. printf("\r\n temp_adf4153.N_Value - (double)temp_adf4153.INT_Value) : %f temp * (double)temp_adf4153.MOD_Value \r\n",temp,temp * (double)temp_adf4153.MOD_Value);
  79. temp_adf4153.FRAC_Value = (temp_adf4153.N_Value - (double)temp_adf4153.INT_Value) * (double)temp_adf4153.MOD_Value;
  80. printf("\r\ntemp_adf4153.N_Value : %x : %f ",temp_adf4153.N_Value,((double)(Freq / 1000) / (double)(temp_adf4153.PFD_Value / 1000)) / 1000);
  81. printf("temp_adf4153.MOD_Value : %x : %d \r\n",temp_adf4153.MOD_Value,temp_adf4153.MOD_Value);
  82. for(uint8_t i = 0; i < 12; i++){
  83. if(temp_adf4153.MOD_Value & 0x800){
  84. printf("1");
  85. }else{
  86. printf("0");
  87. }
  88. temp_adf4153.MOD_Value = temp_adf4153.MOD_Value << 1;
  89. }
  90. printf("\r\n");
  91. printf("temp_adf4153.FRAC_Value : %x : %d\r\n",temp_adf4153.FRAC_Value,temp_adf4153.FRAC_Value);
  92. for(uint8_t i = 0; i < 12; i++){
  93. if(temp_adf4153.FRAC_Value & 0x800){
  94. printf("1");
  95. }else{
  96. printf("0");
  97. }
  98. temp_adf4153.FRAC_Value = temp_adf4153.FRAC_Value << 1;
  99. }
  100. printf("\r\n");
  101. printf("temp_adf4153.INT_Value : %x : %d\r\n",temp_adf4153.INT_Value,temp_adf4153.INT_Value);
  102. for(uint8_t i = 0; i < 9; i++){
  103. if(temp_adf4153.INT_Value & 0x100){
  104. printf("1");
  105. }else{
  106. printf("0");
  107. }
  108. temp_adf4153.INT_Value = temp_adf4153.INT_Value << 1;
  109. }
  110. printf("\r\n");
  111. }
  112. void ADF_Module_Ctrl(PLL_Setting_st pll,uint32_t R0,uint32_t R1,uint32_t R2,uint32_t R3){
  113. R3 = R3 & 0x0007FF;
  114. R2 = R2 & 0x00FFFF;
  115. R1 = R1 & 0xFFFFFF;
  116. R0 = R0 & 0xFFFFFF;
  117. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  118. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  119. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  120. /* R3 Ctrl */
  121. for(int i =0; i < 11; i++){
  122. if(R3 & 0x000700)
  123. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET);
  124. else
  125. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  126. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  127. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  128. R3 = ((R3 << 1) & 0x00000FFF);
  129. }
  130. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  131. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  132. /* R2 Ctrl */
  133. for(int i =0; i < 16; i++){
  134. if(R2 & 0x008000)
  135. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET);
  136. else
  137. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  138. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  139. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  140. R2 = ((R2 << 1) & 0x00FFFF);
  141. }
  142. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  143. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  144. /* R1 Ctrl */
  145. for(int i =0; i < 24; i++){
  146. if(R1 & 0x800000)
  147. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET);
  148. else
  149. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  150. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  151. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  152. R1 = ((R1 << 1) & 0xFFFFFF);
  153. }
  154. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  155. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  156. /* R0 Ctrl */
  157. for(int i =0; i < 24; i++){
  158. if(R0 & 0x800000)
  159. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_SET);
  160. else
  161. HAL_GPIO_WritePin(pll.PLL_DATA_PORT, pll.PLL_DATA_PIN, GPIO_PIN_RESET);
  162. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_SET);
  163. HAL_GPIO_WritePin(pll.PLL_CLK_PORT, pll.PLL_CLK_PIN, GPIO_PIN_RESET);
  164. R0 = ((R0 << 1) & 0xFFFFFF);
  165. }
  166. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_SET);
  167. HAL_GPIO_WritePin(pll.PLL_ENABLE_PORT, pll.PLL_ENABLE_PIN, GPIO_PIN_RESET);
  168. }