From: Jan Michel Date: Fri, 9 Jan 2015 23:22:54 +0000 (+0100) Subject: few updates, including second temp sensor X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=1423a2040585567ec4150a2c39db92a0a71ada59;p=avr.git few updates, including second temp sensor --- diff --git a/atmega32u4/cooler/cooler.c b/atmega32u4/cooler/cooler.c index df6d170..635f52e 100644 --- a/atmega32u4/cooler/cooler.c +++ b/atmega32u4/cooler/cooler.c @@ -17,27 +17,32 @@ // 16 bit color code: red -> 5 bit, green -> 6 bit, blue -> 5 bit #define TOP_BACKGROUND() lcd_set_background(0x03,0x04,0x05) #define BOTTOM_BACKGROUND() lcd_set_background(0x00,0x00,0x00) -#define FIRST_VALUE_FOREGROUND() lcd_set_foreground(0x1f,0x3f,0x0e);lcd_set_background(0x03,0x04,0x05) -#define SECOND_VALUE_FOREGROUND() lcd_set_foreground(0x0e,0x2e,0x1f);lcd_set_background(0x03,0x04,0x05) -#define THIRD_VALUE_FOREGROUND() lcd_set_foreground(31, 63/2 ,31/2);lcd_set_background(0x03,0x04,0x05) +#define FIRST_VALUE_FOREGROUND() lcd_set_color(&foreground,0x1f,0x3f,0x0e) +#define SECOND_VALUE_FOREGROUND() lcd_set_color(&foreground,0x0e,0x2e,0x1f) +#define THIRD_VALUE_FOREGROUND() lcd_set_color(&foreground,31, 63/2 ,31/2) #define FIRST_VALUE_BACKGROUND() lcd_set_background(0x1f,0x3f,0x0e) #define SECOND_VALUE_BACKGROUND() lcd_set_background(0x0e,0x2e,0x1f) -#define AXES_COLOR() lcd_set_foreground(0x1f,0x3f,0x1f); +#define AXES_COLOR() lcd_set_color(&foreground,0x1f,0x3f,0x1f) +#define MAINSENSOR 1 +#define SUPPSENSOR 0 + #define BUFFERSIZE 16 #define STORAGESIZE 300 const uint8_t lut[16] = {0,1,1,2,3,3,4,4,5,5,6,7,7,8,9,9}; uint8_t buffer[BUFFERSIZE]; uint8_t recvpointer = 0; int16_t values[2][STORAGESIZE]; -uint16_t valuepointer[2] = {0}; -int16_t lastvalues[2] = {0,0}; +uint16_t valuepointer[4] = {0}; +int16_t lastvalues[4] = {0,0}; volatile uint8_t second, lastsecond; uint8_t ids[NUMSENSORS][8]; -uint16_t temps[NUMSENSORS] = {-255}; +int16_t temps[NUMSENSORS] = {-255}; int16_t set_value = 12*16; uint8_t output_power_percent = 0; +color_t colors[4]; +color_t topback; volatile uint8_t keys_pressed = 0b00000000; @@ -46,21 +51,24 @@ volatile uint8_t keys_pressed = 0b00000000; #define MINY 100 #define MAXY 220 void draw(void) { - uint16_t c = MINX; - uint16_t p = valuepointer[0]; - FIRST_VALUE_FOREGROUND(); - lcd_set_background(0x00,0x00,0x00); lcd_set_page(0,239); lcd_set_column(0,319); + lcd_set_background(0x00,0x00,0x00); + uint16_t c = MINX; + uint16_t p = valuepointer[0]; do{ - uint16_t y = values[0][p]; - y = y*3; - y >>= 4; - y = 190-y; - lcd_set_pixel_col_xy(c+1,y,background); - lcd_set_pixel_col_xy(c+1,y+1,background); - lcd_set_pixel_col_xy(c,y,foreground); - lcd_set_pixel_col_xy(c,y+1,foreground); + for(uint8_t i = 0; i<=1; i++) { + if(i) SECOND_VALUE_FOREGROUND(); + else FIRST_VALUE_FOREGROUND(); + uint16_t y = values[i][p]; + y = y*3; + y >>= 4; + y = 190-y; + lcd_set_pixel_col_xy(c+1,y,background); + lcd_set_pixel_col_xy(c+1,y+1,background); + lcd_set_pixel_col_xy(c,y,foreground); + lcd_set_pixel_col_xy(c,y+1,foreground); + } p++; if(p>= STORAGESIZE) p = 0; }while(++c> 4; lcd_set_font(FONT_DIGITS_32,SPACING); - TOP_BACKGROUND(); - - if(place == 0) { - FIRST_VALUE_FOREGROUND(); - if(lastvalues[place]<=-160) { - if(val >-160) - lcd_set_area_xy(190,210,23,28); - } - else if (lastvalues[place]<0) { - if(val>0) - lcd_set_area_xy(220,240,23,28); - } - - if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=160)) - lcd_set_area_xy(210,246,8,39); - - FIRST_VALUE_BACKGROUND(); - if(neg) { - if(x>=10 && lastvalues[place]>-160) - lcd_set_area_xy(190,210,23,28); - else if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=0)) - lcd_set_area_xy(220,240,23,28); - } - if(x>=10) lcd_moveto_xy(8,220); - else lcd_moveto_xy(8,249); + lcd_use_background(topback); + + uint16_t left = 0; + uint16_t top = 0; + if (place == 0) {left = 190; top = 8; } + else if(place == 1) {left = 190; top = 48; } + else if(place == 2) {left = 33; top = 48; } + else if(place == 3) {left = 33; top = 8; } + + lcd_use_foreground(colors[place]); + if(lastvalues[place]<=-160) { + if(val >-160) + lcd_set_area_xy(left,left+20,top+15,top+20); } - else { - SECOND_VALUE_FOREGROUND(); - lcd_set_area_xy(190,210,63,68); - lcd_set_area_xy(210,246,48,79); - - SECOND_VALUE_BACKGROUND(); - if(neg) { - if(x>=10) lcd_set_area_xy(190,210,63,68); - else lcd_set_area_xy(220,240,63,68); - } - if(x>=10) lcd_moveto_xy(48,220); - else lcd_moveto_xy(48,249); + else if (lastvalues[place]<0) { + if(val>0) + lcd_set_area_xy(left+30,left+50,top+15,top+20); } - - TOP_BACKGROUND(); + + if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=160)) + lcd_set_area_xy(left+20,left+56,top,top+31); + + lcd_use_background(colors[place]); + if(neg) { + if(x>=10 && lastvalues[place]>-160) + lcd_set_area_xy(left,left+20,top+15,top+20); + else if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=0)) + lcd_set_area_xy(left+30,left+50,top+15,top+20); + } + if(x>=10) lcd_moveto_xy(top,left+30); + else lcd_moveto_xy(top,left+59); + + lcd_use_background(topback); lcd_put_int(x); - if(!place)lcd_moveto_xy(8,289); - else lcd_moveto_xy(48,289); + lcd_moveto_xy(top,left+99); lcd_putc(lut[y]+'0'); lastvalues[place] = val; @@ -297,7 +296,7 @@ void printAxes(void) { AXES_COLOR(); BOTTOM_BACKGROUND(); lcd_set_area_xy(20,319,100,220); - TOP_BACKGROUND(); + lcd_use_background(topback); lcd_set_font(FONT_PROP_16,NORMAL); lcd_putstr_xy_P(PSTR("-10"),216,0); lcd_putstr_xy_P(PSTR(" 30"),96,0); @@ -311,19 +310,31 @@ void printAxes(void) { lcd_putstr_xy_P(PSTR("minutes"),228,150); lcd_putstr_xy_P(PSTR("T"),160,10); - FIRST_VALUE_FOREGROUND(); + lcd_use_foreground(colors[0]); lcd_set_font(FONT_PROP_16,NORMAL); lcd_putstr_xy_P(PSTR("is"),8,190); lcd_set_font(FONT_DIGITS_32,SPACING); lcd_moveto_xy(8,278); lcd_putc('.'); - SECOND_VALUE_FOREGROUND(); - lcd_set_font(FONT_PROP_16,NORMAL); - lcd_putstr_xy_P(PSTR("set"),48,190); + + lcd_use_foreground(colors[1]); lcd_set_font(FONT_DIGITS_32,SPACING); lcd_moveto_xy(48,278); lcd_putc('.'); + lcd_use_foreground(colors[2]); + lcd_set_font(FONT_PROP_16,NORMAL); + lcd_putstr_xy_P(PSTR("power"),48,20); + lcd_set_font(FONT_PROP_16,DOUBLE_SIZE|SPACING); + lcd_putstr_xy_P(PSTR("%"),54,150); + + lcd_use_foreground(colors[3]); + lcd_set_font(FONT_PROP_16,NORMAL); + lcd_putstr_xy_P(PSTR("set"),8,33); + lcd_set_font(FONT_DIGITS_32,SPACING); + lcd_moveto_xy(8,121); + lcd_putc('.'); + } @@ -332,7 +343,7 @@ void new_set_value(int16_t value){ value = MAX(value,SET_VAL_LOWER); value = MIN(value,SET_VAL_UPPER); set_value = value; - showTemp(1,set_value); + showTemp(3,set_value); } // all constants in x/10 @@ -374,7 +385,7 @@ uint16_t pid_calculation(int16_t error) { void showPower(void){ #define POWER_XPOS 62 #define POWER_YPOS 48 - + TOP_BACKGROUND(); THIRD_VALUE_FOREGROUND(); if(output_power_percent <10){ lcd_set_area_xy(POWER_XPOS,POWER_XPOS+29*2,POWER_YPOS,POWER_YPOS+32); @@ -398,12 +409,19 @@ void uartReport(void){ uart_puts(" deg C\n\r"); uart_puts("Temperature: "); - uart_print_sign(temps[0]); - uart_print_number(abs(temps[0])/16,2); + uart_print_sign(temps[MAINSENSOR]); + uart_print_number(abs(temps[MAINSENSOR])/16,2); usb_serial_putchar('.'); - usb_serial_putchar('0'+lut[abs(temps[0])%16]); // print post comma + usb_serial_putchar('0'+lut[abs(temps[MAINSENSOR])%16]); // print post comma uart_puts(" deg C\n\r"); - + + uart_puts("2nd temp: "); + uart_print_sign(temps[SUPPSENSOR]); + uart_print_number(abs(temps[SUPPSENSOR])/16,2); + usb_serial_putchar('.'); + usb_serial_putchar('0'+lut[abs(temps[SUPPSENSOR])%16]); // print post comma + uart_puts(" deg C\n\r"); + uart_puts("PWM Output: "); uart_print_number(output_power_percent,3); uart_puts("%\n\r"); @@ -421,28 +439,23 @@ __attribute__((naked)) int main(void) { keys_init(); PWM_init(); + lcd_set_color(colors+0,0x1f,0x3f,0x0e); + lcd_set_color(colors+1,0x1f,0x3f,0x0e); + lcd_set_color(colors+2,0x1f,0x1f,0x0f); + lcd_set_color(colors+3,0x0e,0x2e,0x1f); + lcd_set_color(&topback,0x03,0x04,0x05); + lcd_command_1(LCD_MIRROR, LCD_BGR | LCD_FLIP_XY); lcd_command(LCD_ON); - TOP_BACKGROUND(); + lcd_use_background(topback); lcd_set_area_xy(0, 0x13F, 0, 0xEF); - lcd_set_foreground(0x1f,0x3f,0x1f); - lcd_set_font(FONT_PROP_16,DOUBLE_HEIGHT|SPACING); - lcd_putstr_xy_P(PSTR("Cooling Control"),10,30); printAxes(); + + new_set_value(12*16); - THIRD_VALUE_FOREGROUND(); - lcd_set_font(FONT_PROP_16,NORMAL); - lcd_putstr_xy_P(PSTR("power"),48,20); - lcd_set_font(FONT_PROP_16,DOUBLE_SIZE|SPACING); - lcd_putstr_xy_P(PSTR("%"),54,150); - - - - pushvalue(1,set_value); - while (1) { int n = usb_serial_getchar(); @@ -476,14 +489,15 @@ __attribute__((naked)) int main(void) { usb_serial_putchar(0x10); read_meas(); start_meas(); - pushvalue(0,temps[0]); + pushvalue(0,temps[MAINSENSOR]); + pushvalue(1,temps[SUPPSENSOR]); lastsecond = second; - if(temps[0] > 30*16){ // turn off peltier if temperature is off limits (>30 deg C) + if(temps[MAINSENSOR] > 30*16){ // turn off peltier if temperature is off limits (>30 deg C) set_PWM_output(0); output_power_percent = 0; } else { - uint16_t pid_output = pid_calculation( temps[0] - set_value ); + uint16_t pid_output = pid_calculation( temps[MAINSENSOR] - set_value ); set_PWM_output(pid_output); // let PID compute output output_power_percent = MIN(100,pid_output/10); // output power in percent (ignore the last 23 from 1023) } diff --git a/atmega32u4/cooler/lcdlib/lcd-color-graphic.c b/atmega32u4/cooler/lcdlib/lcd-color-graphic.c index c4be9fa..a3b1c52 100644 --- a/atmega32u4/cooler/lcdlib/lcd-color-graphic.c +++ b/atmega32u4/cooler/lcdlib/lcd-color-graphic.c @@ -75,6 +75,10 @@ inline void lcd_set_foreground(uint8_t r, uint8_t g, uint8_t b) { foreground.c1 = t>>8; foreground.c2 = t; } +inline void lcd_use_foreground(color_t color) { + foreground.c1 = color.c1; + foreground.c2 = color.c2; + } /****************************************************************************** @@ -85,7 +89,20 @@ inline void lcd_set_background(uint8_t r, uint8_t g, uint8_t b) { background.c1 = t>>8; background.c2 = t; } - +inline void lcd_use_background(color_t color) { + background.c1 = color.c1; + background.c2 = color.c2; + } + +/****************************************************************************** + * Stores the background color for later use + */ +inline void lcd_set_color(color_t* color, uint8_t r, uint8_t g, uint8_t b) { + uint16_t t = r<<11 | g<<5 | b; + color->c1 = t>>8; + color->c2 = t; + } + /****************************************************************************** * Sets the column range used for the next write operation diff --git a/atmega32u4/cooler/lcdlib/lcd-color-graphic.h b/atmega32u4/cooler/lcdlib/lcd-color-graphic.h index 351cf08..4b4000b 100644 --- a/atmega32u4/cooler/lcdlib/lcd-color-graphic.h +++ b/atmega32u4/cooler/lcdlib/lcd-color-graphic.h @@ -87,6 +87,9 @@ typedef struct { //Set the drawing and background colors void lcd_set_foreground(uint8_t r, uint8_t g, uint8_t b); void lcd_set_background(uint8_t r, uint8_t g, uint8_t b); + void lcd_set_color(color_t* color, uint8_t r, uint8_t g, uint8_t b); + void lcd_use_foreground(color_t color); + void lcd_use_background(color_t color); //set display area for next write accesses void lcd_set_page(uint16_t start, uint16_t end); diff --git a/atmega32u4/cooler/main.h b/atmega32u4/cooler/main.h index caf3c2a..ec5738c 100644 --- a/atmega32u4/cooler/main.h +++ b/atmega32u4/cooler/main.h @@ -23,7 +23,7 @@ #define NUMSENSORS 2 extern uint8_t ids[NUMSENSORS][8]; -extern uint16_t temps[NUMSENSORS]; +extern int16_t temps[NUMSENSORS]; #endif \ No newline at end of file