aboutsummaryrefslogtreecommitdiff
path: root/arch/attiny1616.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2024-03-29 08:21:24 -0600
committerSelene ToyKeeper2024-03-29 08:21:24 -0600
commit849bc5951b27f3f6296d28e8f62f2077e811e2ad (patch)
tree96939f9b03267c410bb211427f5ca346dc75df04 /arch/attiny1616.c
parentd3aa weak battery test: blink 3x instead of 2x, and omit number readout (diff)
parentuse smooth steps in lockout mode, if enabled (diff)
downloadanduril-849bc5951b27f3f6296d28e8f62f2077e811e2ad.tar.gz
anduril-849bc5951b27f3f6296d28e8f62f2077e811e2ad.tar.bz2
anduril-849bc5951b27f3f6296d28e8f62f2077e811e2ad.zip
Merge branch 'trunk' into emisar-d3aa
FIXME: The d3aa's voltage calculator needs to be fixed after this merge. * trunk: use smooth steps in lockout mode, if enabled fixed Tactical Mode's strobes when Momentary Mode not enabled increased voltage precision from 0.025V to 0.02V (so 0 to 255 now goes from 0.00V to 5.10V) fixed inaccurate comment (thanks to xikteny for spotting it) Allow manually running GitHub actions workflows Bugfix: Prevent switching channel modes when in tactical mode Bugfix: Tactical mode has a dependency on momentary mode
Diffstat (limited to 'arch/attiny1616.c')
-rw-r--r--arch/attiny1616.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/arch/attiny1616.c b/arch/attiny1616.c
index c5499dd..02e64b1 100644
--- a/arch/attiny1616.c
+++ b/arch/attiny1616.c
@@ -104,18 +104,18 @@ inline uint16_t mcu_adc_result_volts() {
inline uint8_t mcu_vdd_raw2cooked(uint16_t measurement) {
// In : 65535 * 1.5 / Vbat
- // Out: uint8_t: Vbat * 40
+ // Out: uint8_t: Vbat * 50
// 1.5 = ADC Vref
#if 0
// 1024 = how much ADC resolution we're using (10 bits)
// (12 bits available, but it costs an extra 84 bytes of ROM to calculate)
- uint8_t vbat40 = (uint16_t)(40 * 1.5 * 1024) / (measurement >> 6);
+ uint8_t vbat = (uint16_t)(10 * dV * 1.5 * 1024) / (measurement >> 6);
#else
// ... spend the extra 84 bytes of ROM for better precision
// 4096 = how much ADC resolution we're using (12 bits)
- uint8_t vbat40 = (uint32_t)(40 * 1.5 * 4096) / (measurement >> 4);
+ uint8_t vbat = (uint32_t)(10 * dV * 1.5 * 4096) / (measurement >> 4);
#endif
- return vbat40;
+ return vbat;
}
#if 0 // fine voltage, 0 to 10.24V in 1/6400th V steps
@@ -130,12 +130,12 @@ inline uint16_t mcu_vdd_raw2fine(uint16_t measurement) {
#ifdef USE_VOLTAGE_DIVIDER
inline uint8_t mcu_vdivider_raw2cooked(uint16_t measurement) {
// In : 4095 * Vdiv / 1.1V
- // Out: uint8_t: Vbat * 40
+ // Out: uint8_t: Vbat * 50
// Vdiv = Vbat / 4.3 (typically)
// 1.1 = ADC Vref
const uint16_t adc_per_volt =
(((uint16_t)ADC_44 << 4) - ((uint16_t)ADC_22 << 4))
- / (4 * (44-22));
+ / (dV * (44-22));
uint8_t result = measurement / adc_per_volt;
return result;
}