From 463869f62f0f3f75cc017ebbdfa257e4e19c1877 Mon Sep 17 00:00:00 2001 From: "Tom, DL7BJ" <tom@dl7bj.de> Date: Mon, 21 Aug 2023 22:40:04 +0200 Subject: [PATCH] =?UTF-8?q?Das=20Probem=20mit=20dem=20Iambic=20Mode=20lag?= =?UTF-8?q?=20bei=20der=20Funktion=20der=20Entprellung=20der=20Tasteneing?= =?UTF-8?q?=C3=A4nge.=20Muss=20ein=20>=20100=E2=82=AC=20Keyer=20=C3=BCberh?= =?UTF-8?q?aupt=20eine=20Entprellung=20haben=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Überlegung, ob es nicht sinnvoller ist, die Tasteneingänge per Interrupt abzufragen. Das würde den Code auch noch erheblich vereinfachen, da nicht ständig an allen möglichen Stellen die Paddle abgefragt werden müssten. --- .gitignore | 1 + Source/functions.c | 34 +++++++--------------------------- Source/globals.h | 9 ++++++--- Source/main.c | 19 ++++++++++++++----- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 4c5f88a..cc19069 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ .*.swp +Scratch diff --git a/Source/functions.c b/Source/functions.c index 7a9d374..9cfe4a9 100644 --- a/Source/functions.c +++ b/Source/functions.c @@ -141,7 +141,7 @@ void SetEEprom(void) bConfig.Memory = 0; bConfig.RiseTime = 5; bConfig.RiseTimeCounter = 5; - bConfig.DebounceTime = 10; + bConfig.DebounceTime = 5; WriteEEprom(); } /** @brief EEprom lesen @@ -314,7 +314,7 @@ void TXKey(uint8_t State) { if((State) && (bState.KeyState == 0)) { - if(KeyTX) + if(bState.KeyTX) { SidetoneOn(); sbi(PORTC,MORSE_LED); @@ -325,7 +325,7 @@ void TXKey(uint8_t State) { if((State == 0) && (bState.KeyState)) { - if(KeyTX) + if(bState.KeyTX) { SidetoneOff(); cbi(PORTC,MORSE_LED); @@ -451,7 +451,7 @@ void CheckPaddles(void) */ void CheckDitPaddle(void) { - static uint8_t pinvalue = 0; + uint8_t pinvalue = 0; if(PaddleMode == PADDLE_NORMAL) // no reverse paddle pinvalue = PIND & (1<<LEFT_PADDLE); @@ -460,17 +460,7 @@ void CheckDitPaddle(void) if(pinvalue == 0) // DitPaddle betätigt { - if(StatePaddleKeyPressed == NO_KEY_PRESSED) // Entprellen - { - StatePaddleKeyPressed = KEY_PRESSED_DEBOUNCE; - TimerPaddleKeyPressed = 0; - } - if(StatePaddleKeyPressed == KEY_PRESSED) // Debounce ok - { - SerialWriteString("470:DitBuffer == 1\r\n"); - DitBuffer = 1; - StatePaddleKeyPressed = NO_KEY_PRESSED; - } + DitBuffer = 1; } } /* @@ -478,7 +468,7 @@ void CheckDitPaddle(void) */ void CheckDahPaddle(void) { - static uint8_t pinvalue = 0; + uint8_t pinvalue = 0; if(PaddleMode == PADDLE_NORMAL) // no reverse paddle pinvalue = PIND & (1<<RIGHT_PADDLE); @@ -487,17 +477,7 @@ void CheckDahPaddle(void) if(pinvalue == 0) { - if(StatePaddleKeyPressed == NO_KEY_PRESSED) - { - StatePaddleKeyPressed = KEY_PRESSED_DEBOUNCE; - TimerPaddleKeyPressed = 0; - } - if(StatePaddleKeyPressed == KEY_PRESSED) // Debounce ok - { - SerialWriteString("496:DahBuffer == 1\r\n"); - DahBuffer = 1; - StatePaddleKeyPressed = NO_KEY_PRESSED; - } + DahBuffer = 1; } } diff --git a/Source/globals.h b/Source/globals.h index e5fb76e..e475ccc 100644 --- a/Source/globals.h +++ b/Source/globals.h @@ -132,6 +132,7 @@ struct State uint8_t SidetoneEnabled: 1; // Mithörton ein- oder ausgeschaltet uint8_t SendStatus; // uint8_t KeyState:1; // + uint8_t KeyTX:1; }; struct MenuCtrl @@ -206,11 +207,13 @@ volatile uint16_t t_wait_led; volatile uint8_t lastButton; // Wert der letzten Buttonabfrage volatile uint16_t DitMillis; volatile uint16_t DahMillis; -// Zähler und Status für Tasten und Mithörton +// Zähler und Status für Entprellung der Tasteneingänge und Mithörton volatile uint8_t StateStraightKeyPressed; // Merker für StraightKey betätigt volatile uint8_t TimerStraightKeyPressed; // Timer Variable für Entprellung -volatile uint8_t StatePaddleKeyPressed; // Merker für Paddle betätigt -volatile uint8_t TimerPaddleKeyPressed; // Timer Variable für Entprellung +volatile uint8_t StatePaddleDitKeyPressed; // Merker für Paddle betätigt +volatile uint8_t TimerPaddleDitKeyPressed; // Timer Variable für Entprellung +volatile uint8_t StatePaddleDahKeyPressed; // Merker für Paddle betätigt +volatile uint8_t TimerPaddleDahKeyPressed; // Timer Variable für Entprellung volatile uint8_t StateRiseTimeCounter; // Zähler für Anstieg des Mithörtons volatile uint8_t StateRiseTime; volatile uint8_t StateRiseTimeCounter; diff --git a/Source/main.c b/Source/main.c index 812464a..de8adef 100644 --- a/Source/main.c +++ b/Source/main.c @@ -183,6 +183,7 @@ void Init() bMenuCtrl.Config = 0; bMenuCtrl.buttonPressed = 0; bMenuCtrl.buttonPressedLong = 0; + bMenuCtrl.WriteEEprom = 0; sei(); // enable all interrupts } @@ -277,12 +278,20 @@ ISR(TIMER0_COMPA_vect) StateStraightKeyPressed = KEY_PRESSED; } // Softwarentprellung für Paddle - TimerPaddleKeyPressed++; - if(StatePaddleKeyPressed == KEY_PRESSED_DEBOUNCE) + TimerPaddleDitKeyPressed++; + if(StatePaddleDitKeyPressed == KEY_PRESSED_DEBOUNCE) { - if(TimerPaddleKeyPressed > bConfig.DebounceTime) - StatePaddleKeyPressed = KEY_PRESSED; + if(TimerPaddleDitKeyPressed > bConfig.DebounceTime) + StatePaddleDitKeyPressed = KEY_PRESSED; } + // Softwarentprellung für Paddle + TimerPaddleDahKeyPressed++; + if(StatePaddleDahKeyPressed == KEY_PRESSED_DEBOUNCE) + { + if(TimerPaddleDahKeyPressed > bConfig.DebounceTime) + StatePaddleDahKeyPressed = KEY_PRESSED; + } + } /** \brief 8 Bit Timer 2 @@ -328,7 +337,7 @@ void ReStart(void) SetRatio(0); KeyerMode = bConfig.KeyerMode; PaddleMode = bConfig.Reverse; - KeyTX = 1; + bState.KeyTX = 1; bState.KeyState = 0; if(bConfig.SidetoneEnabled) SidetoneEnable();