Revision 355
working on getting I2C working. its not.
ConstantCharging.c | ||
---|---|---|
1 | 1 |
#include <avr/io.h> |
2 |
#include <avr/io.h> |
|
2 | 3 |
#include <avr/interrupt.h> |
3 | 4 |
#include <avr/sleep.h> |
5 |
#include "ring_buffer.h" |
|
4 | 6 |
#include "i2c.h" |
5 |
#include "ring_buffer.h" |
|
6 | 7 |
|
7 | 8 |
|
8 | 9 |
// for i2c_byte coming from charge board |
... | ... | |
22 | 23 |
#define SW0 PA6 |
23 | 24 |
#define HOMING_PIN PA7 |
24 | 25 |
|
25 |
//#define DEBUG 1 |
|
26 |
#define DEBUG 0 |
|
27 |
#define USE_I2C 1 |
|
26 | 28 |
|
29 |
|
|
27 | 30 |
#define MAX_T 300 |
28 | 31 |
#define MIN_T 730 |
29 | 32 |
//range is 0 to 45 C |
... | ... | |
244 | 247 |
|
245 | 248 |
void send_done(void) |
246 | 249 |
{ |
250 |
|
|
251 |
#if use_I2C |
|
247 | 252 |
char tempData; |
248 | 253 |
//Finished, leave |
249 | 254 |
tempData = 'F'; |
250 | 255 |
i2c_putpacket(0x01, &tempData, 1); |
256 |
#endif |
|
251 | 257 |
|
252 | 258 |
PORTA &= ~(_BV(debug_time)|_BV(debug_curr)|_BV(debug_volt)|_BV(debug_temp)|_BV(debug_12in)); |
253 | 259 |
|
... | ... | |
256 | 262 |
void setup(void) |
257 | 263 |
{ |
258 | 264 |
DDRA = _BV(PA3); |
259 |
#ifdef debug
|
|
265 |
#if DEBUG
|
|
260 | 266 |
//DDRA = (_BV(debug_time)|_BV(debug_curr)|_BV(debug_volt)|_BV(debug_temp)|_BV(debug_12in)); |
261 | 267 |
#endif |
262 | 268 |
PORTA = 0x00; |
... | ... | |
432 | 438 |
{ |
433 | 439 |
PORTB |= _BV(LED1); |
434 | 440 |
//curr = regulate_current(500); |
435 |
//+++curr = get_avg_current();
|
|
441 |
curr = get_avg_current(); |
|
436 | 442 |
|
437 | 443 |
if(status==0) |
438 | 444 |
{ |
439 | 445 |
status=1; |
446 |
#if use_I2C |
|
440 | 447 |
data[1]='a'; |
441 | 448 |
i2c_putpacket(0x01, data, 2); |
442 | 449 |
data[1]=I2C_MSG_BATTERY_CHARGING; |
443 | 450 |
i2c_putpacket(0x01, data, 2); |
451 |
#endif |
|
444 | 452 |
} |
445 | 453 |
|
446 | 454 |
/* Trickle Charge */ |
447 | 455 |
if(status==1) |
448 |
OCR1B = 200;
|
|
456 |
OCR1B = 128;
|
|
449 | 457 |
} |
450 | 458 |
/* NO CONTACT */ |
451 | 459 |
else |
... | ... | |
454 | 462 |
if(status==1) |
455 | 463 |
{ |
456 | 464 |
status=0; |
465 |
#if use_I2C |
|
457 | 466 |
data[1]=I2C_MSG_CONTACT_ERROR; |
458 | 467 |
i2c_putpacket(0x01, data, 2); |
468 |
#endif |
|
459 | 469 |
} |
460 | 470 |
else |
461 | 471 |
{ |
... | ... | |
529 | 539 |
|
530 | 540 |
temp=6666; |
531 | 541 |
} |
532 |
|
|
542 |
#if use_I2C |
|
533 | 543 |
data[1]=I2C_MSG_BATTERY_FULL; |
534 | 544 |
i2c_putpacket(0x01, data, 2); |
535 |
|
|
545 |
#endif |
|
536 | 546 |
} |
537 | 547 |
|
538 | 548 |
int main(void) |
... | ... | |
541 | 551 |
char tempData[5]; //For i2c communication |
542 | 552 |
|
543 | 553 |
setup(); |
554 |
|
|
555 |
#if use_I2C |
|
544 | 556 |
i2c_init(); |
557 |
i2c_putpacket(0x01,"I2C init'd on ARCHS\r\n", 21); |
|
558 |
#endif |
|
545 | 559 |
|
546 | 560 |
|
547 | 561 |
/*GIMSK = (_BV(PCIE0)); //enable PCINT interrupts |
... | ... | |
715 | 729 |
|
716 | 730 |
ISR(TIMER1_OVF_vect) |
717 | 731 |
{ |
718 |
wait(5); //wait a bit so we know the ouput gets set (which happens at timer = 0)
|
|
732 |
wait(2); //wait a bit so we know the ouput gets set (which happens at timer = 0)
|
|
719 | 733 |
|
720 |
TCNT1 = 156; // start out at 156. Now OCR1B - 156 = duty cycle |
|
734 |
TCNT1 = 0;//156; // start out at 156. Now OCR1B - 156 = duty cycle
|
|
721 | 735 |
} |
722 | 736 |
|
723 | 737 |
ISR(PCINT_vect){;} //so the interrupt doesnt go to the reset vector |
Also available in: Unified diff