فهرست منبع

Добавлена таблица, по которой рассчитываются значения для потенциометра.

Anatoliy Chigirinskiy 1 سال پیش
والد
کامیت
1339963a50
7فایلهای تغییر یافته به همراه105 افزوده شده و 17 حذف شده
  1. 2 1
      Devices/lmx2594.c
  2. 31 8
      Devices/potentiometer.c
  3. 5 0
      Devices/potentiometer.h
  4. 50 0
      Potentiometer.txt
  5. 14 5
      command.c
  6. 1 0
      command.h
  7. 2 3
      main.c

+ 2 - 1
Devices/lmx2594.c

@@ -381,6 +381,7 @@ struct vco_params calculate_vco_params (double lmx_freq, double f_pd) {
 			params.N = 32;
 		}
 	}
+    printf("N in lmx: %u\n", params.N);
 	return params;
 }
 
@@ -531,7 +532,7 @@ double lmx_get_freq(double freq) {
 	else if (freq > 15e9 && freq <=30e9) {
 		return freq / 2;
 	}
-	else if (freq > 27e9 && freq <= 45e9) {
+	else if (freq > 30e9 && freq <= 45e9) {
 		return freq / 4;
 	}
 	return 0;

+ 31 - 8
Devices/potentiometer.c

@@ -1,7 +1,16 @@
 #include "potentiometer.h"
 #include "tmsgheaders.h"
 
-uint32_t pot_array [2] = {0,0};
+uint32_t pot_array [2]  = {0,0};
+double freq_file [50] = {0};
+uint32_t pot_offset [50]= {0};
+uint32_t pot_slope [50]= {0};
+
+uint32_t pot_ch_a_file;
+uint32_t pot_ch_b_file;
+
+
+/* arrays of potentiometer values from file  */
 
 void potentiometer_set(reg_addr_pci* pci_bar_1, uint8_t pot_val_ch_a, uint8_t pot_val_ch_b) {
     usleep(1);
@@ -26,14 +35,28 @@ void potentiometer_set(reg_addr_pci* pci_bar_1, uint8_t pot_val_ch_a, uint8_t po
     set_cfg_reg(cfg_reg);
     usleep(1);
 }
+/* Read the potentiometer values from the file */
+void read_pot_file (const char* filename) {
+    FILE *file = fopen(filename, "r");
+    if (file == NULL) {
+        printf("Error: File not found\n");
+        return;
+    }
+    int i = 0;
+    while (fscanf(file, "%lf %u %u", &freq_file[i], &pot_offset[i], &pot_slope[i]) != EOF) {
+        i++;
+    }
+    fclose(file);
+}
 
-void potentiometer_set_qspi(uint8_t pot_offset, uint8_t pot_slope) {
-
-    uint32_t pot_ch_a	=	(TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_offset << TPL0202_DATA_BITP);
-    uint32_t pot_ch_b	=	(TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_slope << TPL0202_DATA_BITP);
-
-    pot_array[0] = pot_ch_a;
-    pot_array[1] = pot_ch_b;
+void set_pot_values(double freq){
+    for (int i = 0; i < 50; i++) {
+        if (freq <= freq_file[i]) {
+            pot_ch_a_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_offset[i-1] << TPL0202_DATA_BITP);
+            pot_ch_b_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_slope[i-1]<< TPL0202_DATA_BITP);
+            break;
+        }
+    }
 }
 
 void potentiometer_set_offset (reg_addr_pci* pci_bar_1, uint8_t pot_offset) {

+ 5 - 0
Devices/potentiometer.h

@@ -22,9 +22,14 @@
 
 extern uint32_t pot_array [2];
 
+extern uint32_t pot_ch_a_file;
+extern uint32_t pot_ch_b_file;
+
 void potentiometer_set(reg_addr_pci* pci_bar_1, uint8_t pot_val_ch_a, uint8_t pot_val_ch_b);
 void potentiometer_set_qspi(uint8_t pot_offset, uint8_t pot_slope);
 void potentiometer_set_offset(reg_addr_pci* pci_bar_1, uint8_t pot_offset);
 void potentiometer_set_slope(reg_addr_pci* pci_bar_1, uint8_t pot_slope);
+void read_pot_file (const char* filename);
+void set_pot_values(double freq);
 
 #endif //POTENTIOMETER_H

+ 50 - 0
Potentiometer.txt

@@ -0,0 +1,50 @@
+   10.000000e6 	218	250
+  600.000000e6 	218	250
+  600.000000e6 	215 	250
+ 1300.000000e6 	215 	250
+ 1300.000000e6 	225 	250
+ 2300.000000e6 	225	250
+ 2300.000000e6 	225 	230
+ 3500.000000e6 	225 	230
+ 3500.000000e6 	240 	240
+ 5500.000000e6 	240 	240
+ 5500.000000e6 	235 	240
+ 9000.000000e6 	235 	240
+ 9000.000000e6 	230 	230
+13300.000000e6 	230 	230
+13300.000000e6 	235     230
+14300.000000e6 	235     230
+14300.000000e6 	235 	230
+15000.000000e6 	235 	230
+15000.000000e6 	245 	220
+27000.000000e6 	245 	220
+27000.000000e6 	245 	200
+30000.000000e6 	245 	200
+30000.000000e6 	250 	200
+31000.000000e6 	250 	200
+31000.000000e6 	245 	200
+32000.000000e6 	245 	200
+32000.000000e6 	245 	200
+33000.000000e6 	245 	200
+33000.000000e6 	250 	200
+34000.000000e6 	250 	200
+34000.000000e6 	250 	200
+35000.000000e6 	250 	200
+35000.000000e6 	245 	200
+36000.000000e6 	245 	200
+36000.000000e6 	245 	200
+37000.000000e6 	245 	200
+37000.000000e6 	245 	200
+38000.000000e6 	245 	200
+38000.000000e6 	245 	200
+39000.000000e6 	245 	200
+39000.000000e6 	245 	200
+40000.000000e6 	245 	200
+40000.000000e6 	245 	200
+41000.000000e6 	245 	200
+41000.000000e6 	245 	200
+42000.000000e6 	245 	200
+42000.000000e6 	245 	150
+43000.000000e6 	245 	150
+43000.000000e6 	250 	150
+44000.000000e6 	250 	150

+ 14 - 5
command.c

@@ -2,13 +2,10 @@
 
 #include <stdint.h>
 #include <stdlib.h>
-#include <inttypes.h>
 #include <stdio.h>
 #include <strings.h>
 #include <string.h>
 #include <sys/socket.h>
-#include <sys/time.h>
-#include <unistd.h>
 #include <time.h>
 
 #include "Devices/lmx2594.h"
@@ -32,6 +29,7 @@ command commands[] = {{"TMSG44:FREQ ",   handle_freq_cmd},
                       {"*IDN?",          handle_idn_cmd},
                       {"TMSG44:OFFSET ", handle_offset_cmd},
                       {"TMSG44:SLOPE ",  handle_slope_cmd},
+                      {"TMSG44:FILE ",  handle_file_cmd},
                       {NULL, NULL} // Завершающий элемент для обозначения конца массива
 };
 
@@ -44,6 +42,7 @@ void handle_freq_cmd(const char *recv_buff) {
 
     split_lexeme(recv_buff, freq, sizeof(freq[0]), convert_to_double);
 
+    set_pot_values(freq[0]);
     lmx_freq = lmx_get_freq(freq[0]);
     f_pd = ad9912_set(pci_bar_1, lmx_freq, f_pd);
     printf("f_pd frequency is set to %.6f MHz\n", f_pd / 1e6);
@@ -63,9 +62,9 @@ void send_data_qspi(reg_addr_pci *pci_bar_1) {
 
     // Create a header 4 Mosi mode
     uint32_t qspi_header = ((ENUM_SPIMODE_4MOSI) | (0x1 << BITP_GPIO_4MOSI_HEADER) |
-                            (0x1 << BITP_SHIFT_REG_4MOSI_HEADER) |
+                            (0x1 << BITP_SHIFT_REG_4MOSI_HEADER) |+
                             ((sizeof(ad9912_ftw_regs_qspi) / 4) << BITP_DDS_4MOSI_HEADER) |
-                            ((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | (TERM_BIT_1));
+                            ((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | (2 << BITP_POT_4MOSI_HEADER) | (TERM_BIT_1));
 
     pci_bar_1->sbtmsg_addr = qspi_header;
 
@@ -85,6 +84,16 @@ void send_data_qspi(reg_addr_pci *pci_bar_1) {
 
     // Send the data for the shift register
     pci_bar_1->sbtmsg_addr = shift_reg;
+    // Send the data for the potentiometer
+    pci_bar_1->sbtmsg_addr = pot_ch_a_file;
+    pci_bar_1->sbtmsg_addr = pot_ch_b_file;
+}
+
+void handle_file_cmd(const char *recv_buff) {
+    printf("\nHandle command \"TMSG44:FILE\"\n");
+
+    /* Read the adjusted potentiometer values from the file */
+    read_pot_file("/tmp/TMSG44-CoolPi/Potentiometer.txt");
 }
 
 void handle_ld_cmd(const char *recv_buff) {

+ 1 - 0
command.h

@@ -44,6 +44,7 @@ void handle_att_cmd(const char* recv_buff);
 void handle_idn_cmd(const char* recv_buff);
 void handle_offset_cmd(const char* recv_buff);
 void handle_slope_cmd(const char* recv_buff);
+void handle_file_cmd(const char* recv_buff);
 void process_command(const char* recv_buff);
 void convert_to_uint16(const char *str, void *output);
 void convert_to_uint64(const char *str, void *output);

+ 2 - 3
main.c

@@ -124,10 +124,9 @@ int main(int argc, char *argv[])
 	max2870_init(pci_bar_1);
     ad9912_init(pci_bar_1);
     lmx2594_init(pci_bar_1);
-
+    read_pot_file("/tmp/TMSG44-CoolPi/Potentiometer.txt");
 	usleep(1000);
-	
-	// Установка режима SPI
+		// Установка режима SPI
 	uint32_t cfg_reg = get_cfg_reg();
 	SET_REGISTER_PARAM(cfg_reg, CFG_REG_SPI_MODE_BITM, CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_4MOSI);
 	SET_REGISTER_PARAM(cfg_reg, CFG_REG_SPI_CLK_BITM, CFG_REG_SPI_CLK_BITP, CFG_REG_SPI_CLK_50MHZ);