소스 검색

Тесты аналоговых входов.

TelenkovDmitry 7 달 전
부모
커밋
86e720f06d

+ 22 - 1
fw/modules/adc/adc_transport.c

@@ -204,6 +204,27 @@ unsigned char SPI_Read(unsigned char* data, unsigned char bytesNumber)
     return bytesNumber;  
 }
 
+// Базовая инициализацияч ADC MS5192
+bool adc_init(void)
+{
+    uint8_t ret;
+    
+    adc_gpio_init();
+
+    for (uint32_t i = 0; i < 20; i++) {
+        MS5192T_Reset();
+        ret = MS5192T_Init();
+        printf("ADC init status: %s\r\n", ret == 1 ? "OK" : "FAILED");
+        if (ret == 1)
+            break;
+        vTaskDelay(10);
+        
+    }
+    
+    
+}
+
+#if 0
 //
 void adc_task(void *params)
 {
@@ -324,7 +345,7 @@ void adc_task(void *params)
         vTaskDelay(1000);
     }
 }
-
+#endif
 
 
 

+ 1 - 1
fw/modules/adc/adc_transport.h

@@ -24,7 +24,7 @@ unsigned char SPI_Write(unsigned char* data, unsigned char bytesNumber);
 unsigned char SPI_Read(unsigned char* data, unsigned char bytesNumber);
 
 //
-void adc_task(void *params);
+//void adc_task(void *params);
 
 #endif  // __ADC_TRANSPORT_H
 

+ 226 - 2
fw/modules/io/analog_input.c

@@ -4,8 +4,15 @@
 #include "utility.h"
 #include "FreeRTOS.h"
 #include "task.h"
+#include "settings_api.h"
+#include "adc_transport.h"
+#include "ms5192t.h"
+#include "monitoring.h"
 #include <stdio.h>
 
+#undef DBG
+#define DBG if(1)
+
 
 uint8_t input_mux; // выход сдвигового регистра U1010 (управляет MUX 301, 401)
                    // мультиплексоры отвечат за коммутацию аналоговых входов и АЦП
@@ -15,9 +22,226 @@ uint16_t input_mode; // режим измерения аналоговых ка
                      // младшие 6 (с 1..6) бит - каналы с 1 по 6 соответственно
                      // биты 9..14 - каналы с 7 по 12 соответственно
 
+ANALOG_IN_t channel_name[NUMBER_ADC_CH] = {AN_INP_1, AN_INP_2, AN_INP_3, 
+                                           AN_INP_4, AN_INP_5, AN_INP_6,
+                                           V_ISO_CL, V_ISO, 
+                                           AN_INP_7, AN_INP_8, AN_INP_9,
+                                           AN_INP_10, AN_INP_11, AN_INP_12,
+                                           CRNT_LIM_U_BFR_R, CRNT_LIM_U_ABFR_R};
+
+uint16_t adc_raw_data[NUMBER_ADC_CH];
+
 //en_crnt_alrm_in
 
 
+
+
+// Установить режим измерения канало с 1 по 12.
+void ai_set_meas_mode(void)
+{
+    uint8_t bit = 0;
+    
+    for (uint8_t i = 1; i < 13; i++)
+    {
+        bit = settings.ai_mode_bits & (1 << (i - 1));
+        ai_set_mode((MEAS_CHAN_MODE_t)bit, i);  
+    }
+}   
+
+// Настройка внешнего ADC
+bool ai_adc_init(void)
+{
+    uint8_t ret;
+    unsigned long value;
+    
+    adc_gpio_init();
+    
+    for (uint32_t i = 0; i < 100; i++) {
+        MS5192T_Reset();
+        ret = MS5192T_Init();
+        DBG printf("ADC init status: %s\r\n", ret == 1 ? "OK" : "FAILED");
+        if (ret == 1)
+           break;
+        vTaskDelay(10);
+    }
+        
+    if (!ret) {
+        mon_set_err(ERR_WORD_1, ADC_ERR, true);
+        return false;
+    }
+    
+    // Запрос регистра конфигурации для (0x710 - значение по умолчанию)
+    value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
+    DBG printf("ADC cfg reg: 0x%X: ", value);
+    DBG print_binary_half_word((uint16_t)value);
+    
+    // Коэф-т усиления: 1
+    DBG printf("ADC. Set gain rate 1\r\n");
+    MS5192T_SetGain(MS5192T_GAIN_1);
+    value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
+    DBG printf("ADC cfg reg: 0x%X: ", value);
+    DBG print_binary_half_word((uint16_t)value);
+    
+    // Униполярный режим
+    DBG printf("Set unipolar input mode...\r\n");
+    MS5192T_SetPolar(MS5192T_CONF_UNIPOLAR);
+    value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
+    DBG printf("ADC cfg reg: 0x%X: ", value);
+    DBG print_binary_half_word((uint16_t)value);
+    
+    // Регистр статуса
+    value = MS5192T_GetRegisterValue(MS5192T_REG_STAT, 1, 1);
+    DBG printf("ADC status reg: 0x%X: ", value);
+    DBG print_binary_byte((uint8_t)value);
+    
+    // Установка внутреннего опорного напряжения
+    MS5192T_SetIntReference(MS5192T_REFSEL_INT); // select internal 1.17V reference
+    value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
+    DBG printf("ADC cfg reg: 0x%X: ", value);
+    DBG print_binary_half_word((uint16_t)value);
+    
+    // Регистр режима (MODE register)
+    value = MS5192T_GetRegisterValue(MS5192T_REG_MODE, 2, 1);
+    DBG printf("ADC mode reg: 0x%X: ", value);
+    DBG print_binary_half_word((uint16_t)value);
+    
+    // Установить update rate
+    DBG printf("Set update rate.\r\n");
+    MS5192T_SetUpdateRate(MS5192T_UP_RATE_500);
+    value = MS5192T_GetRegisterValue(MS5192T_REG_MODE, 2, 1);
+    DBG printf("ADC mode reg: 0x%X: ", value);
+    DBG print_binary_half_word((uint16_t)value);
+    
+    // Калибровка 
+    
+    // 1 - ый канал
+    MS5192T_Calibrate(MS5192T_MODE_CAL_INT_ZERO, MS5192T_CH_AIN1P_AIN1M); 
+    MS5192T_Calibrate(MS5192T_MODE_CAL_INT_FULL, MS5192T_CH_AIN1P_AIN1M); 
+    
+    // 2 - ой канал
+    MS5192T_Calibrate(MS5192T_MODE_CAL_INT_ZERO, MS5192T_CH_AIN2P_AIN2M); 
+    MS5192T_Calibrate(MS5192T_MODE_CAL_INT_FULL, MS5192T_CH_AIN2P_AIN2M); 
+    
+    //MS5192T_SetChannel(MS5192T_CH_AIN1P_AIN1M);
+          
+    return true;
+}  
+
+// Оцифровка всех каналов (входы + дополнительные каналы)
+void ai_processing(void)
+{
+    //unsigned long value;
+        
+#if 0 
+    ai_connect_channel(AN_INP_4);
+    vTaskDelay(10);
+    MS5192T_SetChannel(MS5192T_CH_AIN1P_AIN1M);
+    vTaskDelay(10);
+    value = MS5192T_SingleConversion();
+    printf("ADC channel [AN_INP_1] data raw: 0x%X, %f\r\n", value, (double)value*0.00001785305/0.0961538);
+    
+    ai_connect_channel(AN_INP_10);
+    vTaskDelay(10);
+    MS5192T_SetChannel(MS5192T_CH_AIN2P_AIN2M);
+    vTaskDelay(10);
+    value = MS5192T_SingleConversion();
+    printf("ADC channel [AN_INP_7] data raw: 0x%X, %f\r\n", value, (double)value*0.00001785305/0.0961538);
+#endif
+    
+    
+#if 0    
+    ai_connect_channel(AN_INP_2);
+    vTaskDelay(10);
+    MS5192T_SetChannel(MS5192T_CH_AIN1P_AIN1M);
+    vTaskDelay(10);
+    value = MS5192T_SingleConversion();
+    printf("ADC channel [AN_INP_1] data raw: 0x%X, %f\r\n", value, (double)value*0.00001785305/0.0961538);
+    
+    ai_connect_channel(AN_INP_8);
+    vTaskDelay(10);
+    MS5192T_SetChannel(MS5192T_CH_AIN2P_AIN2M);
+    vTaskDelay(10);
+    value = MS5192T_SingleConversion();
+    printf("ADC channel [AN_INP_7] data raw: 0x%X, %f\r\n", value, (double)value*0.00001785305/0.0961538);
+    
+    
+    ai_connect_channel(V_ISO_CL);
+    vTaskDelay(10);
+    MS5192T_SetChannel(MS5192T_CH_AIN1P_AIN1M);
+    vTaskDelay(10);
+    value = MS5192T_SingleConversion();
+    printf("ADC channel [V_ISO_CL] data raw: 0x%X, %f\r\n", value, (double)value*0.00001785305/0.0961538);
+    
+    ai_connect_channel(AN_INP_9);
+    vTaskDelay(10);
+    MS5192T_SetChannel(MS5192T_CH_AIN2P_AIN2M);
+    vTaskDelay(10);
+    value = MS5192T_SingleConversion();
+    printf("ADC channel [AN_INP_9] data raw: 0x%X, %f\r\n", value, (double)value*0.00001785305/0.0961538);
+#endif
+    
+#if 1    
+    for (uint8_t i = 0; i < 8; i++)
+    {
+        adc_get_two_channles(channel_name[i], channel_name[i + 8]);
+        //printf("one: %u, two: %u\r\n", i, i + 8);
+    }
+#if 0    
+    printf("end\r\n");
+    adc_print_data();
+    printf("end\r\n");  
+#endif
+#endif        
+        
+}
+
+//
+void adc_get_two_channles(ANALOG_IN_t one, ANALOG_IN_t two)
+{
+    ai_connect_channel(one);
+    vTaskDelay(10);
+    MS5192T_SetChannel(MS5192T_CH_AIN1P_AIN1M);
+    vTaskDelay(10);
+    adc_raw_data[one] = MS5192T_SingleConversion();
+        
+    ai_connect_channel(two);
+    vTaskDelay(10);
+    MS5192T_SetChannel(MS5192T_CH_AIN2P_AIN2M);
+    vTaskDelay(10);
+    adc_raw_data[two] = MS5192T_SingleConversion();
+}
+
+//
+void adc_print_data(void)
+{
+    printf("AN_INP_1: 0x%X, %f\r\n", adc_raw_data[AN_INP_1], (double) adc_raw_data[AN_INP_1]*0.00001785305/0.0961538);
+    printf("AN_INP_2: 0x%X, %f\r\n", adc_raw_data[AN_INP_2], (double) adc_raw_data[AN_INP_2]*0.00001785305/0.0961538);
+    printf("AN_INP_3: 0x%X, %f\r\n", adc_raw_data[AN_INP_3], (double) adc_raw_data[AN_INP_3]*0.00001785305/0.0961538);
+    printf("AN_INP_4: 0x%X, %f\r\n", adc_raw_data[AN_INP_4], (double) adc_raw_data[AN_INP_4]*0.00001785305/0.0961538);
+    printf("AN_INP_5: 0x%X, %f\r\n", adc_raw_data[AN_INP_5], (double) adc_raw_data[AN_INP_5]*0.00001785305/0.0961538);
+    printf("AN_INP_6: 0x%X, %f\r\n", adc_raw_data[AN_INP_6], (double) adc_raw_data[AN_INP_6]*0.00001785305/0.0961538);
+    printf("AN_INP_7: 0x%X, %f\r\n", adc_raw_data[AN_INP_7], (double) adc_raw_data[AN_INP_7]*0.00001785305/0.0961538);
+    printf("AN_INP_8: 0x%X, %f\r\n", adc_raw_data[AN_INP_8], (double) adc_raw_data[AN_INP_8]*0.00001785305/0.0961538);
+    printf("AN_INP_9: 0x%X, %f\r\n", adc_raw_data[AN_INP_9], (double) adc_raw_data[AN_INP_9]*0.00001785305/0.0961538);
+    printf("AN_INP_10: 0x%X, %f\r\n", adc_raw_data[AN_INP_10], (double) adc_raw_data[AN_INP_10]*0.00001785305/0.0961538);
+    printf("AN_INP_11: 0x%X, %f\r\n", adc_raw_data[AN_INP_11], (double) adc_raw_data[AN_INP_11]*0.00001785305/0.0961538);
+    printf("AN_INP_12: 0x%X, %f\r\n", adc_raw_data[AN_INP_12], (double) adc_raw_data[AN_INP_12]*0.00001785305/0.0961538);
+    printf("V_ISO_CL: 0x%X, %f\r\n", adc_raw_data[V_ISO_CL], (double) adc_raw_data[V_ISO_CL]*0.00001785305/0.0961538);
+    printf("V_ISO: 0x%X, %f\r\n", adc_raw_data[V_ISO], (double) adc_raw_data[V_ISO]*0.00001785305/0.0961538);
+    printf("CRNT_LIM_U_BFR_R: 0x%X, %f\r\n", adc_raw_data[CRNT_LIM_U_BFR_R], (double) adc_raw_data[CRNT_LIM_U_BFR_R]*0.00001785305/0.0961538);
+    printf("CRNT_LIM_U_ABFR_R: 0x%X, %f\r\n", adc_raw_data[CRNT_LIM_U_ABFR_R], (double) adc_raw_data[CRNT_LIM_U_ABFR_R]*0.00001785305/0.0961538);
+}
+
+// 
+void adc_task(void *params)
+{
+    for (;;)
+    {
+        ai_processing();
+        vTaskDelay(10);
+    }
+}
+
 // Подключить канал к АЦП
 // Одновременно могут быть подключены только 2 канала из наборов:
 // 1: AN_INP_1, AN_INP_2, AN_INP_3, AN_INP_4, AN_INP_5, AN_INP_6, V_ISO_CL, 
@@ -64,8 +288,8 @@ void ai_connect_channel(uint8_t channel)
     
     sh_ai_connect(input_mux);
     
-    printf("Analog input connect register: ");
-    print_binary_byte(input_mux);
+    //printf("Analog input connect register: ");
+    //print_binary_byte(input_mux);
 }
 
 // Утсновить режим измерения канала (ток или напряжение)

+ 27 - 1
fw/modules/io/analog_input.h

@@ -4,6 +4,8 @@
 #include <stdbool.h>
 
 
+
+
 // Режим измерения (ток или напряжение)
 typedef enum
 {
@@ -33,10 +35,29 @@ typedef enum
     AN_INP_11,
     AN_INP_12,
     CRNT_LIM_U_BFR_R,
-    CRNT_LIM_U_ABFR_R
+    CRNT_LIM_U_ABFR_R,
+    
+    NUMBER_ADC_CH,
     
 } ANALOG_IN_t;
 
+//
+void ai_set_meas_mode(void);
+
+//
+bool ai_adc_init(void);
+
+//
+void ai_processing(void);
+
+//
+void adc_get_two_channles(ANALOG_IN_t one, ANALOG_IN_t two);
+
+//
+void adc_print_data(void);
+
+// 
+void adc_task(void *params);
 
 //
 void ai_connect_channel(uint8_t channel);
@@ -50,5 +71,10 @@ void ai_connect_test(void);
 //
 void ai_mode_test(void);
 
+
+
+extern uint16_t adc_raw_data[];
+
+
 #endif  // __ANALOG_INPUT_H
 

+ 147 - 0
fw/modules/modbus/modbus_ai_params.c

@@ -2,6 +2,7 @@
 #include "modbus_ai_params.h"
 #include "settings_api.h"
 #include "modbus_params.h"
+#include "analog_input.h"
 
 
 extern mb_param_t mb_param[];
@@ -23,6 +24,152 @@ uint16_t mb_init_ai_params(uint16_t i)
     
     index++;
     
+    // Сырые данные каналов ADC
+    
+    mb_param[index].reg = 0x0302;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_1];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+   
+    mb_param[index].reg = 0x0303;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_2];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x0304;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_3];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x0305;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_4];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x0306;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_5];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x0307;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_6];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x0308;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_7];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x0309;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_8];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x030A;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_9];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x030B;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_10];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x030C;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_11];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x030D;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[AN_INP_12];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x030E;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[V_ISO_CL];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x030F;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[V_ISO];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x0310;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[CRNT_LIM_U_BFR_R];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
+    mb_param[index].reg = 0x0311;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&adc_raw_data[CRNT_LIM_U_ABFR_R];
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+    
     return index;
 }
 

+ 18 - 0
fw/modules/monitor/monitoring.c

@@ -0,0 +1,18 @@
+#include "at32f403a_407.h"
+#include "monitoring.h"
+
+
+static uint16_t int_err[4];    // Внутренние ошибки модуля
+
+
+// state == true (есть ошибка, нужно установить бит)
+void mon_set_err(err_word_t word_index, err_code_t err_code, bool state)
+{
+    if (state)
+        int_err[word_index] |= 1 << err_code;
+    else
+        int_err[word_index] &= ~(1 << err_code);
+}
+
+
+

+ 30 - 0
fw/modules/monitor/monitoring.h

@@ -0,0 +1,30 @@
+#ifndef __MONITORING_H
+#define __MONITORING_H
+
+#include <stdbool.h>
+
+// Слово ошибок (индекс)
+typedef enum 
+{
+    ERR_WORD_1 = 0,
+    ERR_WORD_2,
+    ERR_WORD_3,
+    ERR_WORD_4,
+      
+} err_word_t;
+
+
+// Коды ошибок модуля
+typedef enum
+{
+    ERR_OK = 0,
+    ADC_ERR,
+    
+} err_code_t;
+
+
+void mon_set_err(err_word_t word_index, err_code_t err_code, bool state);
+
+
+#endif  // __MONITORING_H
+

+ 6 - 4
fw/user/main.cpp

@@ -143,13 +143,15 @@ void init_task(void *argument)
     //ai_connect_channel(AN_INP_1);  
     //ai_connect_channel(AN_INP_7); 
     
-    sh_init();
-      
+    sh_init();          // Сдвиговые регистры
+    ai_set_meas_mode(); // Режим зимерения из настроек
+    ai_adc_init();      // Внешинй ADC
+    
     // Режим зимерения напряженния
-    ai_mode_test();
+    //ai_mode_test();
     
     //ai_connect_channel(V_ISO_CL);
-    ai_connect_channel(V_ISO);
+    //ai_connect_channel(V_ISO);
     
     xTaskCreate(adc_task, "adc_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
 #endif    

BIN
output/fw.bin


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 394 - 392
project/ewarm/iap/iap.dep


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 606 - 581
project/ewarm/module_universal_io.dep


+ 7 - 0
project/ewarm/module_universal_io.ewp

@@ -386,6 +386,7 @@
                     <state>$PROJ_DIR$\..\..\fw\modules\log</state>
                     <state>$PROJ_DIR$\..\..\fw\modules\terminal</state>
                     <state>$PROJ_DIR$\..\..\fw\modules\testing</state>
+                    <state>$PROJ_DIR$\..\..\fw\modules\monitor</state>
                     <state>$PROJ_DIR$\..\..\fw\user</state>
                     <state>$PROJ_DIR$\..\..\libs\thirdparty\freertos\include</state>
                     <state>$PROJ_DIR$\..\..\libs\thirdparty\freertos\portable\IAR\ARM_CM4F</state>
@@ -2254,6 +2255,12 @@
                     <name>$PROJ_DIR$\..\..\fw\modules\modbus\update.c</name>
                 </file>
             </group>
+            <group>
+                <name>monitor</name>
+                <file>
+                    <name>$PROJ_DIR$\..\..\fw\modules\monitor\monitoring.c</name>
+                </file>
+            </group>
             <group>
                 <name>settings</name>
                 <file>

+ 6 - 0
project/ewarm/module_universal_io.ewt

@@ -2463,6 +2463,12 @@
                     <name>$PROJ_DIR$\..\..\fw\modules\modbus\update.c</name>
                 </file>
             </group>
+            <group>
+                <name>monitor</name>
+                <file>
+                    <name>$PROJ_DIR$\..\..\fw\modules\monitor\monitoring.c</name>
+                </file>
+            </group>
             <group>
                 <name>settings</name>
                 <file>

BIN
tools/__pycache__/digital_io.cpython-312.pyc


BIN
tools/__pycache__/log_reader.cpython-312.pyc


BIN
tools/__pycache__/mb_registers.cpython-312.pyc


+ 65 - 4
tools/analog_in.py

@@ -6,14 +6,26 @@ from colorama import Fore
 from time import sleep
 from serial import Serial
 from mb_registers import AI_REGS
+import matplotlib.pyplot as plt 
+import matplotlib.animation as animation 
 
 
 class IO_AnalogInput(IO_Module):
+
+    GRAPTH_LEN = 100
+
     def __init__(self, modbus: Modbus):
         self.modbus = modbus
         super().__init__(self.modbus)
         self.log = AnalogInputLogReader(self.modbus)
 
+        self.fig = plt.figure()
+        self.in1 = self.fig.add_subplot(1, 1, 1)
+        # self.in2 = self.fig.add_subplot(1, 1, 2)
+        self.x = [0]
+        self.data_in1 = []
+        # self.data_in2 = []
+
     '''Чтение параметров'''
 
     # Рожим работы входов
@@ -21,24 +33,73 @@ class IO_AnalogInput(IO_Module):
         data = self.modbus.read_holding_registers(AI_REGS['ain_mode'], 1)
         return format(data[0], '012b')
 
+    def get_raw_inputs(self):
+        data = self.modbus.read_holding_registers(AI_REGS['ain_raw'], 16)
+        return data
+
     '''Установка параметров'''
 
     def set_inputs_mode(self, val):
         self.modbus.write_holding_register(AI_REGS['ain_mode'], val)
 
+    '''Вывод параметров'''
+    def print_raw_inputs(self):
+        data = self.get_raw_inputs()
+        print(f"[ADC raw] IN_1: {data[0]}, IN_2: {data[1]}, IN_3: {data[2]}, IN_4: {data[3]}")
+        print(f"[ADC raw] IN_5: {data[4]}, IN_6: {data[5]}, IN_7: {data[6]}, IN_8: {data[7]}")
+        print(f"[ADC raw] IN_9: {data[8]}, IN_10: {data[9]}, IN_11: {data[10]}, IN_12: {data[11]}")
+        print(f"[ADC raw] V_ISO_CL: {data[12]}, V_ISO: {data[13]}")
+        print(f"[ADC raw] CRNT_LIM_U_BFR_R: {data[14]}, CRNT_LIM_U_ABFR_R: {data[15]}")
+
+    '''Вывод данных на график'''
+
+    
+
+    def draw_raw_inputs(self, i):
+        data = self.get_raw_inputs()
+
+        self.data_in1.append(data[0]) 
+        # self.data_in2.append(data[1])
+
+
+        self.in1.clear()
+        self.in1.plot(self.x, self.data_in1)
+        # self.in2.clear()
+        # self.in2.plot(self.x, self.data_in2)
+
+        if len(self.data_in1) == self.GRAPTH_LEN:
+            self.data_in1.pop(0)
+            # self.data_in2.pop(0)
+            self.x.pop(0)
+
+        self.x.append(self.x[-1] + 1)
+
+        # print(self.in1)
+        # print(self.x)
+
+        
+        
+
+
+
 def main():
     colorama.init(autoreset=True)
     
-    serial_port = Serial('COM56', 115200, timeout=0.05, parity='N', xonxoff=False)
+    serial_port = Serial('COM24', 115200, timeout=0.05, parity='N', xonxoff=False)
     
     modbus_tester = Modbus(serial_port, 1)
     # dev_tester = IO_Digital(modbus_tester)
     ai = IO_AnalogInput(modbus_tester)
 
     '''Режим работы аналоговых входов'''
-    print(ai.get_inputs_mode())
-    ai.set_inputs_mode(0b00011000)
-    print(ai.get_inputs_mode())
+    # print(ai.get_inputs_mode())
+    # ai.set_inputs_mode(0b00011000)
+    
+    # ai.get_raw_inputs()
+    # ai.print_raw_inputs()
+
+    ani = animation.FuncAnimation(ai.fig, ai.draw_raw_inputs, interval=100)
+    plt.show()
 
 if __name__ == '__main__':
     main()

+ 1 - 1
tools/mb_registers.py

@@ -10,6 +10,6 @@ reg_table = {'out_cur': 0x0200, 'out_mode': 0x0202, 'out_mode_save': 0x0203, 'pw
 DIO_REGS = {'in_bits': 0x0100, 'in_cnt': 0x0102,'in_mode': 0x0120, 'in_norm': 0x0122,
             'in_deb_start': 0x124, 'load_bits': 0x0130, 'cred_bits': 0x0131, 'out_cur': 0x0200}
 
-AI_REGS = {'ain_mode': 0x0300}
+AI_REGS = {'ain_mode': 0x0300, 'ain_raw': 0x0302}
 
 LOG_REGS = {'log_info': 0x0900, 'log_ent': 0x0901, 'arch_cap': 0x0902, 'arch_ent': 0x0903, 'arch_per': 0x0904}

+ 2 - 2
tools/tester.py

@@ -1,5 +1,5 @@
 import digital_io
-
+import time
 
 class Tester:
 
@@ -9,7 +9,7 @@ class Tester:
 
 
 def main():
-    pass
+    print(time.time())
 
 if __name__ == '__main__':
     main()

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.