From 8bbde5260e9a77daf27ad9653103c8c58f07273a Mon Sep 17 00:00:00 2001 From: jakeg00dwin Date: Wed, 10 Apr 2024 13:36:50 -0700 Subject: [PATCH] rewrote to use 16bits for overflow events timer. Also set to the calculated 510ms --- main.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 4c7be5f..2b3f5c3 100644 --- a/main.c +++ b/main.c @@ -32,6 +32,10 @@ #define UINT8_MAX 256 #endif +#ifndef UINT16_MAX +#define UINT16_MAX 65536 +#endif + //This is the bitpattern that should be at address 0x00 #define START_PATTERN 0xAA #define END_PATTERN 0x55 @@ -70,13 +74,17 @@ * OVF_S = (F_CPU / DIV)/ (2^8) * 61 = (1000000 / 64) / 256 * + * for a 4.8MHz setup. + * OVF_S = (48000000 / 64) / 256 = 2929.6875 + * + *so 0.510S = 510ms means we need about 1493 overflows or ticks + * * This is important because the ATiny13/A only have a single timer built into * them. * * Ticks are used as our way of keep track of long button presses. * */ -//original sent had 60 -#define LONG_PRESS_TICKS 66 +#define LONG_PRESS_TICKS 1493 /*A structure to hold the button info*/ @@ -85,7 +93,7 @@ typedef struct { uint8_t is_bypassed: 1; uint8_t is_long_pressed: 1; uint8_t timer_enabled: 1; - uint8_t pressed_ticks; + uint16_t pressed_ticks; uint8_t input_pin; uint8_t output_pin; }btn_state; @@ -407,11 +415,11 @@ ISR(TIM0_OVF_vect) debounce_switch(); /*Update the tick_count*/ - if(btn1.timer_enabled && btn1.pressed_ticks <= UINT8_MAX){ + if(btn1.timer_enabled && btn1.pressed_ticks <= UINT16_MAX){ btn1.pressed_ticks += 1; } - if(btn2.timer_enabled && btn2.pressed_ticks <= UINT8_MAX){ + if(btn2.timer_enabled && btn2.pressed_ticks <= UINT16_MAX){ btn2.pressed_ticks += 1; }