From 6208012510ae5c6464441f98ed2beede7f4b59e1 Mon Sep 17 00:00:00 2001 From: Manfred Steiner Date: Wed, 11 Sep 2024 12:49:17 +0200 Subject: [PATCH] software/nano-644/test_2024-07-23 (Anpassungen Board 2 - R2R) --- software/nano-644/test_2024-07-23/src/units/r2r.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/software/nano-644/test_2024-07-23/src/units/r2r.cpp b/software/nano-644/test_2024-07-23/src/units/r2r.cpp index 87fb822..54664b1 100644 --- a/software/nano-644/test_2024-07-23/src/units/r2r.cpp +++ b/software/nano-644/test_2024-07-23/src/units/r2r.cpp @@ -11,11 +11,11 @@ #ifdef __AVR_ATmega328P__ // AVCC=4.7V, POTI Vmax=3.3V - #define K (1023.0 / 738.0) + #define K 1.32 #endif void R2r::init () { - ADMUX = (1 << REFS0) | 2; // ADC2, VREF=AVCC=3.3V + ADMUX = (1 << REFS0) | 2; // ADC2, VREF=AVCC (=3.3V for Nano-644/1284, =5V for Arduino Nano) ADCSRA = (1 << ADEN) | 7; // ADC Enable, Prescaler 128 } @@ -33,8 +33,10 @@ int8_t R2r::run (uint8_t subtest) { ADCSRA |= (1 << ADSC); // start ADC while (ADCSRA & (1 << ADSC)) {} // wait for result printf_P(PSTR("%4d (0x%03x)"), ADC, ADC); - uint8_t sw = (uint8_t)( ((float)(ADC) + 32.0) / 64.0 * K ); - printf_P(PSTR(" SW9:6 = %d %d% d %d "), sw >> 3, (sw >> 2) & 0x01, (sw >> 1) & 0x01, sw & 0x01 ); + // uint8_t sw = (uint8_t)( ((float)(ADC) + 4.0) / 64.0 * K ); + float swf = ((float)(ADC) * K) / 64.8 + 0.55; + uint8_t sw = (uint8_t)swf ; + printf_P(PSTR(" %3.1f => SW9:6 = %d %d% d %d "), swf, sw >> 3, (sw >> 2) & 0x01, (sw >> 1) & 0x01, sw & 0x01 ); } return 0; } -- 2.39.5