Forráskód Böngészése

Протестирован режим 4Mosi для LMX2594

zaytsev.mikhail.olegovich@gmail.com 1 éve
szülő
commit
7a126bccb5
4 módosított fájl, 31 hozzáadás és 14 törlés
  1. 26 12
      Devices/lmx2594.c
  2. 1 0
      Devices/lmx2594.h
  3. 3 1
      Devices/tmsgheaders.h
  4. 1 1
      main.c

+ 26 - 12
Devices/lmx2594.c

@@ -124,6 +124,17 @@ uint32_t lmx2594regs[LMX_COUNT] = {
 
 double lmx_freq; // Frequency of the LMX2594
 
+void auto_cal(void *bar1) {
+    lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_R0_FCAL);
+    lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | LMX2594_R0_FCAL_EN;
+    uint32_t *ptr_header = bar1+LMX_BASE_ADDR;
+    *ptr_header = ((0 << 23) | (DeviceIdLmx2594 << 18) | (0x1 << 1) | 1);
+
+    uint32_t *ptr = bar1 + LMX_BASE_ADDR;
+        *ptr = lmx2594regs[112-FCAL_ADDR];
+
+}
+
 void lmx2594_init(void *bar1) {
     // Header for LMX Reset
     uint32_t *ptr_rst = bar1 + LMX_BASE_ADDR;
@@ -141,6 +152,8 @@ void lmx2594_init(void *bar1) {
         uint32_t *ptr = bar1 + LMX_BASE_ADDR;
         *ptr = lmx2594regs[i];
     }
+    usleep(10);
+    auto_cal(bar1);
     FILE * f = fopen("init.txt", "w");
     for (int i = 0; i < sizeof(lmx2594regs) / 4; i++) {
         fprintf(f, "0x%08X\n", lmx2594regs[i]);
@@ -542,7 +555,6 @@ int lmx_freq_set_main_band_int_mode(void *bar1, double freq, double f_pd) {
     lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | (LMX2594_R0_FCAL_EN);
 
     uint32_t lmx_change_freq_regs[] = {
-            lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_TRISTATE,
             lmx2594regs[112 - VCO_SEL],
             lmx2594regs[112 - CAP_CTRL_START],
             lmx2594regs[112 - VCO_DACISET],
@@ -553,13 +565,12 @@ int lmx_freq_set_main_band_int_mode(void *bar1, double freq, double f_pd) {
             lmx2594regs[112-PLL_N_S],
             lmx2594regs[112-PLL_N_M],
             lmx2594regs[112 - OUTA_MUX],
-            lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_15ma,
             lmx2594regs[112-FCAL_ADDR]
     };
     // Create a header for the LMX2594 with the appropriate number of words
     // uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs)/4) << 1) | 1);
      // Create a header for the LMX2594 with the appropriate number of words MOSI 4
-    uint32_t LMX_HEADER = ((ENUM_SPIMODE_4MOSI << 23) | ((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | 1);
+    uint32_t LMX_HEADER = ((0x1<< 23) | ((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | 1);
     uint32_t *ptr = bar1 + LMX_BASE_ADDR;
     *ptr = LMX_HEADER;
     for (int i = 0; i < sizeof(lmx_change_freq_regs)/4; i++) {
@@ -1200,12 +1211,12 @@ int lmx_freq_set_out_of_band_int_mode(void *bar1, double freq, double f_pd) {
     lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] | (vco_daciset_strt << BITP_LMX2594_R17_VCO_DACISET);
 
     // Set the PFD_DLY_SEL to appropriate value
-    if (freq <= 12500e6) {
+    if (f_vco <= 12500e6) {
         lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
         lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x1 << BITP_LMX2594_R37_PFD_DLY_SEL);
         printf("PFD_DLY_SEL = %d\n", 1);
     }
-    else if (freq > 12500e6) {
+    else if (f_vco > 12500e6) {
         lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
         lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x2 << BITP_LMX2594_R37_PFD_DLY_SEL);
         printf("PFD_DLY_SEL = %d\n", 2);
@@ -1277,7 +1288,6 @@ int lmx_freq_set_out_of_band_int_mode(void *bar1, double freq, double f_pd) {
     lmx2594regs[112 - FCAL_ADDR] = lmx2594regs[112 - FCAL_ADDR] | (LMX2594_R0_FCAL_EN);
 
     uint32_t lmx_change_freq_regs []={
-        lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_TRISTATE,
         lmx2594regs[112 - VCO_SEL],
         lmx2594regs[112 - CAP_CTRL_START],
         lmx2594regs[112 - VCO_DACISET],
@@ -1289,14 +1299,13 @@ int lmx_freq_set_out_of_band_int_mode(void *bar1, double freq, double f_pd) {
         lmx2594regs[112 - CHDIV],
         lmx2594regs[112 - CHDIV_DIV2],
         lmx2594regs[112 - OUTA_MUX],
-        lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_15ma,
         lmx2594regs[112 - FCAL_ADDR]
     };
 
     // Create a header for the LMX2594 with the appropriate number of words
     // uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs) / 4) << 1) | 1);
     // Create a header for the LMX2594 with the appropriate number of words MOSI 4
-    uint32_t LMX_HEADER = ((ENUM_SPIMODE_4MOSI << 23) | ((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | 1);
+    uint32_t LMX_HEADER = ((0x1<< 23) | ((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | 1);
     uint32_t *ptr = bar1 + LMX_BASE_ADDR;
     *ptr = LMX_HEADER;
     // Send the data
@@ -1333,8 +1342,13 @@ int lmx_freq_set(void *bar1, double freq,double f_pd) {
 
     // double f_pd = 175e6;
     // Set the 4 Mosi mode
+    usleep(1);
     uint32_t *spi_mode = bar1 +RST_ADDR;
     *spi_mode = SPI_MODE_4MOSI;
+    usleep(1);
+    *spi_mode = SPI_MODE_4MOSI | TMSG_RST_ON;
+    usleep(1);
+    *spi_mode = SPI_MODE_4MOSI | TMSG_RST_OFF;
     double N_div = 0;
     if (freq < 10e6 || freq > 15e9) {
         printf("Frequency range is 10 MHz to 15 GHz\n");
@@ -1349,12 +1363,12 @@ int lmx_freq_set(void *bar1, double freq,double f_pd) {
         // lmx_freq_set_out_of_band(bar1, freq, f_pd);
         lmx_freq_set_out_of_band_int_mode(bar1, freq, f_pd);
     }
-    // Switch the keys 
-    key_switch(bar1, freq,lmx_freq);
-    usleep(1);
     // Return the 1 MOSI mode
+    usleep(1);
     *spi_mode = SPI_MODE_1MOSI;
-    
+    // Switch the keys 
+     usleep(1);
+    key_switch(bar1, freq,lmx_freq);
     return 0;
 }
 

+ 1 - 0
Devices/lmx2594.h

@@ -8,6 +8,7 @@
 #define     LMX_LD_STATUS_ADDR  0x18
 
 void lmx2594_init(void *bar1);
+void auto_cal(void *bar1);
 
 int lmx_freq_set_main_band(void *bar1, double freq, double f_pd);
 int lmx_freq_set_main_band_int_mode(void *bar1, double freq, double f_pd);

+ 3 - 1
Devices/tmsgheaders.h

@@ -137,7 +137,7 @@
 #define DDS_X2_FPGA                         0x0
 #define DDS_SAW2_FPGA                       0x0
 #define REF_OFFSET_CTRL_FPGA                0x1
-#define GPIO_ADRF_V1                        0x2
+#define GPIO_ADRF_V1                        0x1
 #define GPIO_ADRF_V2                        0x0
 #define DDS_SAW1_FPGA                       0x0
 #define FPGA_AM_CTRL                        0x0
@@ -209,6 +209,8 @@
 #define    MOD_1                        (0x1 << MOD_CMD_REG_BITP)
 #define    SPI_MODE_1MOSI               (0x0 << TMSG_CMD_REG_SPI_MODE_BITP)
 #define    SPI_MODE_4MOSI               (0x1 << TMSG_CMD_REG_SPI_MODE_BITP)
+#define    TMSG_RST_ON                  (0x1 << TMSG_RST_CMD_REG_BITP)
+#define    TMSG_RST_OFF                 (0x0 << TMSG_RST_CMD_REG_BITP)
 
 
 #define     LMX_BASE_ADDR       0x04

+ 1 - 1
main.c

@@ -111,9 +111,9 @@ int main(int argc, char *argv[])
 	pe43711_att_2_init(bar1);
     rst_for_fpga(bar1);
     shift_reg(bar1);
-	max2870_init(bar1);
     ad9912_init(bar1);
     lmx2594_init(bar1);
+	max2870_init(bar1);
 
 	// Установка обработчика сигналов
 	signal(SIGINT, handleCloseSignal);