Compare commits

..

No commits in common. "a39605248760a1acdb6850ef9e7f289bee7cb6fd" and "0e5e87af7c17effdabda33c768167019aa1fa430" have entirely different histories.

4 changed files with 5 additions and 35 deletions

View File

@ -33,14 +33,15 @@ uint8_t batmon_proc()
if (ADCSRA & (1 << ADIF)) { if (ADCSRA & (1 << ADIF)) {
sum += ADCH; sum += ADCH;
if (!(++cnt)) { if (!(cnt++)) {
vbat = sum >> 8; vbat = sum >> 8;
sum = 0; sum = 0;
if (vbat < BAT_THRES_POWER_OFF)
return 1;
} }
vbat = ADCH;
ADCSRA &= ~(1 << ADIF); ADCSRA &= ~(1 << ADIF);
ADCSRA |= (1 << ADSC); // TODO: I want this to work off TIMER0 ADCSRA |= (1 << ADSC); // TODO: I want this to work off TIMER0
if (vbat < BAT_THRES_POWER_OFF)
return 1;
} }
return 0; return 0;
} }
@ -49,28 +50,3 @@ inline uint8_t batmon_get_voltage()
{ {
return vbat; return vbat;
} }
static uint8_t batmon_get_voltage_sync()
{
uint16_t sum = 0;
uint8_t cnt = 255;
ADCSRA |= (1 << ADSC);
do {
if (ADCSRA & (1 << ADIF)) {
sum += ADCH;
ADCSRA &= ~(1 << ADIF);
ADCSRA |= (1 << ADSC);
cnt--;
}
} while (cnt);
return (sum >> 8);
}
// Note: Call batmon_init() after using this function before using batmon_proc() again
inline uint8_t batmon_ok_to_boot()
{
return (batmon_get_voltage_sync() > BAT_THRES_POWER_ON);
}

View File

@ -12,6 +12,5 @@
void batmon_init(); void batmon_init();
uint8_t batmon_get_voltage(); uint8_t batmon_get_voltage();
uint8_t batmon_proc(); uint8_t batmon_proc();
uint8_t batmon_ok_to_boot();
#endif // BATMON_H #endif // BATMON_H

View File

@ -88,7 +88,6 @@ int main()
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
WDTCSR = (1 << WDCE); WDTCSR = (1 << WDCE);
cli(); cli();
_delay_ms(25);
suspend(); suspend();

View File

@ -4,7 +4,6 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "pm.h" #include "pm.h"
#include "batmon.h"
static void disable_periphery() static void disable_periphery()
{ {
@ -59,10 +58,7 @@ void reset()
char* post() char* post()
{ {
// TODO: Implement battery voltage check
_delay_ms(500); _delay_ms(500);
if (!batmon_ok_to_boot())
return PSTR("Low battery.");
return 0; return 0;
} }