From 2fbf53d7f5546fa467c84c129d49e3a76f5db9fd Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 4 Apr 2012 18:37:20 +0200 Subject: o Updating firmware for Rev B. --- firmware/VirtualSerial.c | 88 +++++++++++++++++++++++++++++++++++++----------- firmware/makefile | 4 +-- notes.txt | 10 ++++++ 3 files changed, 80 insertions(+), 22 deletions(-) diff --git a/firmware/VirtualSerial.c b/firmware/VirtualSerial.c index 05bff31..a88f473 100644 --- a/firmware/VirtualSerial.c +++ b/firmware/VirtualSerial.c @@ -84,10 +84,35 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = */ static FILE USBSerialStream; -#define LM74_SIO PD4 -#define LM74_SCL PD5 -#define LM74_CS PD3 -#define LM74_DBG PD6 +#define BOARD_REV 2 + +#if (BOARD_REV == 1) + #define LM74_SIO PD4 + #define LM74_SIO_PIN PIND + #define LM74_SIO_DDR DDRD + #define LM74_SCL PD5 + #define LM74_SCL_PORT PORTD + #define LM74_SCL_DDR DDRD + #define LM74_CS PD3 + #define LM74_CS_PORT PORTD + #define LM74_CS_DDR DDRD + + #define LM74_DBG PD6 + #define LM74_DBG_PORT PORTD + #define LM74_DBG_DDR DDRD +#elif (BOARD_REV == 2) + #define LM74_SIO PD0 + #define LM74_SIO_PIN PIND + #define LM74_SIO_DDR DDRD + #define LM74_SCL PC2 + #define LM74_SCL_PORT PORTC + #define LM74_SCL_DDR DDRC + #define LM74_CS PD1 + #define LM74_CS_PORT PORTD + #define LM74_CS_DDR DDRD +#else + #error BOARD_REV has to be defined as 'A' or 'B'. +#endif /** * Data is clocked out on the falling edge of the serial clock (SC), while data is clocked in on the rising edge of SC. @@ -96,15 +121,15 @@ static int lm74_transaction(double *out) { uint16_t tmp = 0; - PORTD &= ~_BV(LM74_CS); + LM74_CS_PORT &= ~_BV(LM74_CS); for(int i = 0; i < 16; i++) { tmp <<= 1; - PORTD |= _BV(LM74_SCL); - if (PIND & (1 << LM74_SIO)) + LM74_SCL_PORT |= _BV(LM74_SCL); + if (LM74_SIO_PIN & (1 << LM74_SIO)) tmp |= 1; - PORTD &= ~_BV(LM74_SCL); + LM74_SCL_PORT &= ~_BV(LM74_SCL); } - PORTD |= _BV(LM74_CS); + LM74_CS_PORT |= _BV(LM74_CS); /* Replay the data for debugging PORTD &= ~_BV(LM74_CS); @@ -135,12 +160,18 @@ static int lm74_transaction(double *out) static void lm74_init(void) { - PORTD |= (1 << LM74_SCL) | (1 << LM74_CS); - PORTD |= (1 << LM74_DBG); + LM74_SCL_PORT |= (1 << LM74_SCL); + LM74_SCL_DDR |= (1 << LM74_SCL); - DDRD |= (1 << LM74_SCL) | (1 << LM74_CS); - DDRD |= (1 << LM74_DBG); - DDRD &= ~(1 << LM74_SIO); + LM74_CS_PORT |= (1 << LM74_CS); + LM74_CS_DDR |= (1 << LM74_CS); + + LM74_SIO_DDR &= ~(1 << LM74_SIO); + +#ifdef LM74_DBG_PORT + LM74_DBG_PORT |= (1 << LM74_DBG); + LM74_DBG_DDR |= (1 << LM74_DBG); +#endif } static void temp_timer_setup(void) @@ -158,22 +189,41 @@ static void temp_timer_setup(void) TIMSK1 = (1 << OCIE1A); } -/** Compressor - * +/** + * Compressor */ +static void compressor_init(void) +{ +#if (BOARD_REV == 1) + DDRB |= (1 << PB4) | (1 << PB0); + + PORTB |= 1 << PB4; +#elif (BOARD_REV == 2) + DDRC |= 1 << PC5; + PORTC |= 1 << PC5; +#endif +} + static void start_compressor(void) { compressor_running = true; +#if (BOARD_REV == 1) PORTB |= 1 << PB4; - PORTB |= 1 << PB0; +#elif (BOARD_REV == 2) + PORTC |= 1 << PC5; +#endif } static void stop_compressor(void) { compressor_running = false; +#if (BOARD_REV == 1) PORTB &= ~(1 << PB4); PORTB &= ~(1 << PB0); +#elif (BOARD_REV == 2) + PORTC &= ~(1 << PC5); +#endif } /** Main program entry point. This routine contains the overall program flow, including initial @@ -181,11 +231,9 @@ static void stop_compressor(void) */ int main(void) { - DDRB = 1 << PB0 | 1 << PB4 | 0 << PB5; - PORTB = 0 << PB0; - SetupHardware(); lm74_init(); + compressor_init(); target_temp = eeprom_read_float(&eeprom_target_temperature); diff --git a/firmware/makefile b/firmware/makefile index 5b5d12d..0e43fb1 100644 --- a/firmware/makefile +++ b/firmware/makefile @@ -514,8 +514,8 @@ gccversion : program: $(TARGET).hex $(TARGET).eep # $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) #avarice -w -f VirtualSerial.hex -P at90usb162 -2 -j usb -# avrdude -c avr109 -p usb162 -P /dev/ttyACM0 -U flash:w:VirtualSerial.hex - avrdude -c stk500 -p usb162 -P /dev/ttyUSB0 -U flash:w:VirtualSerial.hex + avrdude -c avr109 -p usb162 -P /dev/ttyACM0 -U flash:w:VirtualSerial.hex +# avrdude -c stk500 -p usb162 -P /dev/ttyUSB0 -U flash:w:VirtualSerial.hex reset: avarice -P at90usb162 -2 -j usb -R diff --git a/notes.txt b/notes.txt index b080193..61c388f 100644 --- a/notes.txt +++ b/notes.txt @@ -109,3 +109,13 @@ pcb: 5) open and print ps file +2012-04-04 + +Fuses has to be changed: + +- Run at 16MHz: Set clock divider to 1 +Change lfuse from 0x5e to 0xce + +- Enable bootloader: Set the BOOTRST bit +Change hfuse from factory default 0xd9 to 0xd8 + -- cgit v1.2.3