Rev 1488 | Rev 1506 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1488 | Rev 1501 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | #include "twimaster.h" |
54 | #include "twimaster.h" |
55 | #include "main.h" |
55 | #include "main.h" |
56 | #include "timer0.h" |
56 | #include "timer0.h" |
Line 57... | Line 57... | ||
57 | 57 | ||
- | 58 | #define CAPACITY_UPDATE_INTERVAL 10 // 10 ms |
|
Line 58... | Line 59... | ||
58 | #define CAPACITY_UPDATE_INTERVAL 10 // 10 ms |
59 | #define OFFSET_CURRENT 4 // always calculate with a Current of 0,4A |
59 | 60 | ||
60 | // global varialbles |
61 | // global varialbles |
Line 101... | Line 102... | ||
101 | if(Current > CurrentOffset) Capacity.ActualCurrent = Current - CurrentOffset; |
102 | if(Current > CurrentOffset) Capacity.ActualCurrent = Current - CurrentOffset; |
102 | else Capacity.ActualCurrent = 0; |
103 | else Capacity.ActualCurrent = 0; |
103 | // update used capacity |
104 | // update used capacity |
104 | SubCounter += Capacity.ActualCurrent; |
105 | SubCounter += Capacity.ActualCurrent; |
Line -... | Line 106... | ||
- | 106 | ||
105 | 107 | /* |
|
106 | // 100mA * 1ms * CAPACITY_UPDATE_INTERVAL = 1 mA * 100 ms * CAPACITY_UPDATE_INTERVAL |
108 | // 100mA * 1ms * CAPACITY_UPDATE_INTERVAL = 1 mA * 100 ms * CAPACITY_UPDATE_INTERVAL |
107 | // = 1mA * 0.1s * CAPACITY_UPDATE_INTERVAL = 1mA * 1min / (600 / CAPACITY_UPDATE_INTERVAL) |
109 | // = 1mA * 0.1s * CAPACITY_UPDATE_INTERVAL = 1mA * 1min / (600 / CAPACITY_UPDATE_INTERVAL) |
108 | // = 1mAh / (36000 / CAPACITY_UPDATE_INTERVAL) |
110 | // = 1mAh / (36000 / CAPACITY_UPDATE_INTERVAL) |
109 | #define SUB_COUNTER_LIMIT (36000 / CAPACITY_UPDATE_INTERVAL) |
111 | #define SUB_COUNTER_LIMIT (36000 / CAPACITY_UPDATE_INTERVAL) |
110 | if(SubCounter > SUB_COUNTER_LIMIT) |
112 | if(SubCounter > SUB_COUNTER_LIMIT) |
111 | { |
113 | { |
112 | Capacity.UsedCapacity++; // we have one mAh more |
114 | Capacity.UsedCapacity++; // we have one mAh more |
113 | SubCounter -= SUB_COUNTER_LIMIT; // keep the remaining sub part |
115 | SubCounter -= SUB_COUNTER_LIMIT; // keep the remaining sub part |
- | 116 | } |
|
114 | } |
117 | */ |
115 | } |
118 | } |
116 | else // motors are stopped |
119 | else // motors are stopped |
117 | { // determine offsets of motor currents |
120 | { // determine offsets of motor currents |
118 | Capacity.ActualCurrent = 0; |
121 | Capacity.ActualCurrent = 0; |
119 | #define CURRENT_AVERAGE 256L // 256 * 10 ms = 2.56s average time |
122 | #define CURRENT_AVERAGE 256L // 256 * 10 ms = 2.56s average time |
120 | CurrentOffset = (unsigned short)(SumCurrentOffset/CURRENT_AVERAGE); |
123 | CurrentOffset = (unsigned short)(SumCurrentOffset/CURRENT_AVERAGE); |
121 | SumCurrentOffset -= CurrentOffset; |
124 | SumCurrentOffset -= CurrentOffset; |
122 | SumCurrentOffset += Current; |
125 | SumCurrentOffset += Current; |
- | 126 | } |
|
- | 127 | SubCounter += OFFSET_CURRENT; |
|
- | 128 | // 100mA * 1ms * CAPACITY_UPDATE_INTERVAL = 1 mA * 100 ms * CAPACITY_UPDATE_INTERVAL |
|
- | 129 | // = 1mA * 0.1s * CAPACITY_UPDATE_INTERVAL = 1mA * 1min / (600 / CAPACITY_UPDATE_INTERVAL) |
|
- | 130 | // = 1mAh / (36000 / CAPACITY_UPDATE_INTERVAL) |
|
- | 131 | #define SUB_COUNTER_LIMIT (36000 / CAPACITY_UPDATE_INTERVAL) |
|
- | 132 | if(SubCounter > SUB_COUNTER_LIMIT) |
|
- | 133 | { |
|
- | 134 | Capacity.UsedCapacity++; // we have one mAh more |
|
- | 135 | SubCounter -= SUB_COUNTER_LIMIT; // keep the remaining sub part |
|
123 | } |
136 | } |
124 | } // EOF check delay update timer |
137 | } // EOF check delay update timer |