|
@@ -19,6 +19,7 @@ volatile unsigned char tick; // incremented every 100ms
|
|
|
unsigned char getkey(void){
|
|
|
static unsigned char old;
|
|
|
unsigned char key;
|
|
|
+ static unsigned char counter;
|
|
|
DDRA = 0;
|
|
|
PORTA = 0xff;
|
|
|
DDRC |= _BV(PC7);
|
|
@@ -27,7 +28,22 @@ unsigned char getkey(void){
|
|
|
DDRC &= ~_BV(PC7);
|
|
|
PORTA = 0;
|
|
|
DDRA = 0xff;
|
|
|
- if(key == old) return 0;
|
|
|
+ if(key == 0)
|
|
|
+ counter = 0;
|
|
|
+ if(key == old){
|
|
|
+ switch(counter){
|
|
|
+ default:
|
|
|
+ counter++;
|
|
|
+ return 0;
|
|
|
+ case 5:
|
|
|
+ counter++;
|
|
|
+ break;
|
|
|
+ case 8:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ counter = 0;
|
|
|
+ }
|
|
|
old = key;
|
|
|
return key;
|
|
|
}
|
|
@@ -186,9 +202,9 @@ void main(void){
|
|
|
|
|
|
eeprom_read_block(&settings, &eep_settings, sizeof(struct settings));
|
|
|
|
|
|
- OCR2A = 100; // 100µs
|
|
|
+ OCR2A = (125-1); // 1ms
|
|
|
TCCR2A = _BV(WGM21);
|
|
|
- TCCR2B = _BV(CS21);
|
|
|
+ TCCR2B = _BV(CS22);
|
|
|
TIMSK2 = _BV(OCIE2A);
|
|
|
sei();
|
|
|
|
|
@@ -257,13 +273,13 @@ void main(void){
|
|
|
if(mode != MODE_STOP)
|
|
|
break;
|
|
|
if(volt_set > 0)
|
|
|
- volt_set -= 1;
|
|
|
+ volt_set -= 5;
|
|
|
break;
|
|
|
case 5:
|
|
|
if(mode != MODE_STOP)
|
|
|
break;
|
|
|
if(disch_volt_set > 0)
|
|
|
- disch_volt_set -= 1;
|
|
|
+ disch_volt_set -= 5;
|
|
|
break;
|
|
|
case 6:
|
|
|
if(mode != MODE_STOP)
|
|
@@ -279,13 +295,13 @@ void main(void){
|
|
|
if(mode != MODE_STOP)
|
|
|
break;
|
|
|
if(volt_set < 2000) // 20V
|
|
|
- volt_set += 1;
|
|
|
+ volt_set += 5;
|
|
|
break;
|
|
|
case 5:
|
|
|
if(mode != MODE_STOP)
|
|
|
break;
|
|
|
if(disch_volt_set < 2000) // 20V
|
|
|
- disch_volt_set += 1;
|
|
|
+ disch_volt_set += 5;
|
|
|
break;
|
|
|
case 6:
|
|
|
if(mode != MODE_STOP)
|
|
@@ -330,8 +346,8 @@ void main(void){
|
|
|
if(tick){
|
|
|
cli();
|
|
|
if(mode != MODE_STOP){
|
|
|
- charge_counter += meas[MEAS_CURR] * (float)tick / 10.0 / 0.1e-6;
|
|
|
- energy_counter += meas[MEAS_CURR] * meas[MEAS_VOLT] * (float)tick / 10.0 / 10e-6;
|
|
|
+ charge_counter += meas[MEAS_CURR] * (float)tick / (float)(10.0 * 0.1e-6);
|
|
|
+ energy_counter += meas[MEAS_CURR] * meas[MEAS_VOLT] * (float)tick / (float)(10.0 * 10e-6);
|
|
|
time_counter += tick;
|
|
|
}
|
|
|
tick = 0;
|
|
@@ -353,9 +369,9 @@ void main(void){
|
|
|
putchar('W');
|
|
|
clearline();
|
|
|
cursor(0,9);
|
|
|
- disp_num(charge_counter * 0.1e-6 * 10000 / 3600.0, 4);
|
|
|
+ disp_num((float)charge_counter * (float)(0.1e-6 * 10000.0 / 3600.0), 4);
|
|
|
puttext_P(PSTR("Ah "));
|
|
|
- disp_num(energy_counter * 10e-6 * 10000 / 3600.0, 4);
|
|
|
+ disp_num((float)energy_counter * (float)(10e-6 * 10000.0 / 3600.0), 4);
|
|
|
puttext_P(PSTR("Wh "));
|
|
|
disp_num(time_counter, 1);
|
|
|
puttext_P(PSTR("s"));
|
|
@@ -364,19 +380,11 @@ void main(void){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-ISR(TIMER2_COMPA_vect){ // 100µs
|
|
|
- static unsigned char pre;
|
|
|
-
|
|
|
- if(++pre < 10)
|
|
|
- return;
|
|
|
- pre = 0;
|
|
|
-
|
|
|
- // 1ms
|
|
|
-
|
|
|
+ISR(TIMER2_COMPA_vect){ // 1ms
|
|
|
unsigned int *volatile ctimer;
|
|
|
unsigned char i;
|
|
|
|
|
|
- for(i=0; i<sizeof(timers)/sizeof(unsigned int); i++){
|
|
|
+ for(i=0; i<sizeof(timers)/sizeof(unsigned int); i++){ // decrement every variable from timers struct unless it's already zero
|
|
|
ctimer = ((unsigned int *)&timers) + i;
|
|
|
if(*ctimer)
|
|
|
(*ctimer)--;
|