aboutsummaryrefslogtreecommitdiffstats
path: root/sw
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-10-30 11:26:46 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-10-30 11:26:46 +0100
commit4bd5855f386801a594636dc2848376d56700f066 (patch)
treeeb83250116dace0452cd5d975a2daede53c53a5f /sw
parente3cb8a57512c591197264b89801ed43861fee840 (diff)
downloadglutte-batteries-4bd5855f386801a594636dc2848376d56700f066.tar.gz
glutte-batteries-4bd5855f386801a594636dc2848376d56700f066.tar.bz2
glutte-batteries-4bd5855f386801a594636dc2848376d56700f066.zip
Add disjoncteur state message
Diffstat (limited to 'sw')
-rw-r--r--sw/Makefile10
-rw-r--r--sw/README.rst30
-rw-r--r--sw/main.cpp25
-rw-r--r--sw/pins.hpp10
4 files changed, 61 insertions, 14 deletions
diff --git a/sw/Makefile b/sw/Makefile
index 86ff8a6..25922be 100644
--- a/sw/Makefile
+++ b/sw/Makefile
@@ -128,6 +128,16 @@ fuse:
interactive:
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -t -v
+program_pp: $(APP_HEX)
+ $(SIZE) -C $(BUILD_DIR)/$(APP_ELF)
+ $(AVRDUDE) $(AVRDUDE_FLAGS) -c dragon_pp -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -U flash:w:$(BUILD_DIR)/$(APP_HEX) -v
+
+fuse_pp:
+ $(AVRDUDE) $(AVRDUDE_FLAGS) -c dragon_pp -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -U lfuse:w:0x7e:m -U hfuse:w:0xd9:m -U efuse:w:0xfc:m -v
+
+interactive_pp:
+ $(AVRDUDE) $(AVRDUDE_FLAGS) -c dragon_pp -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -t -v
+
help:
@echo "targets: all, program, fuse, interactive"
diff --git a/sw/README.rst b/sw/README.rst
index 90f999d..e1b2f69 100644
--- a/sw/README.rst
+++ b/sw/README.rst
@@ -12,6 +12,7 @@ Au démarrage, avant de passer à la mesure régulière, le code doit:
- Initialiser UART (uniquement TX, on verra si on a besoin du RX plus tard)
- Configurer SPI pour le LTC2400
- Initialiser entrées analogiques et mesurer tension batterie
+- Initialiser entrée numérique D4 pour mesurer contacts auxiliaires des dijoncteurs des trois phases de l'éolienne.
Protocole du port série
-----------------------
@@ -19,16 +20,17 @@ Protocole du port série
Chaque message commence par un identificateur, suivi d'une virgule, du temps en
secondes, une virgule, un champ de données, et termine par CR LF.
-+--------------------+-----------------------------------+
-| Identificateur | Contenu du champ |
-+--------------------+-----------------------------------+
-| `TEXT` | Un message informatif |
-| `ERROR` | Erreur ou avertissement |
-| `CAPA` | Une valeur en mAh |
-| `RELAY` | Etats des trois relais, ON ou OFF |
-| `VBAT+` | Une valeur en mV |
-| `VBAT-` | Une valeur en mV |
-+--------------------+-----------------------------------+
++------------------+---------------------------------------------+
+| Identificateur | Contenu du champ |
++------------------+---------------------------------------------+
+| `TEXT` | Un message informatif |
+| `ERROR` | Erreur ou avertissement |
+| `CAPA` | Une valeur en mAh |
+| `RELAY` | Etats des trois relais, `On` ou `Off` |
+| `VBAT+` | Une valeur en mV |
+| `VBAT-` | Une valeur en mV |
+| `DISJEOL` | `On` ou `Off`, état du disjoncteur eolienne |
++--------------------+-------------------------------------------+
Par exemple: `TEXT,12,Startup\r\n`
@@ -36,7 +38,6 @@ TODO
----
- Definir le comportement par defaut au démarrage, pas de glitch!
-- Initialiser DS18B20
Reglages eFuse
@@ -48,6 +49,13 @@ Reglages eFuse
Commande AVRdude equivalente: `-U lfuse:w:0x7e:m -U hfuse:w:0xd9:m -U efuse:w:0xfc:m`
+Remarques
+---------
+
+- Le DS18B20 ne sera pas assemblé, l'entrée D4 et son footprint réutilisés pour brancher les auxiliaires des
+ disjoncteurs de l'éolienne
+
+
Acknowledgements
================
diff --git a/sw/main.cpp b/sw/main.cpp
index 74e944b..f6a7ce9 100644
--- a/sw/main.cpp
+++ b/sw/main.cpp
@@ -69,6 +69,7 @@ constexpr double THRESHOLD_K2_DOWN = THRESHOLD_K2;
constexpr double THRESHOLD_K3_DOWN = THRESHOLD_K3;
constexpr uint32_t MAX_CAPACITY = 1650uL * 3600uL; // As
+constexpr uint32_t STARTUP_CAPACITY = 1023uL * 3600uL; // As
static uint32_t current_capacity;
static uint32_t previous_capacity;
@@ -93,6 +94,7 @@ uint32_t EEMEM stored_capacity3;
static uint32_t last_store_time_seconds;
static uint32_t last_threshold_calculation_seconds;
static uint32_t last_status_print_seconds;
+static uint32_t last_disjoncteur_print_seconds;
static timer_t last_ltc2400_measure;
enum class adc_state_t {
@@ -208,6 +210,14 @@ static void send_voltage(uint32_t millivolts, adc_voltage_id voltage_id, const t
uart_puts(timestamp_buf);
}
+static void send_disjoncteur_state(bool state, const timer_t& time)
+{
+ snprintf(timestamp_buf, sizeof(timestamp_buf), "DISJEOL,%ld,%s" ENDL,
+ time.get_seconds_atomic(),
+ state ? "On" : "Off");
+ uart_puts(timestamp_buf);
+}
+
static void load_capacity_from_eeprom()
{
@@ -243,7 +253,7 @@ static void load_capacity_from_eeprom()
if (current_capacity == 0xFFffFFff) {
/* EEPROM does not contain a valid value */
- current_capacity = MAX_CAPACITY;
+ current_capacity = STARTUP_CAPACITY;
}
previous_capacity = current_capacity;
@@ -404,6 +414,12 @@ int main()
send_message("Startup");
}
+#if 0
+ current_capacity = 1023uL * 3600uL;
+ store_capacity_to_eeprom();
+ while (true) {}
+#endif
+
system_timer = timer_t(0, 0);
/* Load capacity stored in EEPROM */
@@ -417,6 +433,7 @@ int main()
last_store_time_seconds =
last_status_print_seconds =
+ last_disjoncteur_print_seconds =
last_adc_measure_time_seconds =
last_threshold_calculation_seconds = system_timer.get_seconds_atomic();
@@ -551,6 +568,12 @@ int main()
break;
}
+ constexpr auto disjoncteur_measure_interval = 60;
+ if (last_disjoncteur_print_seconds + disjoncteur_measure_interval < time_now.seconds_) {
+ last_disjoncteur_print_seconds += disjoncteur_measure_interval;
+ send_disjoncteur_state(pins_read_disjoncteur_eolienne(), time_now);
+ }
+
relays_handle(time_now);
}
diff --git a/sw/pins.hpp b/sw/pins.hpp
index 7654819..b873edb 100644
--- a/sw/pins.hpp
+++ b/sw/pins.hpp
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2019 Matthias P. Braendli
+ * Copyright (c) 2020 Matthias P. Braendli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -70,7 +70,7 @@ constexpr uint8_t PINC_INIT = 0;
constexpr uint8_t PIND_UART_RX = _BV(0);
constexpr uint8_t PIND_UART_TX = _BV(1);
-constexpr uint8_t PIND_ONEWIRE = _BV(4); // with exteral pullup
+constexpr uint8_t PIND_DISJONCTEUR_EOLIENNE = _BV(4); // with exteral 4k7 pullup
constexpr uint8_t PIND_K1_RESET = _BV(5);
constexpr uint8_t PIND_K1_SET = _BV(6);
@@ -91,3 +91,9 @@ inline void pins_set_status(bool enable)
}
}
+/* True = breaker is closed, wind generator is connected. */
+inline bool pins_read_disjoncteur_eolienne()
+{
+ /* Breaker closed means auxiliary closed, measure low voltage */
+ return not(PIND & PIND_DISJONCTEUR_EOLIENNE);
+}