adf4153(7445).h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /**************************************************************************//**
  2. * @file adf4153.h
  3. * @brief Header file of adf4153 driver.
  4. *
  5. * @author Istvan Csomortani (istvan.csomortani@analog.com)
  6. *
  7. *******************************************************************************
  8. * Copyright 2013(c) Analog Devices, Inc.
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without modification,
  13. * are permitted provided that the following conditions are met:
  14. * - Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. * - Neither the name of Analog Devices, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. * - The use of this software may or may not infringe the patent rights
  24. * of one or more patent holders. This license does not release you
  25. * from the requirement that you obtain separate licenses from these
  26. * patent holders to use this software.
  27. * - Use of the software either in source or binary form, must be run
  28. * on or directly connected to an Analog Devices Inc. component.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
  31. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
  32. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  33. * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35. * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  36. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  37. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  39. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ******************************************************************************/
  42. #ifndef __ADF4153_H__
  43. #define __ADF4153_H__
  44. #include "main.h"
  45. /*****************************************************************************/
  46. /* Device specific MACROs */
  47. /*****************************************************************************/
  48. /* Control Bits */
  49. #define ADF4153_CTRL_MASK 0x3
  50. #define ADF4153_CTRL_N_DIVIDER 0 /* N Divider Register */
  51. #define ADF4153_CTRL_R_DIVIDER 1 /* R Divider Register */
  52. #define ADF4153_CTRL_CONTROL 2 /* Control Register */
  53. #define ADF4153_CTRL_NOISE_SPUR 3 /* Noise and Spur Reg*/
  54. /* N Divider Register */
  55. /* 12-bit fractional value */
  56. #define ADF4153_R0_FRAC_OFFSET 2
  57. #define ADF4153_R0_FRAC_MASK 0xFFF
  58. #define ADF4153_R0_FRAC(x) ((x) & ADF4153_R0_FRAC_MASK) \
  59. << ADF4153_R0_FRAC_OFFSET
  60. /* 9-bit integer value */
  61. #define ADF4153_R0_INT_OFFSET 14
  62. #define ADF4153_R0_INT_MASK 0x1FF
  63. #define ADF4153_R0_INT(x) ((x) & ADF4153_R0_INT_MASK) \
  64. << ADF4153_R0_INT_OFFSET
  65. /* Fast-Lock */
  66. #define ADF4153_R0_FASTLOCK_OFFSET 23
  67. #define ADF4153_R0_FASTLOCK_MASK 0x1
  68. #define ADF4153_R0_FASTLOCK(x) ((x) & ADF4153_R0_FASTLOCK_MASK) \
  69. << ADF4153_R0_FASTLOCK_OFFSET
  70. /* R Divider Register */
  71. /* 12-bit interpolator modulus value */
  72. #define ADF4153_R1_MOD_OFFSET 2
  73. #define ADF4153_R1_MOD_MASK 0xFFF
  74. #define ADF4153_R1_MOD(x) ((x) & ADF4153_R1_MOD_MASK) \
  75. << ADF4153_R1_MOD_OFFSET
  76. /* 4-bit R Counter */
  77. #define ADF4153_R1_RCOUNTER_OFFSET 14
  78. #define ADF4153_R1_RCOUNTER_MASK 0xF
  79. #define ADF4153_R1_RCOUNTER(x) ((x) & ADF4153_R1_RCOUNTER_MASK) \
  80. << ADF4153_R1_RCOUNTER_OFFSET
  81. /* Prescale */
  82. #define ADF4153_R1_PRESCALE_OFFSET 18
  83. #define ADF4153_R1_PRESCALE_MASK 0x1
  84. #define ADF4153_R1_PRESCALE(x) ((x) & ADF4153_R1_PRESCALE_MASK) \
  85. << ADF4153_R1_PRESCALE_OFFSET
  86. /* MUXOUT */
  87. #define ADF4153_R1_MUXOUT_OFFSET 20
  88. #define ADF4153_R1_MUXOUT_MASK 0x7
  89. #define ADF4153_R1_MUXOUT(x) ((x) & ADF4153_R1_MUXOUT_MASK) \
  90. << ADF4153_R1_MUXOUT_OFFSET
  91. /* Load Control */
  92. #define ADF4153_R1_LOAD_OFFSET 23
  93. #define ADF4153_R1_LOAD_MASK 0x1
  94. #define ADF4153_R1_LOAD(x) ((x) & ADF4153_R1_LOAD_MASK) \
  95. << ADF4153_R1_LOAD_OFFSET
  96. /* Control Register */
  97. /* Counter Reset */
  98. #define ADF4153_R2_COUNTER_RST_OFFSET 2
  99. #define ADF4153_R2_COUNTER_RST_MASK 0x1
  100. #define ADF4153_R2_COUNTER_RST(x) ((x) & ADF4153_R2_COUNTER_RST_MASK)\
  101. << ADF4153_R2_COUNTER_RST_OFFSET
  102. /* CP Three-State */
  103. #define ADF4153_R2_CP_3STATE_OFFSET 3
  104. #define ADF4153_R2_CP_3STATE_MASK 0x1
  105. #define ADF4153_R2_CP_3STATE(x) ((x) & ADF4153_R2_CP_3STATE_MASK) \
  106. << ADF4153_R2_CP_3STATE_OFFSET
  107. /* Power-down */
  108. #define ADF4153_R2_POWER_DOWN_OFFSET 4
  109. #define ADF4153_R2_POWER_DOWN_MASK 0x1
  110. #define ADF4153_R2_POWER_DOWN(x) ((x) & ADF4153_R2_POWER_DOWN_MASK) \
  111. << ADF4153_R2_POWER_DOWN_OFFSET
  112. /* LDP */
  113. #define ADF4153_R2_LDP_OFFSET 5
  114. #define ADF4153_R2_LDP_MASK 0x1
  115. #define ADF4153_R2_LDP(x) ((x) & ADF4153_R2_LDP_MASK) \
  116. << ADF4153_R2_LDP_OFFSET
  117. /* PD Polarity */
  118. #define ADF4153_R2_PD_POL_OFFSET 6
  119. #define ADF4153_R2_PD_POL_MASK 0x1
  120. #define ADF4153_R2_PD_POL(x) ((x) & ADF4153_R2_PD_POL_MASK) \
  121. << ADF4153_R2_PD_POL_OFFSET
  122. /* CP Current Settings and CP/2 */
  123. #define ADF4153_R2_CP_CURRENT_OFFSET 7
  124. #define ADF4153_R2_CP_CURRENT_MASK 0xF
  125. #define ADF4153_R2_CP_CURRENT(x) ((x) & ADF4153_R2_CP_CURRENT_MASK) \
  126. << ADF4153_R2_CP_CURRENT_OFFSET
  127. /* Reference doubler */
  128. #define ADF4153_R2_REF_DOUBLER_OFFSET 11
  129. #define ADF4153_R2_REF_DOUBLER_MASK 0x1
  130. #define ADF4153_R2_REF_DOUBLER(x) ((x) & ADF4153_R2_REF_DOUBLER_MASK)\
  131. << ADF4153_R2_REF_DOUBLER_OFFSET
  132. /* Resync */
  133. #define ADF4153_R2_RESYNC_OFFSET 12
  134. #define ADF4153_R2_RESYNC_MASK 0x7
  135. #define ADF4153_R2_RESYNC(x) ((x) & ADF4153_R2_RESYNC_MASK) \
  136. << ADF4153_R2_RESYNC_OFFSET
  137. /* Noise and spur register */
  138. /* Noise and spur mode */
  139. #define ADF4153_R3_NOISE_SPURG_MASK 0x3C4
  140. #define ADF4153_R3_NOISE_SPURG(x) ( (((x) << 0x2) & 0x7) | \
  141. (((x) >> 0x1) << 0x6) ) &\
  142. ADF4153_R3_NOISE_SPURG_MASK
  143. /* Fast-Lock definitions */
  144. #define ADF4153_FASTLOCK_DISABLED 0
  145. #define ADF4153_FASTLOCK_ENABLED 1
  146. /* Prescale definitions */
  147. #define ADF4153_PRESCALER_4_5 0
  148. #define ADF4153_PRESCALER_8_9 1
  149. /* Muxout definitions */
  150. #define ADF4153_MUXOUT_THREESTATE 0
  151. #define ADF4153_MUXOUT_DIGITAL_LOCK 1
  152. #define ADF4153_MUXOUT_NDIV_OUTPUT 2
  153. #define ADF4153_MUXOUT_LOGICHIGH 3
  154. #define ADF4153_MUXOUT_RDIV_OUTPUT 4
  155. #define ADF4153_MUXOUT_ANALOG_LOCK 5
  156. #define ADF4153_MUXOUT_FASTLOCK 6
  157. #define ADF4153_MUXOUT_LOGICLOW 7
  158. /* Load Control definitions */
  159. #define ADF4153_LOAD_NORMAL 0
  160. #define ADF4153_LOAD_RESYNC 1
  161. /* Counter Reset Definitions */
  162. #define ADF4153_CR_DISABLED 0
  163. #define ADF4153_CR_ENABLED 1
  164. /* CP Three-state definitions */
  165. #define ADF4153_CP_DISABLED 0
  166. #define ADF4153_CP_THREE_STATE 1
  167. /* Power-down definitions */
  168. #define ADF4153_PD_DISABLED 0
  169. #define ADF4153_PD_ENABLED 1
  170. /* LDP definitions */
  171. #define ADF4153_LDP_24 0
  172. #define ADF4153_LDP_40 1
  173. /* PD Polarity definitions */
  174. #define ADF4153_PD_POL_NEGATIV 0
  175. #define ADF4153_PD_POL_POSITIVE 1
  176. /* CR Current Settings definitions */
  177. #define ADF4153_CP_CURRENT_0_63 0
  178. #define ADF4153_CP_CURRENT_1_25 1
  179. #define ADF4153_CP_CURRENT_1_88 2
  180. #define ADF4153_CP_CURRENT_2_50 3
  181. #define ADF4153_CP_CURRENT_3_13 4
  182. #define ADF4153_CP_CURRENT_3_75 5
  183. #define ADF4153_CP_CURRENT_4_38 6
  184. #define ADF4153_CP_CURRENT_5_00 7
  185. #define ADF4153_CP2_CURRENT_0_31 8
  186. #define ADF4153_CP2_CURRENT_0_63 9
  187. #define ADF4153_CP2_CURRENT_0_94 10
  188. #define ADF4153_CP2_CURRENT_1_25 11
  189. #define ADF4153_CP2_CURRENT_1_57 12
  190. #define ADF4153_CP2_CURRENT_1_88 13
  191. #define ADF4153_CP2_CURRENT_2_19 14
  192. #define ADF4153_CP2_CURRENT_2_50 15
  193. /* Reference doubler definition */
  194. #define ADF4153_REF_DOUBLER_DIS 0
  195. #define ADF4153_REF_DOUBLER_EN 1
  196. /* Noise and Spur mode definitions */
  197. #define ADF4153_LOW_SPUR_MODE 0b00000
  198. #define ADF4153_LOW_NOISE_SPUR 0b11100
  199. #define ADF4153_LOWEST_NOISE 0b11111
  200. /* The default slave ID for SPI interface */
  201. #define ADF4153_SLAVE_ID 1
  202. /*****************************************************************************/
  203. /************************** Types Declarations *******************************/
  204. /*****************************************************************************/
  205. /**
  206. * struct ADF4106_settings_t - store the value of all the latch and the input
  207. * reference frequency
  208. *
  209. * N Divider Register
  210. * @fracValue - these 12 bits control what is loaded as the FRAC value into
  211. * the fractional interpolator.
  212. * @intValue - these nine bits control what is loaded as the INT value, this
  213. * is used to determine the overall division factor
  214. * @fastlock - when set to logic high fast-lock is enabled
  215. *
  216. * R Divider Register
  217. * @modValue - set the fractional modulus, this is the ratio of the PFD
  218. * frequency to the channel step resolution on the RF output
  219. * @rCounter - the r counter allows the input reference frequency to
  220. * be divided down to produce the reference clock to phase
  221. * frequency detector
  222. * @prescaler - the dual-modulus prescaler, along with the INT, FRAC and MOD
  223. * counters, determines the overall division ratio from the RFin
  224. * to PFD input
  225. * @muxout - the on chip multiplexer selection bits
  226. * @loadControl - when set to logic high the value being programmed in the
  227. * modulus is not loaded into the modulus. Instead, it sets the
  228. * resync delay of the Sigma-Delta.
  229. *
  230. * Control Register
  231. * @counterReset - resets the R and N counters
  232. * @cpThreeState - puts the charge pump into three-state mode when programmed
  233. * to 1
  234. * @powerDown - activate power down mode
  235. * @ldp - lock detect precision
  236. * @pdPolarity - phase detector polarity
  237. * @cpCurrent - Charge Pump Current settings, this should be set to the charge
  238. * pump current that the loop filter is designed with
  239. * @refDoubler - REFin Doubler, when the doubler is enabled, both the rising
  240. * and falling edges of REFin become active edges at the PFD input
  241. * @resync - define the time between two resync, if it is zero, than
  242. * the phase resync feature is disabled
  243. *
  244. * Noise and Spur register
  245. * @noiseSpur - allows the user to optimize a design either for improved
  246. * spurious performance or for improved phase noise performance
  247. */
  248. typedef struct _ADF4153_settings_t {
  249. /* Reference Input Frequency*/
  250. uint32_t refIn;
  251. /* Channel resolution or Channel spacing */
  252. uint32_t channelSpacing;
  253. /* N Divider */
  254. unsigned short fracValue : 12;
  255. unsigned short intValue : 9;
  256. unsigned char fastlock : 1;
  257. /* R Divider */
  258. unsigned short modValue : 12;
  259. unsigned char rCounter : 4;
  260. unsigned char prescaler : 1;
  261. unsigned char muxout : 3;
  262. unsigned char loadControl : 1;
  263. /* Control Register */
  264. unsigned char counterReset : 1;
  265. unsigned char cpThreeState : 1;
  266. unsigned char powerDown : 1;
  267. unsigned char ldp : 1;
  268. unsigned char pdPolarity : 1;
  269. unsigned char cpCurrent : 4;
  270. unsigned char refDoubler : 1;
  271. unsigned char resync : 4;
  272. /* Noise and Spur register */
  273. unsigned char noiseSpur : 5;
  274. } ADF4153_settings_t;
  275. typedef struct _PLL_Setting_st{
  276. GPIO_TypeDef * PLL_CLK_PORT;
  277. uint16_t PLL_CLK_PIN;
  278. GPIO_TypeDef * PLL_DATA_PORT;
  279. uint16_t PLL_DATA_PIN;
  280. GPIO_TypeDef * PLL_ENABLE_PORT;
  281. uint16_t PLL_ENABLE_PIN;
  282. } PLL_Setting_st;
  283. /*****************************************************************************/
  284. /* Functions Prototypes */
  285. /*****************************************************************************/
  286. /* Initialize the communication with the device */
  287. char ADF4153_Init(ADF4153_settings_t ADF4153_st);
  288. /* Update register function */
  289. void ADF4153_UpdateLatch(uint32_t latchData);
  290. /* Return the value of a desired latch */
  291. unsigned long ADF4153_ReadLatch(unsigned char latchType);
  292. /* Set the frequency to a desired value */
  293. unsigned long long ADF4153_SetFrequency(unsigned long long frequency);
  294. /* Return the value of the channel spacing */
  295. unsigned long ADF4153_GetChannelSpacing( void );
  296. /* Return the value of the R counter*/
  297. uint8_t ADF4153_GetRcounter(void);
  298. void ADF_Module_Ctrl(PLL_Setting_st pll,uint32_t R0,uint32_t R1,uint32_t R2,uint32_t R3);
  299. #endif // __ADF4153_H__