Преглед изворни кода

Verbesserungen:
* DAC Optimierung: General Call wegrefactored
* DAC Regelschleife funktioniert
* ADC auskommentierten Code entfernt

Heinrich Blatt пре 7 месеци
родитељ
комит
32ed47067b
5 измењених фајлова са 10 додато и 63 уклоњено
  1. 1 1
      main_target.c
  2. 4 5
      main_target.syscfg
  3. 4 3
      src/battery_data/battery.c
  4. 0 30
      src/peripherals/adc/adc.c
  5. 1 24
      src/peripherals/dac/dac.c

+ 1 - 1
main_target.c

@@ -114,7 +114,7 @@ int main(void)
             printf("Calling MCU target action\n");
 #endif
             mcu_i2c_handle(I2C_target_INST);
-            mcu_CommandPending= false;
+            mcu_CommandPending = false;
         }
         
         for(uint8_t slot= 0; slot< NUM_SLOTS; slot++){

+ 4 - 5
main_target.syscfg

@@ -72,49 +72,48 @@ I2C2.sclPinConfig.passedPeripheralType = scripting.forceWrite("Digital");
 I2C2.sclPinConfig.enableConfig         = true;
 
 PWM1.timerCount                         = 320;
-PWM1.timerStartTimer                    = true;
 PWM1.ccIndex                            = [1];
 PWM1.$name                              = "PWM_3";
 PWM1.peripheral.$assign                 = "TIMG0";
 PWM1.peripheral.ccp1Pin.$assign         = "PA6";
-PWM1.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric11";
 PWM1.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
 PWM1.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
 PWM1.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
 PWM1.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
+PWM1.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric11";
 PWM1.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC0";
 
 PWM2.ccIndex                            = [1];
 PWM2.$name                              = "PWM_2";
 PWM2.peripheral.$assign                 = "TIMG1";
 PWM2.peripheral.ccp1Pin.$assign         = "PA2";
-PWM2.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric6";
 PWM2.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
 PWM2.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
 PWM2.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
 PWM2.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
+PWM2.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric6";
 PWM2.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC1";
 
 PWM3.ccIndex                            = [1];
 PWM3.$name                              = "PWM_1";
 PWM3.peripheral.$assign                 = "TIMG2";
 PWM3.peripheral.ccp1Pin.$assign         = "PA22";
-PWM3.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric8";
 PWM3.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
 PWM3.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
 PWM3.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
 PWM3.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
+PWM3.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric8";
 PWM3.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC2";
 
 PWM4.ccIndex                            = [1];
 PWM4.$name                              = "PWM_0";
 PWM4.peripheral.$assign                 = "TIMG4";
 PWM4.peripheral.ccp1Pin.$assign         = "PA25";
-PWM4.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric10";
 PWM4.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
 PWM4.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
 PWM4.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
 PWM4.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
+PWM4.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric10";
 PWM4.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC3";
 
 SYSCTL.disableNRSTPin     = true;

+ 4 - 3
src/battery_data/battery.c

@@ -55,6 +55,7 @@ static void batteryslots_init() {
         set_pwm(i, 0);
     }
 
+    
     if (!i2c_discover(DAC_TARGET_ADDRESS)) {
         // there is only 1 DAC for all 4 slots
         for(uint8_t i=0; i< NUM_SLOTS; i++) {
@@ -114,7 +115,7 @@ static void batteryslots_read_state(uint8_t slot) {
 static void batteryslots_adjust_current(uint8_t slot) {
 
 #ifdef DEBUG_TRACE_CTRL
-    printf("Ctrl: Adjusting battery current. Set current: %d mA, measured current: %d mA\n",
+    printf("Ctrl: Checking to adjust battery current. Set current: %d mA, measured current: %d mA\n",
         battery_slots[slot].set_current,
         battery_slots[slot].measurement.current
         );
@@ -132,7 +133,7 @@ static void batteryslots_adjust_current(uint8_t slot) {
             set_pwm(slot, 0);
         }
 
-        if (battery_slots[slot].set_current + BATTERY_CURRENT_THRESHOLD > battery_slots[slot].measurement.current) {
+        if (battery_slots[slot].set_current + BATTERY_CURRENT_THRESHOLD < battery_slots[slot].measurement.current) {
             // we are outside of the tolerance band
             // exceeded to the upper limit
             // -> update dac value, decrease the voltage
@@ -149,7 +150,7 @@ static void batteryslots_adjust_current(uint8_t slot) {
 #endif
                 *battery_slots[slot].state = SLOT_WARN_LOWER_DAC_NOT_POSSIBLE;
             }
-        } else if (battery_slots[slot].set_current - BATTERY_CURRENT_THRESHOLD < battery_slots[slot].measurement.current) {
+        } else if (battery_slots[slot].set_current - BATTERY_CURRENT_THRESHOLD > battery_slots[slot].measurement.current) {
             // we are outside of the tolerance band
             // exceeded to the upplowerer limit
             // -> update dac value, increase the voltage

+ 0 - 30
src/peripherals/adc/adc.c

@@ -58,36 +58,6 @@ uint16_t read_adc_channel(uint8_t slot, uint8_t channel) {
             printf("[ADC] ADC reading completed. Slot %d Channel %d is %d \n", slot, channel, adc_voltage);
 #endif
             adc_state = ADC_STATE_DONE;
-
-            /*
-            } else if (channel == 1) {
-
-                int16_t raw_adc_current = adc_hal.read_raw(slot, &adc_params);
-                battery_slots[slot].measurement.current =
-                    adc_hal.convert_current(raw_adc_current, &adc_params);
-                adc_state = ADC_STATE_DONE;
-#ifdef DEBUG_ADC
-                printf("[ADC] Battery Current in slot %d is %d mA.\n", slot, battery_slots[slot].measurement.current);
-#endif
-            } else if (channel == 2) {
-                // @fixme: this is the third adc channel, needed for current meausrement on disharge mode
-                int16_t raw_adc_voltage = adc_hal.read_raw(slot, &adc_params);
-                battery_slots[slot].high_side_voltage =
-                    adc_hal.convert_voltage(raw_adc_voltage, &adc_params); 
-                adc_state = ADC_STATE_DONE;
-#ifdef DEBUG_ADC
-                printf("[ADC] Ch3 Voltage in slot %d is %d mV.\n", slot, battery_slots[slot].measurement.voltage);
-#endif
-            } else if (channel == 3) {
-                // @fixme: this is the third adc channel, needed for current meausrement on disharge mode
-                int16_t raw_adc_voltage = adc_hal.read_raw(slot, &adc_params);
-                int16_t high_i = adc_hal.convert_voltage(raw_adc_voltage, &adc_params); 
-                battery_slots[slot].measurement.current = high_i*battery_slots[slot].high_side_voltage/battery_slots[slot].measurement.voltage;
-                adc_state = ADC_STATE_DONE;
-#ifdef DEBUG_ADC
-                printf("[ADC] Ch4 Voltage in slot %d is %d mV.\n", slot, battery_slots[slot].measurement.voltage);
-#endif
-            }*/
             break;
         default:
             channel = 0;

+ 1 - 24
src/peripherals/dac/dac.c

@@ -7,27 +7,6 @@
 #include <stdio.h>
 #include "src/config.h"
 
-
-// The device updates all DAC analog output(vout) at the same time
-
-void DAC_UpdateOutput() {
-  uint8_t general_call_command = 0x08; // General Call Update Command
-  while (DL_I2C_getControllerStatus(I2C_controller_INST) &
-         DL_I2C_CONTROLLER_STATUS_BUSY_BUS)
-    ;
-
-  // Start I2C transaction
-  DL_I2C_startControllerTransfer(I2C_controller_INST, 0x00,
-                                 DL_I2C_CONTROLLER_DIRECTION_TX, 1);
-
-  while (DL_I2C_getControllerStatus(I2C_controller_INST) &
-         DL_I2C_CONTROLLER_STATUS_BUSY_BUS)
-    ;
-
-  DL_I2C_fillControllerTXFIFO(I2C_controller_INST, &general_call_command, 1);
-}
-
-
 bool DAC_SingleWrite(uint8_t slot, uint16_t channel_value) {
     if(channel_value > MAX_DAC_VALUE) {
 #ifdef DEBUG_DAC
@@ -37,7 +16,7 @@ bool DAC_SingleWrite(uint8_t slot, uint16_t channel_value) {
         return false;
     }
     controllerTxPackage.len = 3;
-    controllerTxPackage.packet[0] = (0b01011000 | slot << 1);
+    controllerTxPackage.packet[0] = (0b01000000 | slot << 1);
     controllerTxPackage.packet[1] = (0x10) | ((channel_value >> 8) & 0x0F);
     controllerTxPackage.packet[2] = (channel_value & 0xFF);
 
@@ -58,7 +37,5 @@ bool DAC_SingleWrite(uint8_t slot, uint16_t channel_value) {
         return false;
     }
 
-    DAC_UpdateOutput();
-
     return true;
 }