rewrote to use 16bits for overflow events timer. Also set to the calculated 510ms
This commit is contained in:
parent
b8839a9b2b
commit
8bbde5260e
18
main.c
18
main.c
|
@ -32,6 +32,10 @@
|
||||||
#define UINT8_MAX 256
|
#define UINT8_MAX 256
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UINT16_MAX
|
||||||
|
#define UINT16_MAX 65536
|
||||||
|
#endif
|
||||||
|
|
||||||
//This is the bitpattern that should be at address 0x00
|
//This is the bitpattern that should be at address 0x00
|
||||||
#define START_PATTERN 0xAA
|
#define START_PATTERN 0xAA
|
||||||
#define END_PATTERN 0x55
|
#define END_PATTERN 0x55
|
||||||
|
@ -70,13 +74,17 @@
|
||||||
* OVF_S = (F_CPU / DIV)/ (2^8)
|
* OVF_S = (F_CPU / DIV)/ (2^8)
|
||||||
* 61 = (1000000 / 64) / 256
|
* 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
|
* This is important because the ATiny13/A only have a single timer built into
|
||||||
* them.
|
* them.
|
||||||
*
|
*
|
||||||
* Ticks are used as our way of keep track of long button presses.
|
* Ticks are used as our way of keep track of long button presses.
|
||||||
* */
|
* */
|
||||||
//original sent had 60
|
#define LONG_PRESS_TICKS 1493
|
||||||
#define LONG_PRESS_TICKS 66
|
|
||||||
|
|
||||||
|
|
||||||
/*A structure to hold the button info*/
|
/*A structure to hold the button info*/
|
||||||
|
@ -85,7 +93,7 @@ typedef struct {
|
||||||
uint8_t is_bypassed: 1;
|
uint8_t is_bypassed: 1;
|
||||||
uint8_t is_long_pressed: 1;
|
uint8_t is_long_pressed: 1;
|
||||||
uint8_t timer_enabled: 1;
|
uint8_t timer_enabled: 1;
|
||||||
uint8_t pressed_ticks;
|
uint16_t pressed_ticks;
|
||||||
uint8_t input_pin;
|
uint8_t input_pin;
|
||||||
uint8_t output_pin;
|
uint8_t output_pin;
|
||||||
}btn_state;
|
}btn_state;
|
||||||
|
@ -407,11 +415,11 @@ ISR(TIM0_OVF_vect)
|
||||||
debounce_switch();
|
debounce_switch();
|
||||||
|
|
||||||
/*Update the tick_count*/
|
/*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;
|
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;
|
btn2.pressed_ticks += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue