aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-08-05 21:35:47 -0600
committerSelene ToyKeeper2019-08-05 21:35:47 -0600
commit6c3b0a6b5b71f1b587ec290284923a77177d713a (patch)
tree96023f60929dde1372ff1ad3e1743ac067bd987d
parentfixed weird ramp behavior on D1S v2 (by trusting the compiler more) (diff)
downloadanduril-6c3b0a6b5b71f1b587ec290284923a77177d713a.tar.gz
anduril-6c3b0a6b5b71f1b587ec290284923a77177d713a.tar.bz2
anduril-6c3b0a6b5b71f1b587ec290284923a77177d713a.zip
fixed voltage measurement on D1S v2
-rw-r--r--hwdef-Emisar_D1Sv2.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/hwdef-Emisar_D1Sv2.h b/hwdef-Emisar_D1Sv2.h
index 6895e73..e1f8029 100644
--- a/hwdef-Emisar_D1Sv2.h
+++ b/hwdef-Emisar_D1Sv2.h
@@ -58,11 +58,29 @@
//#define PWM2_LVL OCR1B // OCR1B is the output compare register for PB1
+#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened
+#define VOLTAGE_PIN PA3 // Pin 4 / PA3 / ADC0
+#define VOLTAGE_ADC_DIDR ADC0D // digital input disable pin for PA3
+// DS tables 19-3, 19-4
+// Bit 7 6 5 4 3 2 1 0
+// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0
+// MUX[3:0] = 0, 0, 0, 0 for ADC0 / PA3
+// divided by ...
+// REFS[1:0] = 1, 0 for internal 1.1V reference
+// other bits reserved
+#define ADMUX_VOLTAGE_DIVIDER 0b10000000
#define ADC_PRSCL 0x06 // clk/64
-// average drop across diode on this hardware
-#ifndef VOLTAGE_FUDGE_FACTOR
-#define VOLTAGE_FUDGE_FACTOR 4 // add 0.20V (measured 0.22V)
+// Raw ADC readings at 4.4V and 2.2V
+// calibrate the voltage readout here
+// estimated / calculated values are:
+// (voltage - D1) * (R2/(R2+R1) * 256 / 1.1)
+// D1, R1, R2 = 0, 330, 100
+#ifndef ADC_44
+#define ADC_44 235
+#endif
+#ifndef ADC_22
+#define ADC_22 116
#endif
#define TEMP_CHANNEL 0b00001111
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.