Ver Fonte

Fixes: WIP auf der Messeinrichtung. Achtung, noch größere Delays zum einfacheren Messen drin.

Heinrich Blatt há 5 meses atrás
pai
commit
dfd59ebf65
5 ficheiros alterados com 45 adições e 9 exclusões
  1. 5 0
      main_target.c
  2. 16 2
      main_target.syscfg
  3. 0 1
      src/battery_data/battery.h
  4. 1 1
      src/config.h
  5. 23 5
      src/peripherals/adc.c

+ 5 - 0
main_target.c

@@ -57,6 +57,9 @@ int main(void)
     DL_ADC12_startConversion(ADC12_0_INST);
     DL_ADC12_enableConversions(ADC12_0_INST);
 
+    delay_cycles(320000*4);
+    slot.set_current = 800;
+
     while (1) {
 
         if (handle_read_pending_slot != -1) {
@@ -75,5 +78,7 @@ int main(void)
         } else {
             slot_disable();
         }
+
+        delay_cycles(320000*4);
     }
 }

+ 16 - 2
main_target.syscfg

@@ -20,6 +20,7 @@ const I2C           = scripting.addModule("/ti/driverlib/I2C", {}, false);
 const I2C1          = I2C.addInstance();
 const OPA           = scripting.addModule("/ti/driverlib/OPA", {}, false);
 const OPA1          = OPA.addInstance();
+const OPA2          = OPA.addInstance();
 const PWM           = scripting.addModule("/ti/driverlib/PWM", {}, false);
 const PWM1          = PWM.addInstance();
 const SYSCTL        = scripting.addModule("/ti/driverlib/SYSCTL");
@@ -34,6 +35,7 @@ ADC121.enabledInterrupts   = ["DL_ADC12_INTERRUPT_MEM0_RESULT_LOADED"];
 ADC121.sampClkDiv          = "DL_ADC12_CLOCK_DIVIDE_8";
 ADC121.powerDownMode       = "DL_ADC12_POWER_DOWN_MODE_MANUAL";
 ADC121.sampleTime0         = "125 us";
+ADC121.adcMem0vref         = "VREF";
 ADC121.peripheral.$assign  = "ADC0";
 ADC121.adcPin0Config.$name = "ti_driverlib_gpio_GPIOPinGeneric4";
 
@@ -79,7 +81,6 @@ I2C1.sclPinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric3";
 I2C1.sclPinConfig.enableConfig         = true;
 
 OPA1.$name                     = "OPA_0";
-OPA1.cfg0Gain                  = "N1_P2";
 OPA1.cfg0OutputPin             = "ENABLED";
 OPA1.cfg0PSELChannel           = "DAC8_OUT";
 OPA1.cfg0NSELChannel           = "RTAP";
@@ -88,6 +89,19 @@ OPA1.peripheral.$assign        = "OPA0";
 OPA1.peripheral.OutPin.$assign = "PA22";
 OPA1.OutPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric0";
 
+OPA2.$name                        = "OPA_1";
+OPA2.cfg0PSELChannel              = "IN0_POS";
+OPA2.cfg0NSELChannel              = "IN1_NEG";
+OPA2.cfg0OutputPin                = "ENABLED";
+OPA2.cfg0MSELChannel              = "IN1_NEG";
+OPA2.peripheral.$assign           = "OPA1";
+OPA2.peripheral.In0PosPin.$assign = "PA18";
+OPA2.peripheral.In1NegPin.$assign = "PA17/OPA1.IN0-";
+OPA2.peripheral.OutPin.$assign    = "PA16";
+OPA2.In0PosPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric5";
+OPA2.In1NegPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric6";
+OPA2.OutPinConfig.$name           = "ti_driverlib_gpio_GPIOPinGeneric7";
+
 PWM1.$name                              = "PWM";
 PWM1.ccIndex                            = [1];
 PWM1.timerCount                         = 320;
@@ -99,7 +113,7 @@ PWM1.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
 PWM1.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
 PWM1.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric1";
 PWM1.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC0";
-PWM1.PWM_CHANNEL_1.ccValue              = 320;
+PWM1.PWM_CHANNEL_1.invert               = true;
 
 SYSCTL.disableNRSTPin     = true;
 SYSCTL.peripheral.$assign = "SYSCTL";

+ 0 - 1
src/battery_data/battery.h

@@ -43,7 +43,6 @@ typedef struct {
     SlotState *state;
     int16_t high_side_voltage;
     uint8_t adc_addr;
-
 } BatterySlot;
 
 //global battery array declaration: extending visiblity of the variable to multiple source files: variable declaration

+ 1 - 1
src/config.h

@@ -27,7 +27,7 @@
 #define PWM_INITIALIZATION_DELAY 100
 
 // PWM Define max CC period
-#define MAX_PWM_CYCLE 320
+#define MAX_PWM_CYCLE 300
 
 #define MAX_DAC_VALUE 255
 

+ 23 - 5
src/peripherals/adc.c

@@ -6,19 +6,25 @@
 #include "src/battery_data/battery.h"
 #include <ti/iqmath/include/IQmathLib.h>
 
-#define N_CHANNELS                  5
+#define N_CHANNELS                  6
 
 // A0 PA27
 // A1 PA26
 // A2 PA25
 // A3 PA24
 // A4 PA16
-// Chan11: Temperature Sensor
+// Chan 0: PA27, Low voltage of cell
+// Chan 1: PA26, High voltage of cell
+// Chan 2: PA25, Hi side of the DAC side shunt
+// Chan 3: High side of 5V
+// Chan 13: OpAmp1 Output, Differential measurement of the 5V shunt (internal)
+// Chan 11: 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_13,
     DL_ADC12_INPUT_CHAN_11,
 };
 
@@ -32,15 +38,27 @@ void ADC12_0_INST_IRQHandler(void)
 {
     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);
+            measurement_results[ch] = ((uint32_t)DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0))*3300/4096;
             if (ch == 1) {
                 // 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;
+                slot.measurement.voltage = (measurement_results[1]-measurement_results[0])*(56+100)/56;
             }
-            if (ch == 4) {
+            if (ch == 2 && slot.dac_value > 0) {
+                slot.measurement.current = (measurement_results[2])*10; // 100mOhms
+            }
+            if (ch == 4 && slot.pwm_value > 0) {
+                int32_t hi_side_votlage = measurement_results[3]*(56+100)/56; // high side (5V voltage level) in volts
+                slot.measurement.current = hi_side_votlage*measurement_results[4]/slot.measurement.voltage*-1; // 1:1 - 100mOhm Shunt, aber Faktor 10 über den OpAmp
+            }
+            if (slot.dac_value == 0 && slot.pwm_value == 0) {
+                // we don't have pwm or dac enabled
+                // -> no current
+                slot.measurement.current = 0;
+            }
+            if (ch == 5) {
                 // Temperature channel
                 qVSample = _IQ15div(_IQ15mpy((measurement_results[ch] << 15) -
                 _IQ15(0.5),_IQ15(ADC_TEMP_VREF_VOLTAGE)), _IQ15(ADC_BIT_RESOLUTION));