From 4065d4f5d506d7a0e562e98b06d2afd01e529df6 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 10 Jul 2020 14:53:45 +0200 Subject: add resistive load driver for energy measurement device evaluation --- src/driver/resistive_load.cc | 120 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/driver/resistive_load.cc (limited to 'src/driver') diff --git a/src/driver/resistive_load.cc b/src/driver/resistive_load.cc new file mode 100644 index 0000000..419c6c0 --- /dev/null +++ b/src/driver/resistive_load.cc @@ -0,0 +1,120 @@ +#include "driver/resistive_load.h" +#include "driver/gpio.h" +#include "arch.h" + +#ifndef RESISTIVE_LOAD_PIN1 +#error RESISTIVE_LOAD_PIN1 must be set +#endif + +#ifndef RESISTIVE_LOAD_PIN2 +#error RESISTIVE_LOAD_PIN2 must be set +#endif + +#ifndef RESISTIVE_LOAD_PIN3 +#error RESISTIVE_LOAD_PIN3 must be set +#endif + +#ifndef RESISTIVE_LOAD_PIN4 +#error RESISTIVE_LOAD_PIN4 must be set +#endif + +void ResistiveLoad::setup() +{ + gpio.output(RESISTIVE_LOAD_PIN1, 0); + gpio.output(RESISTIVE_LOAD_PIN2, 0); + gpio.output(RESISTIVE_LOAD_PIN3, 0); + gpio.output(RESISTIVE_LOAD_PIN4, 0); +} + +void ResistiveLoad::switchToNone() +{ + gpio.write(RESISTIVE_LOAD_PIN1, 0); + gpio.write(RESISTIVE_LOAD_PIN2, 0); + gpio.write(RESISTIVE_LOAD_PIN3, 0); + gpio.write(RESISTIVE_LOAD_PIN4, 0); +} + +void ResistiveLoad::switchTo750() +{ + gpio.write(RESISTIVE_LOAD_PIN1, 1); + gpio.write(RESISTIVE_LOAD_PIN2, 1); + gpio.write(RESISTIVE_LOAD_PIN3, 0); + gpio.write(RESISTIVE_LOAD_PIN4, 0); +} + +void ResistiveLoad::switchTo1K0() +{ + gpio.write(RESISTIVE_LOAD_PIN1, 1); + gpio.write(RESISTIVE_LOAD_PIN2, 0); + gpio.write(RESISTIVE_LOAD_PIN3, 0); + gpio.write(RESISTIVE_LOAD_PIN4, 0); +} + +void ResistiveLoad::switchTo2K4() +{ + gpio.write(RESISTIVE_LOAD_PIN1, 0); + gpio.write(RESISTIVE_LOAD_PIN2, 1); + gpio.write(RESISTIVE_LOAD_PIN3, 0); + gpio.write(RESISTIVE_LOAD_PIN4, 1); +} + +void ResistiveLoad::switchTo3K3() +{ + gpio.write(RESISTIVE_LOAD_PIN1, 0); + gpio.write(RESISTIVE_LOAD_PIN2, 1); + gpio.write(RESISTIVE_LOAD_PIN3, 0); + gpio.write(RESISTIVE_LOAD_PIN4, 0); +} + +void ResistiveLoad::switchTo10K() +{ + gpio.write(RESISTIVE_LOAD_PIN1, 0); + gpio.write(RESISTIVE_LOAD_PIN2, 0); + gpio.write(RESISTIVE_LOAD_PIN3, 0); + gpio.write(RESISTIVE_LOAD_PIN4, 1); +} + +void ResistiveLoad::switchTo47K() +{ + gpio.write(RESISTIVE_LOAD_PIN1, 0); + gpio.write(RESISTIVE_LOAD_PIN2, 0); + gpio.write(RESISTIVE_LOAD_PIN3, 1); + gpio.write(RESISTIVE_LOAD_PIN4, 0); +} + +void ResistiveLoad::nop1K0(unsigned int duration_ms) +{ + switchTo1K0(); + arch.delay_ms(duration_ms); + switchToNone(); +} + +void ResistiveLoad::nop2K4(unsigned int duration_ms) +{ + switchTo2K4(); + arch.delay_ms(duration_ms); + switchToNone(); +} + +void ResistiveLoad::nop3K3(unsigned int duration_ms) +{ + switchTo3K3(); + arch.delay_ms(duration_ms); + switchToNone(); +} + +void ResistiveLoad::nop10K(unsigned int duration_ms) +{ + switchTo10K(); + arch.delay_ms(duration_ms); + switchToNone(); +} + +void ResistiveLoad::nop47K(unsigned int duration_ms) +{ + switchTo47K(); + arch.delay_ms(duration_ms); + switchToNone(); +} + +ResistiveLoad resistiveLoad; -- cgit v1.2.3