Changeset 10754 for firmware/FSC
- Timestamp:
- 05/19/11 09:34:57 (14 years ago)
- Location:
- firmware/FSC/usb_src
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/usb_src/FSC.c
r10245 r10754 8 8 #include "macros.h" 9 9 #include "interpol.h" 10 #include "w5100_spi_interface.h"10 //#include "w5100_spi_interface.h" 11 11 #include <avr/interrupt.h> 12 12 #include <avr/wdt.h> … … 28 28 void print_ad7719_nicely(); 29 29 void print_adc_nicely(); 30 30 void print_temp_nicely(); 31 31 // end of function definition: 32 32 //----------------------------------------------------------------------------- … … 54 54 #define TEMP_CHANNELS 64 55 55 #define CHANNEL_BITMAP 8 56 #define AD7719_READINGS_UNTIL_SETTLED 5// bei3:480ms56 #define AD7719_READINGS_UNTIL_SETTLED 3 // bei3:480ms 57 57 U32 ad7719_values[TEMP_CHANNELS]; 58 58 U08 ad7719_enables[CHANNEL_BITMAP]; … … 106 106 PORTB &= ~(1<<PB2); 107 107 108 ad7719_enables[0]=0x00; 109 ad7719_enables[1]=0x00; 110 ad7719_enables[2]=0x00; 111 ad7719_enables[3]=0x00; 112 ad7719_enables[4]=0x00; 113 ad7719_enables[5]=0x00; 114 ad7719_enables[6]=0x00; 115 ad7719_enables[7]=0x00; 108 116 for ( U08 i=0; i<CHANNEL_BITMAP; ++i ) { 109 ad7719_enables[i]=0x00;110 117 ad7719_channels_ready[i]=0; 111 } 112 ad7719_enables[0]=0x01; 118 } 119 ad7719_current_channel = increase_ad7719 (ad7719_current_channel); 120 113 121 for ( U08 i=0; i<V_BITMAP + I_BITMAP; ++i ) { 114 122 adc_enables[i]=0xFF; … … 343 351 // just wait until ADC is redy -- really bad code here! 344 352 } 345 353 //Start a new A/D Conversion 346 354 //temp = readandsendtemp(); 347 355 //adcword = getadc(); … … 905 913 break; 906 914 915 case 'T': 916 print_temp_nicely(); 917 break; 907 918 908 919 … … 999 1010 float value; 1000 1011 1001 usart_write_str((pU08)"\n printing measured resistance in kohms:\n");1002 1003 for (U08 i=0; i< TEMP_CHANNELS;++i) {1004 if (i%8 == 0) usart_write_char('\n');1005 1006 // print channel name:1007 usart_write_str((pU08)"R:"); //R for resistance1008 usart_write_char('A'+i/8); // Letters A,B,C,D,E,F,G,H1009 //usart_write_char(' ');1010 usart_write_U08(i%8+1,1); // Numbers 1...81011 usart_write_char(':');1012 1013 // check if this channel is enabled in the bitmap1014 if (ad7719_enables[i/8] & (1<<i%8))1015 {1016 value = (6.25 * 1.024 * ad7719_values[i]) / ((U32)1 << 25);1017 usart_write_float(value, 3,6);1018 //usart_write_U32(ad7719_values[i],8);1019 //usart_write_U32_hex(data); //data1020 usart_write_str((pU08)" ");1021 } else {1022 usart_write_str((pU08)" ");1023 }1024 //usart_write_char('\n');1025 }1012 usart_write_str((pU08)"\n printing measured resistance in kohms:\n"); 1013 1014 for (U08 i=0; i< TEMP_CHANNELS;++i) { 1015 if (i%8 == 0) usart_write_char('\n'); 1016 1017 // print channel name: 1018 usart_write_str((pU08)"R:"); //R for resistance 1019 usart_write_char('A'+i/8); // Letters A,B,C,D,E,F,G,H 1020 //usart_write_char(' '); 1021 usart_write_U08(i%8+1,1); // Numbers 1...8 1022 usart_write_char(':'); 1023 1024 // check if this channel is enabled in the bitmap 1025 if (ad7719_enables[i/8] & (1<<i%8)) 1026 { 1027 value = (6.25 * 1.024 * ad7719_values[i]) / ((U32)1 << 25); 1028 usart_write_float(value, 3,6); 1029 //usart_write_U32(ad7719_values[i],8); 1030 //usart_write_U32_hex(data); //data 1031 usart_write_str((pU08)" "); 1032 } else { 1033 usart_write_str((pU08)" "); 1034 } 1035 //usart_write_char('\n'); 1036 } 1026 1037 } 1027 1038 … … 1046 1057 usart_write_char('\n'); 1047 1058 } 1059 1060 1061 void print_temp_nicely() 1062 { 1063 float temp; 1064 1065 usart_write_str((pU08)"\n printing measured temperature in °C:\n"); 1066 1067 for (U08 i=0; i< TEMP_CHANNELS;++i) { 1068 if (i%8 == 0) usart_write_char('\n'); 1069 1070 // print channel name: 1071 usart_write_str((pU08)"T:"); //R for resistance 1072 usart_write_char('A'+i/8); // Letters A,B,C,D,E,F,G,H 1073 //usart_write_char(' '); 1074 usart_write_U08(i%8+1,1); // Numbers 1...8 1075 usart_write_char(':'); 1076 1077 // check if this channel is enabled in the bitmap 1078 if (ad7719_enables[i/8] & (1<<i%8)) 1079 { 1080 temp = calc_temp(ad7719_values[i]); 1081 usart_write_float(temp, 3,6); 1082 //usart_write_U32(ad7719_values[i],8); 1083 //usart_write_U32_hex(data); //data 1084 usart_write_str((pU08)" "); 1085 } else { 1086 usart_write_str((pU08)" "); 1087 } 1088 //usart_write_char('\n'); 1089 } 1090 } -
firmware/FSC/usb_src/interpol.c
r10102 r10754 7 7 //#include "application.h" 8 8 #include "num_conversion.h" 9 #include "math.h" 9 10 //----------------------------------------------------------------------------- 10 11 /* … … 302 303 return read_adc(); 303 304 } 305 306 307 float calc_temp(U32 adcword) 308 { 309 U8 temprange = 17; 310 311 float temp=NAN; 312 const U32 min = 0x404054; 313 const U32 max = 0x8CAF50; 314 const U32 s = 0x4C6F0; //(max-min)/16 = s(lice) 315 316 if (adcword >= (min + 8*s)) 317 { 318 if (adcword >= (min + 12*s)) 319 { 320 if (adcword >= (min + 14*s)) 321 { 322 if (adcword >= (min + 15*s)) 323 { 324 if (adcword < max) 325 { 326 temprange = 16; 327 } 328 } 329 else 330 { 331 temprange = 15; 332 } 333 } 334 else 335 { 336 if (adcword >= (min + 13*s)) 337 { 338 temprange = 14; 339 } 340 else 341 { 342 temprange = 13; 343 } 344 } 345 } 346 else 347 { 348 if (adcword >= (min + 10*s)) 349 { 350 if (adcword >= (min + 11*s)) 351 { 352 temprange = 12; 353 } 354 else 355 { 356 temprange = 11; 357 } 358 } 359 else 360 { 361 if (adcword >= (min + 9*s)) 362 { 363 temprange = 10; 364 } 365 else 366 { 367 temprange = 9; 368 } 369 } 370 } 371 } 372 else 373 { 374 if (adcword >= (min + 4*s)) 375 { 376 if (adcword >= (min + 6*s)) 377 { 378 if (adcword >= (min + 7*s)) 379 { 380 temprange = 8; 381 } 382 else 383 { 384 temprange = 7; 385 } 386 } 387 else 388 { 389 if (adcword >= (min + 5*s)) 390 { 391 temprange = 6; 392 } 393 else 394 { 395 temprange = 5; 396 } 397 } 398 } 399 else 400 { 401 if (adcword >= (min + 2*s)) 402 { 403 if (adcword >= (min + 3*s)) 404 { 405 temprange = 4; 406 } 407 else 408 { 409 temprange = 3; 410 } 411 } 412 else 413 { 414 if (adcword >= (min + s)) 415 { 416 temprange = 2; 417 } 418 else 419 { 420 if (adcword > min) 421 { 422 temprange = 1; 423 } 424 } 425 } 426 } 427 } 428 429 430 switch (temprange) 431 { 432 case 1:{ // Temp. Range [-50°C , -34.375°C[ 433 temp = ((float)adcword / 20764.727846 - 252.7721); //20764.727846 - 252.7721 434 } 435 break; 436 437 case 2:{ // Temp. Range [-34.375°C , -18.75°C[ 438 temp = ((float)adcword / 20658.049789 - 253.8995); //20658.049789 - 253.8995 439 } 440 break; 441 442 case 3:{ // Temp. Range [-18.75°C , -3.125°C[ 443 temp = ((float)adcword / 20557.997603 - 255.0436); //20557.997603 - 255.0436 444 } 445 break; 446 447 case 4:{ // Temp. Range [-3.125°C , 12.5°C] 448 temp = ((float)adcword / 20462.362624 - 256.2209); //20462.362624 - 256.2209 449 } 450 break; 451 452 case 5:{ // Temp. Range [12.5°C , 28.125°C] 453 temp = ((float)adcword / 20367.745024 - 257.4692); //20367.745024 - 257.4692 454 } 455 break; 456 457 case 6:{ // Temp. Range [28.125°C , 43.75°C] 458 temp = ((float)adcword / 20273.127424 - 258.8021); //20273.127424 - 258.8021 459 } 460 break; 461 462 case 7:{ // Temp. Range [43.75°C , 59.375°C] 463 temp = ((float)adcword / 20178.509824 - 260.2208); //20178.509824 - 260.2208 464 } 465 break; 466 467 case 8:{ // Temp. Range [59.375°C , 75°C] 468 temp = ((float)adcword / 20083.892224 - 261.7265); //20083.892224 - 261.7265 469 } 470 break; 471 472 case 9:{ // Temp. Range [75°C , 90.625°C] 473 temp = ((float)adcword / 19989.274624 - 263.3203); //19989.274624 - 263.3203 474 } 475 break; 476 477 case 10:{ // Temp. Range [90.625°C , 106.25°C] 478 temp = ((float)adcword / 19894.657024 - 265.0037); //19894.657024 - 265.0037 479 } 480 break; 481 482 case 11:{ // Temp. Range [106.25°C , 121.875°C] 483 temp = ((float)adcword / 19800.039424 - 266.7778); //19800.039424 - 266.7778 484 } 485 break; 486 487 case 12:{ // Temp. Range [121.875°C , 137.5°C] 488 temp = ((float)adcword / 19705.421824 - 268.6439); //19705.421824 - 268.6439 489 } 490 break; 491 492 case 13:{ // Temp. Range [137.5°C , 153.125°C] 493 temp = ((float)adcword / 19610.804224 - 270.6035); //19610.804224 - 270.6035 494 } 495 break; 496 497 case 14:{ // Temp. Range [153.125°C , 168.75°C] 498 temp = ((float)adcword / 19516.186624 - 272.6578); //19516.186624 - 272.6578 499 } 500 break; 501 502 case 15:{ // Temp. Range [168.75°C , 184.375°C] 503 temp = ((float)adcword / 19421.569024 - 274.8082); //19421.569024 - 274.8082 504 } 505 break; 506 507 case 16:{ // Temp. Range [184.375°C , 200°C] 508 temp = ((float)adcword / 19326.951424 - 277.0562); //19326.951424 - 277.0562 509 } 510 break; 511 default: 512 break; 513 }// end of switch case statement 514 return temp; 515 516 } 517 518 -
firmware/FSC/usb_src/interpol.h
r10094 r10754 15 15 float getresistance(void); 16 16 U32 getadc(void); 17 float calc_temp(U32 adcword); 17 18 //----------------------------------------------------------------------------- 18 19 #endif -
firmware/FSC/usb_src/num_conversion.c
r10094 r10754 2 2 3 3 #include "num_conversion.h" 4 #include "math.h" 4 5 //----------------------------------------------------------------------------- 5 6 … … 304 305 } 305 306 307 if (isnan(value)){ 308 pstr[0]=pstr[2]='n'; 309 pstr[1]='a'; 310 pstr[3]=0; 311 return nc_buffer; 312 } 306 313 if (value < 0.0) 307 314 {
Note:
See TracChangeset
for help on using the changeset viewer.