diff --git a/Makefile b/Makefile index d594a6d..1ef4029 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PRG = lipo-charger OBJ = lipo-charger.o -MCU_TARGET = atmega8 +MCU_TARGET = attiny24 OPTIMIZE = -Os DEFS = @@ -47,5 +47,5 @@ bin: $(PRG).bin $(OBJCOPY) -j .text -j .data -O binary $< $@ install: text - uisp -dprog=avr910 -dserial=/dev/ttyS0 -dspeed=115200 -dpart=M8 --erase --upload if=$(PRG).hex -# avrdude -p m8 -c butterfly -b 19200 -P /dev/ttyUSB0 -u -e -U flash:w:$(PRG).hex +# uisp -dprog=avr910 -dserial=/dev/ttyS0 -dspeed=115200 -dpart=M8 --erase --upload if=$(PRG).hex + avrdude -p t24 -c butterfly -b 115200 -P /dev/ttyUSB0 -u -e -U flash:w:$(PRG).hex diff --git a/lipo-charger.c b/lipo-charger.c index e34a427..816f398 100644 --- a/lipo-charger.c +++ b/lipo-charger.c @@ -22,37 +22,21 @@ #define F_CPU 8000000 #include -#include +#define ADC_REF PORTA0 +#define ADC_U PORTA1 +#define ADC_IM PORTA2 +#define ADC_IP PORTA3 +#define SUMMER PORTA7 -#define BAUDRATE 19200 -#define UART_CALC_BAUDRATE(baudRate) ((uint32_t)(F_CPU) / ((uint32_t)(baudRate)*16) -1) +#define LEDRT PORTB0 +#define LEDGN PORTB1 +#define PWM PORTB2 -/* - * LCD: - * - CS Chip Select - * - RS Register Select - * - RW Read/Write - */ -#define RS PORTB6 -#define CS PORTB7 -#define RW PORTD3 -#define LCD_D4 PORTD4 -#define LCD_D5 PORTD5 -#define LCD_D6 PORTD6 -#define LCD_D7 PORTD7 -#define LCD_DATA_MASK ((1< 2V; 15mV -> 2.5mV/bit), ref 2.56V */ +#define CH_U ((1< 2V; 15mV -> 2.5mV/bit) - * - CH1 - current with (1A -> 1000mV; 2.5mA -> 2.5mV/bit) - * - PWM - high-active output to buckconverter - */ -#define CH0 PORTC0 -#define CH1 PORTC1 -#define PWM PORTB1 - -#define NOP asm volatile ("nop") +/* ADC_IP vs ADC_IM: current sense (1A -> 100mV; ??mA -> ?mV/bit), gain x20, ref 5V */ +#define CH_I ((0<> 4); - PORTB &= ~(1< 0x00) pwm--; - OCR1A = pwm; - TCCR1A |= (1< 9V is detected (lipo connected) */ if (voltage > VOLTAGE_CONNECT) mode = MOD_CHARGING; + break; case MOD_CHARGING: + /* current limit */ + if (voltage < (VOLTAGE_CHARGE -50)) { + /* green on, red fast blinking */ + if (led_timer & 0x80) + PORTB &= ~((1< 12.45V and current < 200mA */ if (voltage >= VOLTAGE_CHARGE && current < CURRENT_READY) mode = MOD_READY; break; case MOD_READY: + /* green on, red flashing */ + if (led_timer < 0x3F) + PORTB &= ~((1<>8) & 0xFF; - UBRRL = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); + /* analog inputs */ + DIDR0 = (1<