Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jan Kasprzak
tinyboard
Commits
fbbdcc41
Commit
fbbdcc41
authored
May 10, 2013
by
Jan Kasprzak
Browse files
WDT-based timing instead of ADC-based
This will allow us to use power-down sleep when neither ADC nor PWM is used.
parent
75804664
Changes
5
Hide whitespace changes
Inline
Side-by-side
projects/step-up/adc.c
View file @
fbbdcc41
...
...
@@ -11,7 +11,7 @@
#define NUM_ADCS 2
volatile
static
unsigned
char
current_adc
;;
st
ati
c
unsigned
char
need_battery_adc
;
vol
ati
le
unsigned
char
need_battery_adc
;
static
uint16_t
adc_sum
,
read_zero
,
drop_count
,
read_count
,
n_reads_log
;
volatile
uint16_t
jiffies
;
...
...
@@ -126,30 +126,9 @@ void susp_adc()
DIDR0
=
0
;
}
static
void
inline
adc_based_timer
()
{
static
unsigned
char
count
;
if
(
++
count
<
40
)
// about 100 Hz jiffies
return
;
count
=
0
;
++
jiffies
;
if
((
jiffies
&
0x007F
)
==
1
)
{
// about every 1s
need_battery_adc
=
1
;
}
if
((
jiffies
&
0x0007
)
==
0
)
{
patterns_next_tick
();
}
timer_check_buttons
();
}
ISR
(
ADC_vect
)
{
// IRQ handler
uint16_t
adcval
=
ADCW
;
adc_based_timer
();
if
(
read_zero
)
{
setup_mux
(
current_adc
);
read_zero
=
0
;
...
...
projects/step-up/buttons.c
View file @
fbbdcc41
...
...
@@ -7,9 +7,9 @@
#include
"lights.h"
#define WAKEUP_LIMIT 5 // times 100 ms
#define SHORT_PRESS_MIN
10
// in jiffies (1
00
Hz ticks)
#define SHORT_PRESS_MAX 5
0
#define LONG_PRESS_MIN 10
0
#define SHORT_PRESS_MIN
2
// in jiffies (1
6
Hz ticks)
#define SHORT_PRESS_MAX 5
#define LONG_PRESS_MIN 10
static
uint16_t
button_start
;
static
unsigned
char
prev_state
;
...
...
@@ -67,7 +67,7 @@ void timer_check_buttons()
}
else
if
(
!
cur
&&
prev
)
{
// --- just released ---
uint16_t
duration
=
jiffies
-
button_start
;
if
(
duration
>
SHORT_PRESS_MIN
&&
duration
<
SHORT_PRESS_MAX
)
{
if
(
duration
>
=
SHORT_PRESS_MIN
&&
duration
<
SHORT_PRESS_MAX
)
{
short_press
();
}
else
if
(
duration
>
LONG_PRESS_MIN
)
{
// set_status_led(button, NULL);
...
...
projects/step-up/lights.h
View file @
fbbdcc41
...
...
@@ -20,7 +20,7 @@ void inline log_word(uint16_t word) { }
/* adc.c */
#define PWMLED_ADC_SHIFT 1
/* 1<<1 measurements per single callback */
extern
volatile
u
int16_t
jiffies
;
extern
volatile
u
nsigned
char
need_battery_adc
;
void
init_adc
();
void
susp_adc
();
...
...
@@ -76,6 +76,7 @@ pattern_t *status_led_pattern_select();
void
set_error
(
unsigned
char
err
);
/* wdt.c */
extern
volatile
uint16_t
jiffies
;
void
init_wdt
();
void
susp_wdt
();
...
...
projects/step-up/main.c
View file @
fbbdcc41
...
...
@@ -71,7 +71,6 @@ int main(void)
sei
();
#if 1
while
(
1
)
{
wdt_reset
();
sleep_mode
();
}
#endif
...
...
projects/step-up/wdt.c
View file @
fbbdcc41
...
...
@@ -6,7 +6,8 @@
void
init_wdt
()
{
wdt_enable
(
WDTO_1S
);
wdt_enable
(
WDTO_60MS
);
WDTCR
|=
_BV
(
WDIE
);
}
void
susp_wdt
()
...
...
@@ -14,3 +15,13 @@ void susp_wdt()
wdt_disable
();
}
ISR
(
WDT_vect
)
{
++
jiffies
;
if
(
jiffies
&
0x000F
)
{
need_battery_adc
=
1
;
// about every 1s
}
patterns_next_tick
();
timer_check_buttons
();
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment