-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bat_Capacity_test_simple.ino
67 lines (41 loc) · 1.08 KB
/
Bat_Capacity_test_simple.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Very simple Arduino Lithium-ion battery capacity tester
// from electronicsblog.net
// modified by k3ntinhu 10 Jan 2017
#define LED 13
#define resistor 6.9
float capacity=0, value,voltage,current, time=0;
void measure (void) {
value= analogRead(0);
voltage=value/1024*5.0;
current = voltage/resistor;
capacity=capacity+current/3600;
time++;
Serial.print("Voltage= ");
Serial.print(voltage);
Serial.print("V Current= ");
Serial.print(current);
Serial.print("A Capacity= ");
Serial.print(capacity);
Serial.print("Ah ");
Serial.print("Discharging time= ");
Serial.print(time);
Serial.print("s ");
Serial.print("\n");
}
boolean x=false;
ISR(TIMER1_OVF_vect) {
TCNT1=0x0BDC;
x=!x;
measure();
}
void setup() {
pinMode(LED, OUTPUT);
TIMSK1=0x01; // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0x0BDC; // set initial value to remove time error (16bit counter register)
TCCR1B = 0x04; // start timer/ set clock
Serial.begin(256000);
};
void loop () {
digitalWrite(LED, x);
};