From: Manfred Steiner Date: Mon, 16 Sep 2024 08:11:45 +0000 (+0200) Subject: oftware/.../test_2024-07-23: unit motor fertig (V1a/V2a) X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=55947645bebf84784ffcbf6a916cbb776576f6ad;p=nano-x-base.git oftware/.../test_2024-07-23: unit motor fertig (V1a/V2a) --- diff --git a/software/nano-644/test_2024-07-23/src/units/led.cpp b/software/nano-644/test_2024-07-23/src/units/led.cpp index 5a56665..e908c21 100644 --- a/software/nano-644/test_2024-07-23/src/units/led.cpp +++ b/software/nano-644/test_2024-07-23/src/units/led.cpp @@ -7,12 +7,15 @@ #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) - // Nano-644 + // Nano-644 / Nano 1284 // --------------------------------------------------------------- - // PD4 ..... Red - // PD5 ..... Orange/Yellow - // PD6 ..... Green - // PD7 ..... Blue + + // Nano-X-Base V1a V2a + // ----------------------- + // Red PD4 PD7 + // Orange/Yellow PD5 PD6 + // Green PD6 PD5 + // Blue PD7 PD4 void Led::init () { PORTD &= ~((1 << PD7) | (1 << PD6) | (1 << PD5) | (1 << PD4)); @@ -57,10 +60,13 @@ // Arduino-Nano-5V // --------------------------------------------------------------- - // PD5 ..... Red - // PB1 ..... Orange/Yellow - // PD3 ..... Green - // PD2 ..... Blue + + // Nano-X-Base V1a V2a + // ----------------------- + // Red PD5 PD2 + // Orange/Yellow PB1 PD3 + // Green PD3 PB1 + // Blue PD2 PD5 void Led::init () { PORTD &= ~((1 << PD5) | (1 << PD3) | (1 << PD2)); diff --git a/software/nano-644/test_2024-07-23/src/units/motor.cpp b/software/nano-644/test_2024-07-23/src/units/motor.cpp index 4457c1a..83f0c3b 100644 --- a/software/nano-644/test_2024-07-23/src/units/motor.cpp +++ b/software/nano-644/test_2024-07-23/src/units/motor.cpp @@ -18,6 +18,7 @@ #define ADC0K 64 void Motor::init () { + DDRD |= (1 << PD7); // sensor signal toggle on PD7 (LED D4 red) ADMUX = (1 << ADLAR) | (1 << REFS0); // ADC0, VREF=AVCC=3.3V ADCSRA = (1 << ADEN) | 7; // ADC Enable, Prescaler 128 TCCR0A = (1 << COM0A1) | (1 << WGM01) | (1 << WGM00); // Fast PWM on OC0A @@ -30,6 +31,7 @@ } void Motor::cleanup () { + DDRD &= ~(1 << PD7); ADMUX = 0; ADCSRA = 0; TCCR0A = 0; @@ -58,6 +60,11 @@ bool Motor::isSensorHigh () { return (PINB & (1 << PB0)) != 0; } + + void Motor::toggleD4 () { + PORTD ^= (1 << PD7); + } + #endif #ifdef __AVR_ATmega328P__ @@ -73,6 +80,7 @@ #define ADC0K 91 void Motor::init () { + DDRD |= (1 << PD2); // sensor signal toggle on PD2 (LED D4 red) ADMUX = (1 << ADLAR) | (1 << REFS0); // ADC0, VREF=AVCC=5V ADCSRA = (1 << ADEN) | 7; // ADC Enable, Prescaler 128 TCCR0A = (1 << COM0A1) | (1 << WGM01) | (1 << WGM00); // Fast PWM on OC0A @@ -89,6 +97,7 @@ } void Motor::cleanup () { + DDRD &= ~(1 << PD2); enabled = 0; ADMUX = 0; ADCSRA = 0; @@ -122,6 +131,10 @@ return (PIND & (1 << PD4)) != 0; } + void Motor::toggleD4 () { + PORTD ^= (1 << PD2); + } + #endif int8_t Motor::run (uint8_t subtest) { @@ -169,9 +182,9 @@ int8_t Motor::run (uint8_t subtest) { } float rpm = 60.0 / (float)timer / 0.0001; if (timer > 0) { - printf_P(PSTR(" n= %4d U/min"), (int)rpm); + printf_P(PSTR(" n= %4d U/min (T=%04x)"), (int)rpm, timer); } else { - printf_P(PSTR(" no rotation ")); + printf_P(PSTR(" no rotation (T=%04x) "), timer); } } @@ -188,10 +201,11 @@ void Motor::tick100us () { static bool lastSensorHigh = false; bool sensorHigh = isSensorHigh(); - if (!sensorHigh && sensorHigh != lastSensorHigh && timerL > 10) { + if (!sensorHigh && sensorHigh != lastSensorHigh && timerL > 2) { rpmTimer = timerL + timerH; timerL = 0; timerH = 0; + toggleD4(); } if (sensorHigh) { timerH = timerH < 0x4000 ? timerH + 1 : 0x4000; diff --git a/software/nano-644/test_2024-07-23/src/units/motor.hpp b/software/nano-644/test_2024-07-23/src/units/motor.hpp index 6dc68f0..2cbd15a 100644 --- a/software/nano-644/test_2024-07-23/src/units/motor.hpp +++ b/software/nano-644/test_2024-07-23/src/units/motor.hpp @@ -24,6 +24,7 @@ class Motor : public TestUnit { void setEnable (); bool isFaultLow (); bool isSensorHigh (); + void toggleD4 (); }; #endif \ No newline at end of file