Changeset 10753 for firmware/FSC/src/interpol.c
- Timestamp:
- 05/19/11 09:21:09 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/interpol.c
r10102 r10753 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
Note:
See TracChangeset
for help on using the changeset viewer.