Revision 766
added I term to current control, had weird issues with battery #4 where the current reading dops down to 26 for some reason. After this happens, unloaded voltage on bat (through multimeter) reads >6, even though it seemed discharged before. I am doubting it was fully discharged, maybe the 5 minutes actually forced too much current in?
Charging.c | ||
---|---|---|
84 | 84 |
//same for DV |
85 | 85 |
volatile uint8_t last_DV = 0; |
86 | 86 |
|
87 |
uint16_t tot_err; |
|
88 |
uint8_t last_neg=0; |
|
89 |
|
|
87 | 90 |
#define FAST_CHARGE 1 |
88 | 91 |
#define TRICKLE_CHARGE 2 |
89 | 92 |
|
... | ... | |
310 | 313 |
|
311 | 314 |
|
312 | 315 |
//cool control law stuff |
316 |
|
|
317 |
//P: |
|
313 | 318 |
diff=i-curr; |
314 | 319 |
|
315 | 320 |
//OCR1B = diff/4 + curr/4; //K*Ierr + Kguess |
316 | 321 |
newcurr += diff/4; |
317 | 322 |
|
318 |
if(newcurr>255){ |
|
323 |
|
|
324 |
//I: |
|
325 |
tot_err += diff; |
|
326 |
|
|
327 |
newcurr += tot_err/2; |
|
328 |
|
|
329 |
//sum: |
|
330 |
|
|
331 |
if(newcurr>255){ |
|
319 | 332 |
OCR1B = 255; |
333 |
last_neg=0; |
|
320 | 334 |
}else if(newcurr>0){ |
321 | 335 |
OCR1B = newcurr; |
336 |
last_neg=0; |
|
322 | 337 |
}else { //negative |
323 |
OCR1B = 1; |
|
338 |
if((++last_neg)==3) |
|
339 |
OCR1B = 1; |
|
340 |
//else, no change to OCR |
|
341 |
|
|
324 | 342 |
} |
325 | 343 |
|
326 | 344 |
|
... | ... | |
411 | 429 |
else |
412 | 430 |
PORTA &= ~_BV(PA7); |
413 | 431 |
} |
414 |
|
|
415 | 432 |
|
433 |
|
|
434 |
|
|
416 | 435 |
void test_board(void) |
417 | 436 |
{ |
418 | 437 |
setup(); |
... | ... | |
472 | 491 |
curr=6666; |
473 | 492 |
|
474 | 493 |
mod=abs_time%4; |
475 |
//while(abs_time%4==mod)
|
|
476 |
{ |
|
494 |
while(abs_time%4==mod);
|
|
495 |
//{
|
|
477 | 496 |
volt = get_avg_voltage(); |
478 |
} |
|
497 |
//}
|
|
479 | 498 |
|
480 | 499 |
tempData[0] = 'V'; |
481 | 500 |
tempData[1] = volt>>8; |
... | ... | |
485 | 504 |
volt=6666; |
486 | 505 |
|
487 | 506 |
mod=abs_time%4; |
488 |
//while(abs_time%4==mod)
|
|
489 |
{ |
|
507 |
while(abs_time%4==mod);
|
|
508 |
//{
|
|
490 | 509 |
temp = get_avg_temperature(); |
491 | 510 |
|
492 |
} |
|
511 |
//}
|
|
493 | 512 |
|
494 | 513 |
tempData[0] = 'T'; |
495 | 514 |
tempData[1] = temp>>8; |
... | ... | |
562 | 581 |
|
563 | 582 |
int main(void) |
564 | 583 |
{ |
584 |
tot_err=0; |
|
565 | 585 |
test_board(); |
566 | 586 |
new_second=0; |
567 | 587 |
char tempData[5]; //For i2c communication |
Also available in: Unified diff