Просмотр исходного кода

Исправлена обработка входной частоты для функций ad9912. Переключение ключей перенесено в command.c

Anatoliy Chigirinskiy 1 год назад
Родитель
Сommit
373ef0bef2
3 измененных файлов с 24 добавлено и 24 удалено
  1. 13 14
      Devices/ad9912.c
  2. 6 9
      Devices/lmx2594.c
  3. 5 1
      command.c

+ 13 - 14
Devices/ad9912.c

@@ -60,36 +60,35 @@ void ad9912_init(void *bar1) {
 }
 /*----------------------------------------------------------------------*/
 
-double ad9912_set_main_band(double freq,double f_pd) {
+double ad9912_set_main_band(double lmx_freq,double f_pd) {
     // Divide the frequncy by the old value of the phase detector frequency and only left with the integer part
-    uint32_t N = (uint32_t) (freq/f_pd);
-    if (freq <= 12500e6) {
+    uint32_t N = (uint32_t) (lmx_freq/f_pd);
+    if (lmx_freq <= 12500e6) {
         if (N < 28){
             N= 28;
         };
     }
-    else if (freq > 12500e6) {
+    else if (lmx_freq > 12500e6) {
         if (N <32) {
             N = 32;
         }
     };
     printf("N = %d\n", N);
     // Calculate the new phase detector frequency by dividing the frequency by the new value of N
-    f_pd = freq/N; // Phase detector frequency
+    f_pd = lmx_freq/N; // Phase detector frequency
     return f_pd;
 }
 
-double ad9912_set_out_of_band(double freq,double f_pd) {
+double ad9912_set_out_of_band(double lmx_freq,double f_pd) {
     
     printf("f_pd in out_of_band func = %f\n",f_pd);
-    printf("freq in func = %f\n",freq);
-    double lmx_freq;
-    if (freq >100e3 && freq <=1000e6) {
-        lmx_freq = 4000e6-freq;
-    }
-    else {
-        lmx_freq = freq;
-    }
+    printf("freq in func = %f\n",lmx_freq);
+    // if (freq >100e3 && freq <=1000e6) {
+    //     lmx_freq = 4000e6-freq;
+    // }
+    // else {
+    //     lmx_freq = freq;
+    // }
     double f_vco = 2*lmx_freq; // VCO frequency
     double vco_div = 7.5e9/lmx_freq;
     int chan_div = 2;

+ 6 - 9
Devices/lmx2594.c

@@ -727,7 +727,11 @@ double lmx_lower_bond_set (double freq, double f_pd) {
 }
 
 double lmx_get_freq(double freq) {
-    
+
+    if (freq < 100e3 || freq> 45e9) {
+        printf("Frequency range is 100 kHz to 45 GHz\n");
+        return -1;
+    }
     if (freq >= 100e3 && freq <= 1000e6) {
         double f_max2870 = 4e9;
         double lmx_freq = f_max2870-freq; // 4 GHz - freq
@@ -744,7 +748,7 @@ double lmx_get_freq(double freq) {
     }
 }
 
-int lmx_freq_set(void *bar1, double freq,double f_pd) {
+int lmx_freq_set(void *bar1, double lmx_freq,double f_pd) {
     // Set the 4 Mosi mode
     usleep(1);
     uint32_t cfg_reg = get_cfg_reg();
@@ -757,11 +761,6 @@ int lmx_freq_set(void *bar1, double freq,double f_pd) {
     usleep(1);
     SET_REGISTER_PARAM(cfg_reg, CFG_REG_RST_FOR_FPGA_BITM, CFG_REG_RST_FOR_FPGA_BITP, CFG_REG_RST_FOR_FPGA_OFF);
     *spi_mode = cfg_reg;
-    if (freq < 100e3 || freq > 45e9) {
-        printf("Frequency range is 100 kHz to 45 GHz\n");
-        return -1;
-    }
-    double lmx_freq = lmx_get_freq(freq);
     // if the frequency is in the main band - 7.5 GHz to 15 GHz
     if (lmx_freq >= 7.5e9 && lmx_freq <= 15e9) {
         // lmx_freq_set_main_band(bar1, freq, f_pd);
@@ -775,9 +774,7 @@ int lmx_freq_set(void *bar1, double freq,double f_pd) {
     usleep(1);
     SET_REGISTER_PARAM(cfg_reg,CFG_REG_SPI_MODE_BITM,CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_1MOSI);
     *spi_mode = cfg_reg;
-    // Switch the keys 
     usleep(1);
-    key_switch(bar1, freq,lmx_freq);
     set_cfg_reg(cfg_reg);
     return 0;
 }

+ 5 - 1
command.c

@@ -32,13 +32,17 @@ void handleFreqCmd(const char* recvBuff)
 {
 	printf("\nHandle command \"TMSG44:FREQ\"\n");
 	double freq[1] = {0};
+	double lmx_freq = 0;
 
 	splitLexeme(recvBuff, freq, sizeof(freq[0]), convertToDouble);
 
 	printf("Frequency: %.2f Hz\n", freq[0]);
-	f_pd = ad9912_set(bar1, freq[0], f_pd);
+	lmx_freq = lmx_get_freq(freq[0]);
+	f_pd = ad9912_set(bar1, lmx_freq, f_pd);
 	printf("f_pd frequency is set to %.6f MHz\n", f_pd/1e6);
     lmx_freq_set(bar1, freq[0], f_pd);
+	// Switch the keys 
+	key_switch(bar1, freq[0],lmx_freq);
     printf("The frequency is set to %.2f MHz\n", freq[0]/1e6);
 }