Pārlūkot izejas kodu

Проверил ADC. Доработка драйвера.

TelenkovDmitry 1 gadu atpakaļ
vecāks
revīzija
52b83584b1

+ 56 - 6
fw/modules/adc/adc_transport.c

@@ -6,6 +6,7 @@
 #include "io_utils.h"
 #include "adc_transport.h"
 #include "misc.h"
+#include "utility.h"
 #include <stdio.h>
 
 
@@ -70,6 +71,14 @@ void adc_gpio_init(void)
     
     spi_enable(MS5192T_SPI, TRUE);
 }
+ 
+    
+//
+inline flag_status adc_get_rdy(void)
+{
+    return gpio_input_data_bit_read(GPIOE, GPIO_PINS_13);
+}
+
 
 
 /***************************************************************************//**
@@ -214,23 +223,64 @@ void adc_task(void *params)
         
     // Запрос регистра конфигурации для (0x710 - значение по умолчанию)
     value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
-    printf("ADC configuretion register: 0x%X\r\n", value);
+    printf("ADC cfg reg: 0x%X: ", value);
+    print_binary_half_word((uint16_t)value);
 
     // Коэф-т усиления: 1
-    printf("ADC. Set gain rate: %u\r\n", (uint8_t)MS5192T_GAIN_1);
+    printf("ADC. Set gain rate 1\r\n");
     MS5192T_SetGain(MS5192T_GAIN_1);
     value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
-    printf("ADC configuretion register: 0x%X, gain rate = %u (value 0 eq 1 gain rate)\r\n",
-           value, (value & 0x700) >> 8);
+    printf("ADC cfg reg: 0x%X: ", value);
+    print_binary_half_word((uint16_t)value);
     
-    printf("Set unipolar input mode.\r\n");
+    // Униполярный режим
+    printf("Set unipolar input mode...\r\n");
     MS5192T_SetPolar(MS5192T_CONF_UNIPOLAR);
     value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
-    printf("ADC configuretion register: 0x%X, polar bit: %u\r\n", value, (value & 0x1000) >> 12);
+    printf("ADC cfg reg: 0x%X: ", value);
+    print_binary_half_word((uint16_t)value);
+    
+    // Регистр статуса
+    value = MS5192T_GetRegisterValue(MS5192T_REG_STAT, 1, 1);
+    printf("ADC status reg: 0x%X: ", value);
+    print_binary_byte((uint8_t)value);
     
+    // Установка внутреннего опорного напряжения
+    MS5192T_SetIntReference(MS5192T_REFSEL_INT); // select internal 1.17V reference
+    value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
+    printf("ADC cfg reg: 0x%X: ", value);
+    print_binary_half_word((uint16_t)value);
+      
+    // Регистр режима (MODE register)
+    value = MS5192T_GetRegisterValue(MS5192T_REG_MODE, 2, 1);
+    printf("ADC mode reg: 0x%X: ", value);
+    print_binary_half_word((uint16_t)value);
     
+    // Установить update rate
+    printf("Set update rate.\r\n");
+    MS5192T_SetUpdateRate(MS5192T_UP_RATE_500);
+    value = MS5192T_GetRegisterValue(MS5192T_REG_MODE, 2, 1);
+    printf("ADC mode reg: 0x%X: ", value);
+    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);
+        
     for (;;)
     {
+        value = MS5192T_SingleConversion();
+        printf("ADC data raw: 0x%X, %f\r\n", value, (double)value*0.00001785305);
+        
+        
         
 #if 0      
         if (state == false) 

+ 3 - 0
fw/modules/adc/adc_transport.h

@@ -10,6 +10,9 @@
 //
 void adc_gpio_init(void);
 
+//
+flag_status adc_get_rdy(void);
+
 // Initializes the SPI communication peripheral.
 unsigned char SPI_Init(unsigned char lsbFirst, unsigned long clockFreq,
                        unsigned char clockPol, unsigned char clockPha);

+ 22 - 9
fw/modules/adc/ms5192t.c

@@ -102,13 +102,8 @@ void MS5192T_SetRegisterValue(unsigned char regAddress,
  * @return None.
 *******************************************************************************/
 void MS5192T_WaitRdyGoLow(void)
-{
-/*  
-    while( MS5192T_RDY_STATE )
-    {
-        ;
-    }
-*/    
+{   
+    while (adc_get_rdy() == SET) {}
 }
 
 /***************************************************************************//**
@@ -133,6 +128,24 @@ void MS5192T_SetMode(unsigned long mode)
             2, 
             1); // CS is modified by SPI read/write functions.
 }
+
+                              
+void MS5192T_SetUpdateRate(unsigned long rate)
+{
+    unsigned long command;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_MODE,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_MODE_RATE(0xFF);
+    command |= MS5192T_MODE_RATE(rate);
+    MS5192T_SetRegisterValue(
+            MS5192T_REG_MODE,
+            command,
+            2, 
+            1); // CS is modified by SPI read/write functions.
+}
+                              
 /***************************************************************************//**
  * @brief Selects the channel of MS5192T.
  *
@@ -265,10 +278,10 @@ unsigned long MS5192T_SingleConversion(void)
                             2,
                             0);// CS is not modified by SPI read/write functions.
     MS5192T_WaitRdyGoLow();
-    regData = MS5192T_GetRegisterValue(MS5192T_REG_DATA, 3, 0); // CS is not modified by SPI read/write functions.
+    regData = MS5192T_GetRegisterValue(MS5192T_REG_DATA, 2, 0); // CS is not modified by SPI read/write functions.
     MS5192T_CS_HIGH;
 
-    return(regData);
+    return regData;
 }
 
 /***************************************************************************//**

+ 21 - 1
fw/modules/adc/ms5192t.h

@@ -33,7 +33,7 @@
 /* Mode Register Bit Designations (MS5192T_REG_MODE) */
 #define MS5192T_MODE_SEL(x)		(((x) & 0x7) << 13)	/* Operation Mode Select */
 #define MS5192T_MODE_CLKSRC(x)	(((x) & 0x3) << 6) 	/* ADC Clock Source Select */
-#define MS5192T_MODE_RATE(x)		((x) & 0xF) 		/* Filter Update Rate Select */
+#define MS5192T_MODE_RATE(x)	((x) & 0xF) 		/* Filter Update Rate Select */
 
 /* AD7793_MODE_SEL(x) options */
 #define MS5192T_MODE_CONT       0 /* Continuous Conversion Mode */
@@ -51,6 +51,23 @@
 #define MS5192T_CLK_EXT		    2 /* External 64 kHz Clock */
 #define MS5192T_CLK_EXT_DIV2	3 /* External Clock divided by 2 */
 
+/* MS5192T update rate */
+#define MS5192T_UP_RATE_500     1 /* 500 Hz */
+#define MS5192T_UP_RATE_250     2 /* 250 Hz */
+#define MS5192T_UP_RATE_125     3 /* 125 Hz */
+#define MS5192T_UP_RATE_62      4 /* 62.5 Hz */
+#define MS5192T_UP_RATE_50      5 /* 50 Hz */
+#define MS5192T_UP_RATE_39      6 /* 39.2 Hz */
+#define MS5192T_UP_RATE_33      7 /* 33.3 Hz */
+#define MS5192T_UP_RATE_19      8 /* 19.2 Hz */
+#define MS5192T_UP_RATE_16      9 /* 16.7 Hz */
+#define MS5192T_UP_RATE_14      10 /* 14 Hz */
+#define MS5192T_UP_RATE_12      11 /* 12.5 Hz */
+#define MS5192T_UP_RATE_10      12 /* 500 Hz */
+#define MS5192T_UP_RATE_8       13 /* 8.33 Hz */
+#define MS5192T_UP_RATE_6       14 /* 6.25 Hz */
+#define MS5192T_UP_RATE_4       15 /* 4.17 Hz */
+
 /* Configuration Register Bit Designations (MS5192T_REG_CONF) */
 #define MS5192T_CONF_VBIAS(x)   (((x) & 0x3) << 14) 	/* Bias Voltage Generator Enable */
 #define MS5192T_CONF_BO_EN	    (1 << 13) 			/* Burnout Current Enable */
@@ -129,6 +146,9 @@ void MS5192T_WaitRdyGoLow(void);
 /* Sets the operating mode of MS5192T. */
 void MS5192T_SetMode(unsigned long mode);     
 
+/* Sets update rate */
+void MS5192T_SetUpdateRate(unsigned long rate);
+
 /* Selects the channel of MS5192T. */
 void MS5192T_SetChannel(unsigned long channel);
 

+ 1 - 5
fw/modules/io/analog_input.c

@@ -66,7 +66,6 @@ void ai_connect_channel(uint8_t channel)
     
     printf("Analog input connect register: ");
     print_binary_byte(input_mux);
-    printf("\r\n");
 }
 
 // Утсновить режим измерения канала (ток или напряжение)
@@ -88,10 +87,7 @@ void ai_set_mode(MEAS_CHAN_MODE_t mode, uint8_t channel)
     sh_ai_mode(input_mode);
     
     printf("Analog input mode: ");
-    print_binary_byte(input_mode >> 8);
-    printf("");
-    print_binary_byte(input_mode & 0xFF);
-    printf("\r\n");
+    print_binary_half_word(input_mode);
 }
 
 //

+ 3 - 0
fw/modules/shift_reg/shift_reg.c

@@ -2,6 +2,7 @@
 #include "shift_reg.h"
 #include "FreeRTOS.h"
 #include "task.h"
+#include "misc.h"
 #include <stdio.h>
 #include <stdbool.h>
 
@@ -104,6 +105,7 @@ uint16_t sh_ai_mode(uint16_t val)
     ret |= (SH_SPI->dt & 0x3F) << 8;
     
     gpio_bits_set(GPIOD, GPIO_PINS_0 | GPIO_PINS_1);
+    nop(10);
     gpio_bits_reset(GPIOD, GPIO_PINS_0 | GPIO_PINS_1);
 
     return ret;
@@ -122,6 +124,7 @@ void sh_ai_connect(uint16_t val)
     ret = SH_SPI->dt;
 */    
     gpio_bits_set(GPIOD, GPIO_PINS_3);
+    nop(100);
     gpio_bits_reset(GPIOD, GPIO_PINS_3);
 }
 

+ 3 - 2
fw/user/main.c

@@ -154,8 +154,9 @@ void init_task(void *argument)
 // Тесты аналоговых входов    
     //ai_connect_test();
     ai_mode_test();
-    ai_connect_channel(V_ISO);  
-    ai_connect_channel(AN_INP_8);  
+    //ai_connect_channel(V_ISO);  
+    ai_connect_channel(V_ISO_CL);  
+    ai_connect_channel(AN_INP_7);  
     
 // -------------------------------------------------------------------------- //    
 // DAC    

BIN
output/fw.bin


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 464 - 467
project/ewarm/iap/iap.dep


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 702 - 710
project/ewarm/module_universal_io.dep


+ 18 - 2
shared/utils/utility.c

@@ -30,11 +30,27 @@ void vApplicationMallocFailedHook(void)
 //
 void print_binary_byte(uint8_t val)
 {
-    for (int i = 7; i >= 0; i--)
-    {
+    for (int i = 7; i >= 0; i--) {
         if (val & (1 << i))
             printf("1");
         else
             printf("0");
+        if (i == 4)
+            printf(" ");
     }
+    printf("\r\n");
 }
+
+//
+void print_binary_half_word(uint16_t val)
+{
+    for (int i = 15; i >= 0; i--) {
+        if (val & (1 << i))
+            printf("1");
+        else
+            printf("0");
+        if ((i == 12) || (i == 8) || (i == 4))
+            printf(" ");
+    }
+    printf("\r\n");
+}

+ 2 - 1
shared/utils/utility.h

@@ -5,7 +5,8 @@
 //
 void print_binary_byte(uint8_t val);
 
-
+//
+void print_binary_half_word(uint16_t val);
 
 
 #endif /* __UTILITY_H_ */

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels