instance_calib.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*! ----------------------------------------------------------------------------
  2. * @file instance_calib.c
  3. * @brief DecaWave application level configuration and calibration functions
  4. *
  5. * @attention
  6. *
  7. * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
  8. *
  9. * All rights reserved.
  10. *
  11. * @author DecaWave
  12. */
  13. #include "compiler.h"
  14. #include "deca_device_api.h"
  15. #include "instance.h"
  16. #include "port.h"
  17. // -------------------------------------------------------------------------------------------------------------------
  18. //The table below specifies the default TX spectrum configuration parameters... this has been tuned for DW EVK hardware units
  19. //the table is set for smart power - see below in the instance_config function how this is used when not using smart power
  20. const tx_struct txSpectrumConfig[8] =
  21. {
  22. //Channel 0 ----- this is just a place holder so the next array element is channel 1
  23. {
  24. 0x0, //0
  25. {
  26. 0x0, //0
  27. 0x0 //0
  28. }
  29. },
  30. //Channel 1
  31. {
  32. 0xc9, //PG_DELAY
  33. {
  34. 0x15355575, //16M prf power
  35. 0x07274767 //64M prf power
  36. }
  37. },
  38. //Channel 2
  39. {
  40. 0xc2, //PG_DELAY
  41. {
  42. 0x15355575, //16M prf power
  43. 0x07274767 //64M prf power
  44. }
  45. },
  46. //Channel 3
  47. {
  48. 0xc5, //PG_DELAY
  49. {
  50. 0x0f2f4f6f, //16M prf power
  51. 0x2b4b6b8b //64M prf power
  52. }
  53. },
  54. //Channel 4
  55. {
  56. 0x95, //PG_DELAY
  57. {
  58. 0x1f1f3f5f, //16M prf power
  59. 0x3a5a7a9a //64M prf power
  60. }
  61. },
  62. //Channel 5
  63. {
  64. 0xc0, //PG_DELAY
  65. {
  66. 0x0E082848, //16M prf power
  67. 0x25456585 //64M prf power
  68. }
  69. },
  70. //Channel 6 ----- this is just a place holder so the next array element is channel 7
  71. {
  72. 0x0, //0
  73. {
  74. 0x0, //0
  75. 0x0 //0
  76. }
  77. },
  78. //Channel 7
  79. {
  80. 0x93, //PG_DELAY
  81. {
  82. 0x32527292, //16M prf power
  83. 0x5171B1d1 //64M prf power
  84. }
  85. }
  86. };
  87. const tx_struct txManualSpectrumConfig[8] =
  88. {
  89. //Channel 0 ----- this is just a place holder so the next array element is channel 1
  90. {
  91. 0x0, //0
  92. {
  93. 0,
  94. 0
  95. }
  96. },
  97. //Channel 1
  98. {
  99. 0xc9, //PG_DELAY
  100. {
  101. 0x75757575,
  102. 0x67676767
  103. }
  104. },
  105. //Channel 2
  106. {
  107. 0xc2, //PG_DELAY
  108. {
  109. 0x75757575,
  110. 0x67676767
  111. }
  112. },
  113. //Channel 3
  114. {
  115. 0xc5, //PG_DELAY
  116. {
  117. 0x6F6F6F6F,
  118. 0x8B8B8B8B
  119. }
  120. },
  121. //Channel 4
  122. {
  123. 0x95, //PG_DELAY
  124. {
  125. 0x5F5F5F5F,
  126. 0x9A9A9A9A
  127. }
  128. },
  129. //Channel 5
  130. {
  131. 0xc0, //PG_DELAY
  132. {
  133. 0x48484848,
  134. 0x85858585
  135. }
  136. },
  137. //Channel 6 ----- this is just a place holder so the next array element is channel 7
  138. {
  139. 0x0, //0
  140. {
  141. 0x0, //0
  142. 0x0 //0
  143. }
  144. },
  145. //Channel 7
  146. {
  147. 0x93, //PG_DELAY
  148. {
  149. 0x92929292,
  150. 0xD1D1D1D1
  151. }
  152. }
  153. };
  154. const tx_struct maxSpectrumConfig[8] =
  155. {
  156. //Channel 0 ----- this is just a place holder so the next array element is channel 1
  157. {
  158. 0x0, //0
  159. {
  160. 0,
  161. 0
  162. }
  163. },
  164. //Channel 1
  165. {
  166. 0xc9, //PG_DELAY
  167. {
  168. 0x751f1f75,
  169. 0x671f1f67
  170. }
  171. },
  172. //Channel 2
  173. {
  174. 0xc2, //PG_DELAY
  175. {
  176. 0x751f1f75, //16M prf power
  177. 0x671f1f67 //64M prf power
  178. }
  179. },
  180. //Channel 3
  181. {
  182. 0xc5, //PG_DELAY
  183. {
  184. 0x6F1F1F6F,
  185. 0x8B1f1f8B
  186. }
  187. },
  188. //Channel 4
  189. {
  190. 0x95, //PG_DELAY
  191. {
  192. 0x5F1F1F5F,
  193. 0x9A1f1f9A
  194. }
  195. },
  196. //Channel 5
  197. {
  198. 0xc0, //PG_DELAY
  199. {
  200. 0x481f1f48,
  201. 0x851f1f85
  202. }
  203. },
  204. //Channel 6 ----- this is just a place holder so the next array element is channel 7
  205. {
  206. 0x0, //0
  207. {
  208. 0x0, //0
  209. 0x0 //0
  210. }
  211. },
  212. //Channel 7
  213. {
  214. 0x93, //PG_DELAY
  215. {
  216. 0x921f1f92,
  217. 0xD11f1fD1
  218. }
  219. }
  220. };
  221. //these are default antenna delays for EVB1000, these can be used if there is no calibration data in the DW1000,
  222. //or instead of the calibration data
  223. const uint16_t rfDelays[2] = {
  224. (uint16_t) ((DWT_PRF_16M_RFDLY/ 2.0) * 1e-9 / DWT_TIME_UNITS),//PRF 16
  225. (uint16_t) ((DWT_PRF_64M_RFDLY/ 2.0) * 1e-9 / DWT_TIME_UNITS)
  226. };
  227. //these are default TREK Tag/Anchor antenna delays
  228. const uint16_t rfDelaysTREK[2] = {
  229. (uint16_t) ((514.83f/ 2.0) * 1e-9 / DWT_TIME_UNITS),//channel 2
  230. (uint16_t) ((514.65f/ 2.0) * 1e-9 / DWT_TIME_UNITS) //channel 5
  231. };
  232. int instStartTXtest(int framePeriod)
  233. {
  234. //define some test data for the tx buffer
  235. uint8_t msg[127] = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the l";
  236. //NOTE: SPI frequency must be < 3MHz
  237. SPI_ConfigFastRate(SPI_BAUDRATEPRESCALER_32); //max SPI before PLLs configured is ~4M
  238. // the value here 0x1000 gives a period of 32.82
  239. //this is setting 0x1000 as frame period (125MHz clock cycles) (time from Tx en - to next - Tx en)
  240. dwt_configcontinuousframemode(framePeriod);
  241. dwt_writetxdata(127, (uint8_t *) msg, 0) ;//Clear tx buffer
  242. dwt_writetxfctrl(127, 0);
  243. //to start the first frame - set TXSTRT
  244. dwt_starttx(DWT_START_TX_IMMEDIATE);
  245. //measure the power
  246. //Spectrum Analyser set:
  247. //FREQ to be channel default e.g. 3.9936 GHz for channel 2
  248. //SPAN to 1GHz
  249. //SWEEP TIME 1s
  250. //RBW and VBW 1MHz
  251. //measure channel power
  252. return DWT_SUCCESS ;
  253. }
  254. // -------------------------------------------------------------------------------------------------------------------
  255. //extern instance_data_t instance_data[NUM_INST] ;
  256. /* ==========================================================
  257. Notes:
  258. Previously code handled multiple instances in a single console application
  259. Now have changed it to do a single instance only. With minimal code changes...(i.e. kept [instance] index but it is always 0.
  260. Windows application should call instance_init() once and then in the "main loop" call instance_run().
  261. */