Skip to content

Commit

Permalink
DPM1000: add external discharge resistor control via GPIO
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelius Claussen <[email protected]>
  • Loading branch information
corneliusclaussen committed Sep 19, 2023
1 parent 460c2ff commit 6763a24
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/DPM1000/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target_sources(${MODULE_NAME}
target_link_libraries(${MODULE_NAME}
PRIVATE
can_protocols::dpm1000
everest::gpio
)
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

Expand Down
3 changes: 3 additions & 0 deletions modules/DPM1000/DPM1000.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ struct Conf {
double current_limit_A;
double voltage_limit_V;
std::string series_parallel_mode;
std::string discharge_gpio_chip;

Check notice on line 29 in modules/DPM1000/DPM1000.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/DPM1000/DPM1000.hpp#L29

struct member 'Conf::discharge_gpio_chip' is never used.
int discharge_gpio_line;

Check notice on line 30 in modules/DPM1000/DPM1000.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/DPM1000/DPM1000.hpp#L30

struct member 'Conf::discharge_gpio_line' is never used.
bool discharge_gpio_polarity;

Check notice on line 31 in modules/DPM1000/DPM1000.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/DPM1000/DPM1000.hpp#L31

struct member 'Conf::discharge_gpio_polarity' is never used.
bool debug_print_all_telemetry;
};

Expand Down
14 changes: 14 additions & 0 deletions modules/DPM1000/main/power_supply_DCImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ void power_supply_DCImpl::init() {
config_voltage_limit = mod->config.voltage_limit_V;
config_power_limit = mod->config.power_limit_W;

if (!mod->config.discharge_gpio_chip.empty()) {
discharge_gpio.open(mod->config.discharge_gpio_chip, mod->config.discharge_gpio_line,
!mod->config.discharge_gpio_polarity);
discharge_gpio.set_output(false);
}

can_broker = std::make_unique<CanBroker>(mod->config.device, mod->config.device_address);

// ensure the module is switched off
Expand Down Expand Up @@ -182,6 +188,14 @@ void power_supply_DCImpl::ready() {
}
}

// Discharge output if it is higher then setpoint voltage.
// Note that this has no timeout, so HW must be designed to sustain the worst case load (e.g. 1000V) continously
if (vc.voltage_V > (voltage + 10)) {
discharge_gpio.set(true);
} else {
discharge_gpio.set(false);
}

if (mod->config.debug_print_all_telemetry) {
// read additional meta data
float current_real_part = 0, current_limit = 0, dcdc_temperature = 0, ac_voltage = 0, voltage_limit = 0,
Expand Down
4 changes: 4 additions & 0 deletions modules/DPM1000/main/power_supply_DCImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
#include <atomic>

#include <gpio.hpp>
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1

namespace module {
Expand Down Expand Up @@ -58,6 +60,8 @@ class power_supply_DCImpl : public power_supply_DCImplBase {
float config_voltage_limit{0};
float config_power_limit{0};
float config_min_voltage_limit{50.};

Everest::Gpio discharge_gpio;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down
14 changes: 14 additions & 0 deletions modules/DPM1000/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ config:
- Parallel
- Automatic
default: Series
discharge_gpio_chip:
description: >-
GPIO chip to use to switch external discharge load on and off. An empty string disables discharging.
Note that the hardware load must be designed to allow permanent discharge from the highest voltage (e.g. 1000V)
type: string
default: ''
discharge_gpio_line:
description: GPIO line to use to switch discharge load
type: integer
default: 0
discharge_gpio_polarity:
description: GPIO polarity, false means active low, true means active high
type: boolean
default: true
debug_print_all_telemetry:
description: Read and print all telemetry from the power module. Helpful while debugging.
type: boolean
Expand Down

0 comments on commit 6763a24

Please sign in to comment.