made bigbar working with a delta of 10 Ampere

This commit is contained in:
Lucas Pleß 2013-06-15 07:01:38 +02:00
parent 92d0e1b3da
commit a64bc39662
3 changed files with 118 additions and 214 deletions

View File

@ -3,7 +3,10 @@
<component name="CppTools.Loader" reportImplicitCastToBool="false" reportNameReferencedOnce="false" warnedAboutFileOutOfSourceRoot="true" version="3" currentProject="$PROJECT_DIR$/displayboard/Makefile" additionalPreprocessorDefs="" compilerSelect="GCC" javaIncludes="false">
<system-include-dir path="/usr/lib/avr/include" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true">
<component name="FrameworkDetectionExcludesConfiguration">
<file url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="Cpp SDK" project-jdk-type="CppSdk">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

File diff suppressed because one or more lines are too long

View File

@ -31,14 +31,33 @@ unsigned char data_count = 0;
unsigned char data_in[BUFSIZE];
char command_in[BUFSIZE];
const uint8_t digit_translate[10] = {
const uint8_t segment_translate[10] = {
63, 6, 91, 79, 102, 109, 125, 7, 127, 111
};
const uint8_t leddigit_translate[9] = {
const uint8_t smallbar_translate[9] = {
0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff
};
const uint8_t bigbar_translate[15][2] = {
{ 0x00, 0xc0},
{ 0x00, 0x60},
{ 0x00, 0x30},
{ 0x00, 0x18},
{ 0x00, 0x0c},
{ 0x00, 0x06},
{ 0x00, 0x03},
{ 0x01, 0x01},
{ 0x03, 0x00},
{ 0x06, 0x00},
{ 0x0c, 0x00},
{ 0x18, 0x00},
{ 0x30, 0x00},
{ 0x60, 0x00},
{ 0xc0, 0x00}
};
static void timer_init(void) {
// clock is 8MHz
@ -72,11 +91,11 @@ static void print_sevenseg(uint8_t display, uint16_t value) {
if(display == 0) {
for(uint8_t i = 0; i< 3; i++) {
digitbuffer[i] = digit_translate[d[i]];
digitbuffer[i] = segment_translate[d[i]];
}
} else {
for(uint8_t i = 0; i< 3; i++) {
digitbuffer[i+3] = digit_translate[d[i]];
digitbuffer[i+3] = segment_translate[d[i]];
}
}
}
@ -87,52 +106,55 @@ static void print_bar(uint8_t display, uint16_t value, uint16_t max) {
x = (uint16_t)( (value / temp) * 8.0);
if(x > 8) x = 8;
x%=8;
switch(display) {
case LEDS_LOAD:
leddigitbuffer[2] = leddigit_translate[x];
leddigitbuffer[2] = smallbar_translate[x];
break;
case LEDS_GEN:
leddigitbuffer[3] = leddigit_translate[x];
leddigitbuffer[3] = smallbar_translate[x];
break;
}
}
static void print_bar_bottom(uint16_t curin, uint16_t curout) {
static void print_bar_bottom(uint16_t in, uint16_t out, uint16_t max) {
uint16_t x;
float temp = max;
/*
uart_puts("in= ");
uart_print_uint16(in);
uart_puts(" out= ");
uart_print_uint16(out);
uart_puts(" max= ");
uart_print_uint16(max);*/
if(out == in) {
leddigitbuffer[0] = bigbar_translate[7][0];
leddigitbuffer[1] = bigbar_translate[7][1];
return;
} else if( out > in ) {
x = (uint16_t)( ((out - in) / temp) * 8.0);
x = x+8;
} else {
x = (uint16_t)( ((in - out) / temp) * 8.0);
x = 7-x;
}
}
if(x > 14) x = 14;
if(x < 0) x = 0;
#ifdef DEBUG
void pretty_print_all_values(void) {
uart_puts_P("Voltage: ");
uart_print_uint16(voltage);
uart_puts_P("mV\r\n");
uart_puts_P("Load: ");
uart_print_uint16(current_out);
uart_puts_P("mA ");
uart_print_uint16( power_load);
uart_puts_P("W\r\n");
uart_puts_P("Generator: ");
uart_print_uint16(current_in);
uart_puts_P("mA ");
uart_print_uint16( power_gen);
uart_puts_P("W\r\n");
uart_puts_P("switches (load, dump, gen): ");
uart_putc(48 + loadsw);
uart_putc(',');
uart_putc(48 + dumpsw);
uart_putc(',');
uart_putc(48 + gensw);
/* uart_puts_P(" x= ");
uart_print_uint16(x);
uart_puts_P("\r\n");
*/
leddigitbuffer[0] = bigbar_translate[x][0];
leddigitbuffer[1] = bigbar_translate[x][1];
}
#endif
void process_command() {
if(strstr(command_in,"A") != NULL) {
@ -150,21 +172,9 @@ void process_command() {
// remove first (B is ignored by atoi)
start++;
#ifdef DEBUG
uart_puts_P("from start: ");
uart_puts(start);
uart_puts_P("\r\n");
#endif
token = strtok(start, ",");
while( token ) {
#ifdef DEBUG
uart_puts_P("token= ");
uart_puts(token);
uart_puts_P("\r\n");
#endif
switch(tokencounter) {
case 0:
voltage = atoi(token);
@ -198,10 +208,6 @@ void process_command() {
tokencounter++;
token = strtok(NULL, ",");
}
#ifdef DEBUG
pretty_print_all_values();
#endif
}
}
@ -225,12 +231,50 @@ static void work_uart(){
}
static void demo_display(void) {
for(uint8_t i = 0; i< 16;i++) {
leddigitbuffer[0] = bigbar_translate[i][0];
leddigitbuffer[1] = bigbar_translate[i][1];
wait(5);
}
for(uint8_t i = 0; i< 9;i++) {
leddigitbuffer[2] = smallbar_translate[i];
wait(5);
}
for(uint8_t i = 0; i< 9;i++) {
leddigitbuffer[3] = smallbar_translate[i];
wait(5);
}
for(uint8_t j = 0; j< 3;j++) {
for(uint8_t i = 0; i< 6; i++) {
digitbuffer[i] = 0xff;
}
wait(20);
for(uint8_t i = 0; i< 6; i++) {
digitbuffer[i] = 0x00;
}
wait(20);
}
for(uint8_t i = 0; i< 3;i++) {
leddigitbuffer[i] = 0x00;
}
}
int main(void) {
ports_init();
timer_init();
uart_init(UART_BAUD_SELECT(19200,F_CPU));
memset(data_in, 0, BUFSIZE);
//demo_display();
while(1) {
work_uart();
@ -244,6 +288,8 @@ int main(void) {
print_bar(LEDS_GEN, current_in, CURRENT_MAX);
print_bar(LEDS_LOAD, current_out, CURRENT_MAX);
print_bar_bottom(current_in, current_out, 10000);
syscounter = 0;
}
}