Heinrich Blatt před 5 měsíci
rodič
revize
e4ca8f41a1
7 změnil soubory, kde provedl 63 přidání a 26 odebrání
  1. 5 0
      main_target.c
  2. 10 11
      main_target.syscfg
  3. 1 1
      src/config.h
  4. 27 14
      src/peripherals/adc.c
  5. 20 0
      src/peripherals/adc.h
  6. 0 0
      src/peripherals/temp.c
  7. 0 0
      src/peripherals/temp.h

+ 5 - 0
main_target.c

@@ -38,6 +38,8 @@ void I2C_target_INST_IRQHandler(void) {
   }
 }
 
+_iq15 qVTrim;
+
 int main(void)
 
 {   
@@ -49,6 +51,9 @@ int main(void)
 
     initialize_target_address();
 
+    qVTrim = _IQ15div(_IQ15mpy((_IQ15(DL_SYSCTL_getTempCalibrationConstant()) -
+            _IQ15(0.5)), _IQ15(ADC_TEMP_VREF_VOLTAGE)), ((uint32_t)(1) << 27));
+
     DL_ADC12_startConversion(ADC12_0_INST);
     DL_ADC12_enableConversions(ADC12_0_INST);
 

+ 10 - 11
main_target.syscfg

@@ -1,8 +1,8 @@
 /**
  * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
  * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
- * @cliArgs --device "MSPM0L130X" --part "Default" --package "VSSOP-20(DGS20)" --product "mspm0_sdk@2.04.00.06"
- * @v2CliArgs --device "MSPM0L1304" --package "VSSOP-20(DGS20)" --product "mspm0_sdk@2.04.00.06"
+ * @cliArgs --device "MSPM0L130X" --part "Default" --package "VSSOP-20(DGS20)" --product "mspm0_sdk@2.05.00.05"
+ * @v2CliArgs --device "MSPM0L1304" --package "VSSOP-20(DGS20)" --product "mspm0_sdk@2.05.00.05"
  * @versions {"tool":"1.22.0+3893"}
  */
 
@@ -43,8 +43,8 @@ Board.peripheral.swclkPin.$assign = "PA20";
 Board.peripheral.swdioPin.$assign = "PA19";
 
 COMP1.$name         = "COMP_0";
-COMP1.vSource       = "DL_COMP_REF_SOURCE_VREF_DAC";
 COMP1.controlSelect = "DL_COMP_DAC_CONTROL_SW";
+COMP1.vSource       = "DL_COMP_REF_SOURCE_VDDA_DAC";
 
 GPIO1.$name                         = "ADDR";
 GPIO1.associatedPins.create(2);
@@ -79,10 +79,11 @@ I2C1.sclPinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric3";
 I2C1.sclPinConfig.enableConfig         = true;
 
 OPA1.$name                     = "OPA_0";
-OPA1.cfg0PSELChannel           = "DAC_OUT";
-OPA1.cfg0NSELChannel           = "RTAP";
 OPA1.cfg0Gain                  = "N1_P2";
 OPA1.cfg0OutputPin             = "ENABLED";
+OPA1.cfg0PSELChannel           = "DAC8_OUT";
+OPA1.cfg0NSELChannel           = "RTAP";
+OPA1.cfg0MSELChannel           = "GND";
 OPA1.peripheral.$assign        = "OPA0";
 OPA1.peripheral.OutPin.$assign = "PA22";
 OPA1.OutPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric0";
@@ -103,17 +104,15 @@ PWM1.PWM_CHANNEL_1.invert               = true;
 SYSCTL.disableNRSTPin     = true;
 SYSCTL.peripheral.$assign = "SYSCTL";
 
-VREF.basicMode              = ["DL_VREF_ENABLE_DISABLE"];
-VREF.vrefPosPinConfig.$name = "ti_driverlib_gpio_GPIOPinGeneric1";
 
 ProjectConfig.migrationCondition = true;
+ProjectConfig.genLibIQ           = true;
 
 /**
  * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future
  * version of the tool will not impact the pinmux you originally saw.  These lines can be completely deleted in order to
  * re-solve from scratch.
  */
-ADC121.peripheral.adcPin0.$suggestSolution  = "PA27";
-COMP1.peripheral.$suggestSolution           = "COMP0";
-VREF.peripheral.$suggestSolution            = "VREF";
-VREF.peripheral.vrefPosPin.$suggestSolution = "PA23";
+ADC121.peripheral.adcPin0.$suggestSolution = "PA27";
+COMP1.peripheral.$suggestSolution          = "COMP0";
+VREF.peripheral.$suggestSolution           = "VREF";

+ 1 - 1
src/config.h

@@ -29,7 +29,7 @@
 // PWM Define max CC period
 #define MAX_PWM_CYCLE 320
 
-#define MAX_DAC_VALUE 4096
+#define MAX_DAC_VALUE 255
 
 //------------
 // Section for configuring debugging outputs

+ 27 - 14
src/peripherals/adc.c

@@ -4,39 +4,52 @@
 #include "ti/driverlib/dl_adc12.h"
 #include "ti_msp_dl_config.h"
 #include "src/battery_data/battery.h"
+#include <ti/iqmath/include/IQmathLib.h>
+
+#define N_CHANNELS                  5
 
 // A0 PA27
 // A1 PA26
 // A2 PA25
 // A3 PA24
 // A4 PA16
-const uint8_t measurement_channels[4] = {
+// Chan11: Temperature Sensor
+const uint8_t measurement_channels[N_CHANNELS] = {
     DL_ADC12_INPUT_CHAN_0,
     DL_ADC12_INPUT_CHAN_1,
     DL_ADC12_INPUT_CHAN_2,
-    DL_ADC12_INPUT_CHAN_3
+    DL_ADC12_INPUT_CHAN_3,
+    DL_ADC12_INPUT_CHAN_11,
 };
 
 uint8_t ch=0;
 
-uint16_t measurement_results[4] = {
-    0,
-    0,
-    0,
-    0
-};
+uint16_t measurement_results[N_CHANNELS] = { 0 };
+
+_iq15 qTsample, qVSample;
 
 void ADC12_0_INST_IRQHandler(void)
 {
-    uint32_t irqval = DL_ADC12_getPendingInterrupt(ADC12_0_INST);
-    printf("irqval: %d", irqval);
-    switch (irqval) {
+    switch (DL_ADC12_getPendingInterrupt(ADC12_0_INST)) {
         case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
-            measurement_results[ch] = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0)*3300/4096;
+            measurement_results[ch] = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0);
             if (ch == 1) {
-                slot.measurement.voltage = (measurement_results[1]-measurement_results[0])*(56+100)/56;
+                // We have upper and lower temperature of the cell
+                // -> difference is the cell voltage
+
+                // WTF, teh voltage divider is bridged?
+                slot.measurement.voltage = (measurement_results[1]-measurement_results[0]); //*(56+100)/56;
+            }
+            if (ch == 4) {
+                // Temperature channel
+                qVSample = _IQ15div(_IQ15mpy((measurement_results[ch] << 15) -
+                _IQ15(0.5),_IQ15(ADC_TEMP_VREF_VOLTAGE)), _IQ15(ADC_BIT_RESOLUTION));
+                qTsample = _IQ15mpy(_IQ15(TEMP_TS_COEF_mV_C), (qVSample - qVTrim)) +
+                            (TEMP_TS_TRIM_C << 15);
+
+                slot.measurement.temperature = _IQ15toF(qTsample)*1000;
             }
-            if (++ch == 4) {
+            if (++ch == N_CHANNELS) {
                 ch = 0;
             }
             DL_ADC12_stopConversion(ADC12_0_INST);

+ 20 - 0
src/peripherals/adc.h

@@ -1,4 +1,24 @@
 #ifndef ADC_H
 #define ADC_H
 
+#include <ti/iqmath/include/IQmathLib.h>
+
+/* clang-format off */
+
+/*
+ * The following trim parameter are provided in the device datasheet in chapter
+ * "Temperature Sensor"
+ */
+#define TEMP_TS_TRIM_C                                            ((uint32_t)30)
+/*
+ * Constant below is (1/TSc). Where TSc is Temperature Sensor coefficient
+ * available in the device datasheet
+ */
+#define TEMP_TS_COEF_mV_C                                              (-1.75f)
+
+#define ADC_TEMP_VREF_VOLTAGE                                             (3.3f)
+#define ADC_BIT_RESOLUTION                                   ((uint32_t)(1)<<12)
+
+extern _iq15 qVTrim;
+
 #endif

+ 0 - 0
src/peripherals/temp.c


+ 0 - 0
src/peripherals/temp.h