Revision 266
PWM hack works in that it increases frequency. I2C breaks everything. Added robot debug code which will just print everything it gets from i2c... hopefully
ConstantCharging.c | ||
---|---|---|
22 | 22 |
#define SW0 PA6 |
23 | 23 |
#define HOMING_PIN PA7 |
24 | 24 |
|
25 |
#define DEBUG 0
|
|
25 |
//#define DEBUG 1
|
|
26 | 26 |
|
27 | 27 |
#define MAX_T 300 |
28 | 28 |
#define MIN_T 730 |
... | ... | |
270 | 270 |
TIMSK = (_BV(TOIE0)); //enable overflow interrupts |
271 | 271 |
|
272 | 272 |
TCCR1A = (_BV(COM1B1)|_BV(PWM1B)|_BV(COM1A1)|_BV(PWM1A)); //clear timer 1 on compare, set at 0x00. Fast PWM mode |
273 |
TCCR1B |= _BV(CS12)|_BV(CS10); //leave timer on and set compare to 0 to make output off
|
|
273 |
TCCR1B |= _BV(CS10); //leave timer on and set compare to 0 to make output off |
|
274 | 274 |
|
275 | 275 |
//hack stuff so it will run in continuous mode |
276 | 276 |
TIMSK |= _BV(TOIE1); //enable overflow interrupt for timer 1 |
... | ... | |
395 | 395 |
int curr = 0; |
396 | 396 |
int meas_count = 0; |
397 | 397 |
int mod=0; |
398 |
sei(); |
|
399 | 398 |
OCR1B = 0; |
400 | 399 |
|
400 |
PORTB &= ~(_BV(LED1)|_BV(LED2)); |
|
401 |
|
|
402 |
|
|
401 | 403 |
while(status!=2) |
402 | 404 |
{ |
403 | 405 |
mod=abs_time%4; |
404 | 406 |
|
407 |
PORTB ^= _BV(LED2); |
|
408 |
|
|
405 | 409 |
if(supply_voltage()) |
406 | 410 |
while(abs_time%4==mod); |
407 | 411 |
|
408 | 412 |
/* TIME TERMINATION */ |
409 |
if(abs_time>500) //12000=25 minutes
|
|
413 |
if(abs_time>12000) //12000=25 minutes
|
|
410 | 414 |
{ |
411 | 415 |
//SEND_DONE |
412 | 416 |
OCR1B=0; |
... | ... | |
426 | 430 |
/* CONTACT */ |
427 | 431 |
if(supply_voltage()) |
428 | 432 |
{ |
433 |
PORTB |= _BV(LED1); |
|
429 | 434 |
//curr = regulate_current(500); |
430 |
curr = get_avg_current(); |
|
435 |
//+++curr = get_avg_current();
|
|
431 | 436 |
|
432 | 437 |
if(status==0) |
433 | 438 |
{ |
... | ... | |
445 | 450 |
/* NO CONTACT */ |
446 | 451 |
else |
447 | 452 |
{ |
453 |
PORTB &= ~_BV(LED1); |
|
448 | 454 |
if(status==1) |
449 | 455 |
{ |
450 | 456 |
status=0; |
... | ... | |
453 | 459 |
} |
454 | 460 |
else |
455 | 461 |
{ |
456 |
get_delay(); //reject the first reading
|
|
462 |
/*get_delay(); //reject the first reading //homing import stuff, uncomment this!!!!!!
|
|
457 | 463 |
data[0]=I2C_MSG_HOMING; |
458 | 464 |
data[1]=get_delay(); |
459 |
i2c_putpacket(0x01, data, 2); |
|
465 |
i2c_putpacket(0x01, data, 2);*/
|
|
460 | 466 |
|
461 | 467 |
data[0]='D'; |
462 | 468 |
} |
... | ... | |
533 | 539 |
{ |
534 | 540 |
new_second=0; |
535 | 541 |
char tempData[5]; //For i2c communication |
536 |
//test_board(); |
|
537 | 542 |
|
538 | 543 |
setup(); |
539 | 544 |
i2c_init(); |
... | ... | |
710 | 715 |
|
711 | 716 |
ISR(TIMER1_OVF_vect) |
712 | 717 |
{ |
713 |
delay_ms(1); //wait a clock cycle so we know the ouput gets set (which happens at timer = 0)
|
|
718 |
wait(5); //wait a bit so we know the ouput gets set (which happens at timer = 0)
|
|
714 | 719 |
|
715 | 720 |
TCNT1 = 156; // start out at 156. Now OCR1B - 156 = duty cycle |
716 | 721 |
} |
Also available in: Unified diff