lt_fdc2214.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef __FDC2214_H__
  2. #define __FDC2214_H__
  3. #include <stdint.h>
  4. //#include "bianliang.h"
  5. #define PI 3.1415926
  6. #define ClockFrequency 40000000 //时钟频率
  7. #define SWAP16(data) (uint32_t)((((uint16_t)(data) & (0xFF<<0 ))<<8)|(((uint32_t)(data) & (0xFF<<8))>>8))
  8. #define FDC2214_Addr (0x2A)
  9. #define FDC2214_DATA_CH0 (0x00)
  10. #define FDC2214_DATA_LSB_CH0 (0x01)
  11. #define FDC2214_DATA_CH1 (0x02)
  12. #define FDC2214_DATA_LSB_CH1 (0x03)
  13. #define FDC2214_DATA_CH2 (0x04)
  14. #define FDC2214_DATA_LSB_CH2 (0x05)
  15. #define FDC2214_DATA_CH3 (0x06)
  16. #define FDC2214_DATA_LSB_CH3 (0x07)
  17. #define FDC2214_RCOUNT_CH0 (0x08)
  18. #define FDC2214_RCOUNT_CH1 (0x09)
  19. #define FDC2214_RCOUNT_CH2 (0x0A)
  20. #define FDC2214_RCOUNT_CH3 (0x0B)
  21. #define FDC2214_SETTLECOUNT_CH0 (0x10)
  22. #define FDC2214_SETTLECOUNT_CH1 (0x11)
  23. #define FDC2214_SETTLECOUNT_CH2 (0x12)
  24. #define FDC2214_SETTLECOUNT_CH3 (0x13)
  25. #define FDC2214_CLOCK_DIVIDERS_CH0 (0x14)
  26. #define FDC2214_CLOCK_DIVIDERS_CH1 (0x15)
  27. #define FDC2214_CLOCK_DIVIDERS_CH2 (0x16)
  28. #define FDC2214_CLOCK_DIVIDERS_CH3 (0x17)
  29. #define FDC2214_STATUS (0x18)
  30. #define FDC2214_ERROR_CONFIG (0x19)
  31. #define FDC2214_CONFIG (0x1A)
  32. #define FDC2214_MUX_CONFIG (0x1B)
  33. #define FDC2214_RESET_DEV (0x1C)
  34. #define FDC2214_DRIVE_CURRENT_CH0 (0x1E)
  35. #define FDC2214_DRIVE_CURRENT_CH1 (0x1F)
  36. #define FDC2214_DRIVE_CURRENT_CH2 (0x20)
  37. #define FDC2214_DRIVE_CURRENT_CH3 (0x21)
  38. #define FDC2214_MANUFACTURER_ID (0x7E)
  39. #define FDC2214_DEVICE_ID (0x7F)
  40. #define FDC2214_ID (0x3055)
  41. typedef enum
  42. {
  43. FDC2214_Channel_0 = 0x00,
  44. FDC2214_Channel_1 = 0x01,
  45. FDC2214_Channel_2 = 0x02,
  46. FDC2214_Channel_3 = 0x03
  47. } FDC2214_channel_t;
  48. typedef enum
  49. {
  50. FDC2214_Channel_Sequence_0_1 = 0x00,
  51. FDC2214_Channel_Sequence_0_1_2 = 0x01,
  52. FDC2214_Channel_Sequence_0_1_2_3 = 0x02,
  53. } FDC2214_channel_sequence_t;
  54. typedef enum
  55. {
  56. FDC2214_Bandwidth_1M = 0x01, //1MHz
  57. FDC2214_Bandwidth_3_3M = 0x04, //3.3MHz
  58. FDC2214_Bandwidth_10M = 0x05, //10MHz
  59. FDC2214_Bandwidth_33M = 0x07 //33MHz
  60. } FDC2214_filter_bandwidth_t;
  61. typedef enum
  62. {
  63. FDC2214_Drive_Current_0_016 = 0x00, //0.016mA
  64. FDC2214_Drive_Current_0_018 = 0x01, //0.018mA
  65. FDC2214_Drive_Current_0_021 = 0x02, //0.021mA
  66. FDC2214_Drive_Current_0_025 = 0x03, //0.025mA
  67. FDC2214_Drive_Current_0_028 = 0x04, //0.028mA
  68. FDC2214_Drive_Current_0_033 = 0x05, //0.033mA
  69. FDC2214_Drive_Current_0_038 = 0x06, //0.038mA
  70. FDC2214_Drive_Current_0_044 = 0x07, //0.044mA
  71. FDC2214_Drive_Current_0_052 = 0x08, //0.052mA
  72. FDC2214_Drive_Current_0_060 = 0x09, //0.060mA
  73. FDC2214_Drive_Current_0_069 = 0x0A, //0.069mA
  74. FDC2214_Drive_Current_0_081 = 0x0B, //0.081mA
  75. FDC2214_Drive_Current_0_093 = 0x0C, //0.093mA
  76. FDC2214_Drive_Current_0_108 = 0x0D, //0.108mA
  77. FDC2214_Drive_Current_0_126 = 0x0E, //0.126mA
  78. FDC2214_Drive_Current_0_146 = 0x0F, //0.146mA
  79. FDC2214_Drive_Current_0_169 = 0x10, //0.169mA
  80. FDC2214_Drive_Current_0_196 = 0x11, //0.196mA
  81. FDC2214_Drive_Current_0_228 = 0x12, //0.228mA
  82. FDC2214_Drive_Current_0_264 = 0x13, //0.264mA
  83. FDC2214_Drive_Current_0_307 = 0x14, //0.307mA
  84. FDC2214_Drive_Current_0_356 = 0x15, //0.356mA
  85. FDC2214_Drive_Current_0_413 = 0x16, //0.413mA
  86. FDC2214_Drive_Current_0_479 = 0x17, //0.479mA
  87. FDC2214_Drive_Current_0_555 = 0x18, //0.555mA
  88. FDC2214_Drive_Current_0_644 = 0x19, //0.644mA
  89. FDC2214_Drive_Current_0_747 = 0x1A, //0.747mA
  90. FDC2214_Drive_Current_0_867 = 0x1B, //0.867mA
  91. FDC2214_Drive_Current_1_006 = 0x1C, //1.006mA
  92. FDC2214_Drive_Current_1_167 = 0x1D, //1.167mA
  93. FDC2214_Drive_Current_1_354 = 0x1E, //1.354mA
  94. FDC2214_Drive_Current_1_571 = 0x1F //1.571mA
  95. } FDC2214_drive_current_t;
  96. extern uint32_t ch0,ch1,ch2,ch3;
  97. uint8_t FDC2214_Init(void);
  98. void FDC2214_Write16(uint8_t Slve_Addr, uint8_t reg, uint16_t data);
  99. uint16_t FDC2214_Read16(uint8_t Slve_Addr, uint8_t reg);
  100. uint8_t FDC2214_GetChannelData(FDC2214_channel_t channel, uint32_t *data);
  101. void FDC2214_SetRcount(FDC2214_channel_t channel, uint16_t rcount);
  102. void FDC2214_SetSettleCount(FDC2214_channel_t channel, uint16_t count);
  103. void FDC2214_SetChannelClock(FDC2214_channel_t channel, uint8_t frequency_select, uint16_t divider);
  104. void FDC2214_SetINTB(uint8_t mode);
  105. void FDC2214_SetActiveChannel(FDC2214_channel_t channel);
  106. void FDC2214_SetSleepMode(uint8_t mode);
  107. void FDC2214_SetCurrentMode(uint8_t mode);
  108. void FDC2214_SetClockSource(uint8_t src);
  109. void FDC2214_SetHighCurrentMode(uint8_t mode);
  110. void FDC2214_SetMUX_CONFIG(uint8_t autoscan, FDC2214_channel_sequence_t channels, FDC2214_filter_bandwidth_t bandwidth);
  111. void FDC2214_Reset(void);
  112. void FDC2214_SetDriveCurrent(FDC2214_channel_t channel, FDC2214_drive_current_t current);
  113. double FDC2214_CalculateFrequency(FDC2214_channel_t channel, uint32_t datax);
  114. double FDC2214_CalculateCapacitance(double frequency, float inductance, float capacitance);
  115. double getcap(uint8_t channel,double dg,double dr);
  116. #endif