comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 165:8b5b848db4cd

+ Clean Buhlmann tables addressing + OSTC 1.80 uses ZH-L16a coefficient, version 1995 (?), with compartiment 1a.
author JeanDo
date Fri, 21 Jan 2011 01:44:38 +0100
parents 999abb01c78f
children cb055a7d75f3
comparison
equal deleted inserted replaced
164:999abb01c78f 165:8b5b848db4cd
142 static float temp_tissue; 142 static float temp_tissue;
143 static float temp_surface; 143 static float temp_surface;
144 static float N2_ratio; 144 static float N2_ratio;
145 static float He_ratio; 145 static float He_ratio;
146 static float temp_ratio; 146 static float temp_ratio;
147 static float var_a; 147 static float var_N2_a;
148 static float var2_a; 148 static float var_N2_b;
149 static float var_b; 149 static float var_He_a;
150 static float var2_b; 150 static float var_He_b;
151 static float var_t05nc; 151 static float var_N2_e;
152 static float var2_t05nc; 152 static float var_He_e;
153 static float var_e2secs; 153 static float var_N2_halftime;
154 static float var2_e2secs; 154 static float var_He_halftime;
155 static float var_e1min;
156 static float var2_e1min;
157 static float var_halftimes;
158 static float var2_halftimes;
159 static float pres_gtissue_limit; 155 static float pres_gtissue_limit;
160 static float temp_pres_gtissue_limit; 156 static float temp_pres_gtissue_limit;
161 static float actual_ppO2; // new in v.102 157 static float actual_ppO2; // new in v.102
162 158
163 static float pres_diluent; // new in v.101 159 static float pres_diluent; // new in v.101
247 // *********************** 243 // ***********************
248 // ** THE LOOKUP TABLES ** 244 // ** THE LOOKUP TABLES **
249 // *********************** 245 // ***********************
250 // *********************** 246 // ***********************
251 247
252 #pragma romdata tables = 0x10200 248 #pragma romdata buhlmann_tables = 0x010200 // Needs to be in UPPER bank.
253 #include "p2_tables.romdata" // new table for deco_main_v.101 (var_a modified) 249 #include "p2_tables.romdata" // new table for deco_main_v.101 (var_N2_a modified)
254 250
255 #pragma romdata tables2 = 0x10600 251 #pragma romdata hash_tables = 0x010600 // Address fixed by ASM access...
256 rom const rom unsigned int md_pi[] = 252 rom const rom unsigned int md_pi[] =
257 { 253 {
258 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613 254 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613
259 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA 255 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA
260 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512 256 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512
439 void check_post_dbg(void) 435 void check_post_dbg(void)
440 { 436 {
441 check_dbg(1); 437 check_dbg(1);
442 } 438 }
443 439
444 // ------------------------- 440 //////////////////////////////////////////////////////////////////////////////
441 // read buhlmann tables for compatriment ci
442 // If mode == 0 : 2sec interval
443 // 1 : 1 min interval
444 // 2 : 10 min interval.
445 // TODO: an assembleur version of the table reads...
446 static void read_buhlmann_compartment(static char mode)
447 {
448 var_N2_a = buhlmann_a[ci];
449 var_N2_b = buhlmann_b[ci];
450 var_He_a = buhlmann_a[ci + 16];
451 var_He_b = buhlmann_b[ci + 16];
452 // Check reading consistency:
453 if( (var_N2_a < 0.231)
454 || (var_N2_a > 1.27)
455 || (var_N2_b < 0.504)
456 || (var_N2_b > 0.966)
457 || (var_He_a < 0.510)
458 || (var_He_a > 1.75)
459 || (var_He_b < 0.423)
460 || (var_He_b > 0.927)
461 )
462 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
463
464 // Integration intervals.
465 switch(mode)
466 {
467 case 0: //---- 2 sec -----------------------------------------------------
468 var_N2_e = e2secs[ci];
469 var_He_e = e2secs[ci + 16];
470
471 // Check reading consistency:
472 if( (var_N2_e < 0.0000363)
473 || (var_N2_e > 0.00577)
474 || (var_He_e < 0.0000961)
475 || (var_He_e > 0.150)
476 )
477 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
478
479 break;
480
481 case 1: //---- 1 min -----------------------------------------------------
482 var_N2_e = e1min[ci];
483 var_He_e = e1min[ci + 16];
484
485 // Check reading consistency:
486 if( (var_N2_e < 1.09E-3)
487 || (var_N2_e > 0.1592)
488 || (var_He_e < 0.00288)
489 || (var_He_e > 0.3682)
490 )
491 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
492
493 break;
494
495 case 2: //---- 10 min ----------------------------------------------------
496 var_N2_e = e10min[ci];
497 var_He_e = e10min[ci + 16];
498
499 // Check reading consistency:
500 if( (var_N2_e < 0.01085)
501 || (var_N2_e > 0.82323)
502 || (var_He_e < 0.02846)
503 || (var_He_e > 0.98986)
504 )
505 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
506
507 break;
508 }
509 }
510
511 //////////////////////////////////////////////////////////////////////////////
445 // calc_next_decodepth_GF // 512 // calc_next_decodepth_GF //
446 // ------------------------- 513 //
447 // new in v.102 514 // new in v.102
515 //
448 void calc_nextdecodepth_GF(void) 516 void calc_nextdecodepth_GF(void)
449 { 517 {
450 // INPUT, changing during dive: 518 // INPUT, changing during dive:
451 // temp_pres_gtissue_limit_GF_low 519 // temp_pres_gtissue_limit_GF_low
452 // temp_pres_gtissue_limit_GF_low_below_surface 520 // temp_pres_gtissue_limit_GF_low_below_surface
731 } 799 }
732 800
733 // --------------- 801 // ---------------
734 // CLEAR tissue // 802 // CLEAR tissue //
735 // --------------- 803 // ---------------
736 // optimized in v.101 (var_a) 804 // optimized in v.101 (var_N2_a)
737 805
738 #pragma code p2_deco_suite = 0x10700 806 #pragma code p2_deco_suite = 0x10700
739 807
740 void clear_tissue(void) // preload tissues with standard pressure for the given ambient pressure 808 void clear_tissue(void) // preload tissues with standard pressure for the given ambient pressure
741 { 809 {
754 movlw 1 822 movlw 1
755 movwf TBLPTRU,0 823 movwf TBLPTRU,0
756 _endasm 824 _endasm
757 for(ci=0;ci<16;ci++) 825 for(ci=0;ci<16;ci++)
758 { 826 {
759 overlay float p;
760 // cycle through the 16 b"uhlmann tissues 827 // cycle through the 16 b"uhlmann tissues
761 p = N2_ratio * (pres_respiration - 0.0627) ; 828 overlay float p = N2_ratio * (pres_respiration - 0.0627);
762 pres_tissue[ci] = p; 829 pres_tissue[ci] = p;
763 830
764 var_a = ((rom float*)a_N2)[ci]; 831 read_buhlmann_compartment(0);
765 var_b = ((rom float*)b_N2)[ci]; 832
766 p = (p - var_a) * var_b ; 833 p = (p - var_N2_a) * var_N2_b ;
767 if( p < 0.0 ) 834 if( p < 0.0 )
768 p = 0.0; 835 p = 0.0;
769 pres_tissue_limit[ci] = p; 836 pres_tissue_limit[ci] = p;
770 837
771 // cycle through the 16 b"uhlmann tissues for Helium 838 // cycle through the 16 b"uhlmann tissues for Helium
1200 char_O_gtissue_no = 255; 1267 char_O_gtissue_no = 255;
1201 pres_gtissue_limit = 0.0; 1268 pres_gtissue_limit = 0.0;
1202 1269
1203 for (ci=0;ci<16;ci++) 1270 for (ci=0;ci<16;ci++)
1204 { 1271 {
1205 _asm 1272 read_buhlmann_compartment(0); // 2 sec mode.
1206 movlw 0x02
1207 movwf TBLPTRH,0
1208 movlb 5 // fuer ci
1209 movf ci,0,1
1210 addwf ci,0,1
1211 addwf ci,0,1
1212 addwf ci,0,1
1213 movwf TBLPTRL,0
1214 TBLRDPOSTINC
1215 movff TABLAT,var_e2secs+1 // the order is confussing
1216 TBLRDPOSTINC
1217 movff TABLAT,var_e2secs // low byte first, high afterwards
1218 TBLRDPOSTINC
1219 movff TABLAT,var_e2secs+3
1220 TBLRD
1221 movff TABLAT,var_e2secs+2
1222 addlw 0x40
1223 movwf TBLPTRL,0
1224 TBLRDPOSTINC
1225 movff TABLAT,var2_e2secs+1
1226 TBLRDPOSTINC
1227 movff TABLAT,var2_e2secs
1228 TBLRDPOSTINC
1229 movff TABLAT,var2_e2secs+3
1230 TBLRD
1231 movff TABLAT,var2_e2secs+2
1232 addlw 0x40
1233 movwf TBLPTRL,0
1234 TBLRDPOSTINC
1235 movff TABLAT,var_a+1
1236 TBLRDPOSTINC
1237 movff TABLAT,var_a
1238 TBLRDPOSTINC
1239 movff TABLAT,var_a+3
1240 TBLRD
1241 movff TABLAT,var_a+2
1242 addlw 0x40
1243 movwf TBLPTRL,0
1244 TBLRDPOSTINC
1245 movff TABLAT,var2_a+1
1246 TBLRDPOSTINC
1247 movff TABLAT,var2_a
1248 TBLRDPOSTINC
1249 movff TABLAT,var2_a+3
1250 TBLRD
1251 movff TABLAT,var2_a+2
1252 addlw 0x40
1253 movwf TBLPTRL,0
1254 incf TBLPTRH,1,0
1255 TBLRDPOSTINC
1256 movff TABLAT,var_b+1
1257 TBLRDPOSTINC
1258 movff TABLAT,var_b
1259 TBLRDPOSTINC
1260 movff TABLAT,var_b+3
1261 TBLRD
1262 movff TABLAT,var_b+2
1263 addlw 0x40
1264 movwf TBLPTRL,0
1265 TBLRDPOSTINC
1266 movff TABLAT,var2_b+1
1267 TBLRDPOSTINC
1268 movff TABLAT,var2_b
1269 TBLRDPOSTINC
1270 movff TABLAT,var2_b+3
1271 TBLRD
1272 movff TABLAT,var2_b+2
1273 _endasm
1274 // the start values are the previous end values // write new values in temp
1275
1276 if( (var_e2secs < 0.0000363)
1277 || (var_e2secs > 0.00577)
1278 || (var2_e2secs < 0.0000961)
1279 || (var2_e2secs > 0.150)
1280 || (var_a < 0.231)
1281 || (var_a > 1.27)
1282 || (var_b < 0.504)
1283 || (var_b > 0.966)
1284 || (var2_a < 0.510)
1285 || (var2_a > 1.75)
1286 || (var2_b < 0.423)
1287 || (var2_b > 0.927)
1288 )
1289 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
1290 1273
1291 // N2 1274 // N2
1292 temp_tissue = (temp_atem - pres_tissue[ci]) * var_e2secs; 1275 temp_tissue = (temp_atem - pres_tissue[ci]) * var_N2_e;
1293 temp_tissue_safety(); 1276 temp_tissue_safety();
1294 pres_tissue[ci] = pres_tissue[ci] + temp_tissue; 1277 pres_tissue[ci] = pres_tissue[ci] + temp_tissue;
1295 1278
1296 // He 1279 // He
1297 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var2_e2secs; 1280 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var_He_e;
1298 temp_tissue_safety(); 1281 temp_tissue_safety();
1299 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue; 1282 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue;
1300 1283
1301 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; 1284 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16];
1302 1285
1303 var_a = (var_a * pres_tissue[ci] + var2_a * pres_tissue[ci+16]) / temp_tissue; 1286 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * pres_tissue[ci+16]) / temp_tissue;
1304 var_b = (var_b * pres_tissue[ci] + var2_b * pres_tissue[ci+16]) / temp_tissue; 1287 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * pres_tissue[ci+16]) / temp_tissue;
1305 pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; 1288 pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b;
1306 if (pres_tissue_limit[ci] < 0) 1289 if (pres_tissue_limit[ci] < 0)
1307 pres_tissue_limit[ci] = 0; 1290 pres_tissue_limit[ci] = 0;
1308 if (pres_tissue_limit[ci] > pres_gtissue_limit) 1291 if (pres_tissue_limit[ci] > pres_gtissue_limit)
1309 { 1292 {
1310 pres_gtissue_limit = pres_tissue_limit[ci]; 1293 pres_gtissue_limit = pres_tissue_limit[ci];
1460 temp_pres_gtissue_limit = 0.0; 1443 temp_pres_gtissue_limit = 0.0;
1461 temp_gtissue_no = 255; 1444 temp_gtissue_no = 255;
1462 1445
1463 for (ci=0;ci<16;ci++) 1446 for (ci=0;ci<16;ci++)
1464 { 1447 {
1465 _asm 1448 read_buhlmann_compartment(1); // 1 minute interval
1466 movlw 0x02 1449
1467 movwf TBLPTRH,0
1468 movlb 5 // fuer ci
1469 movf ci,0,1
1470 addwf ci,0,1
1471 addwf ci,0,1
1472 addwf ci,0,1
1473 addlw 0x80
1474 movwf TBLPTRL,0
1475 TBLRDPOSTINC
1476 movff TABLAT,var_a+1
1477 TBLRDPOSTINC
1478 movff TABLAT,var_a
1479 TBLRDPOSTINC
1480 movff TABLAT,var_a+3
1481 TBLRD
1482 movff TABLAT,var_a+2
1483 addlw 0x40
1484 movwf TBLPTRL,0
1485 TBLRDPOSTINC
1486 movff TABLAT,var2_a+1
1487 TBLRDPOSTINC
1488 movff TABLAT,var2_a
1489 TBLRDPOSTINC
1490 movff TABLAT,var2_a+3
1491 TBLRD
1492 movff TABLAT,var2_a+2
1493 addlw 0x40
1494 movwf TBLPTRL,0
1495 incf TBLPTRH,1,0
1496 TBLRDPOSTINC
1497 movff TABLAT,var_b+1
1498 TBLRDPOSTINC
1499 movff TABLAT,var_b
1500 TBLRDPOSTINC
1501 movff TABLAT,var_b+3
1502 TBLRD
1503 movff TABLAT,var_b+2
1504 addlw 0x40
1505 movwf TBLPTRL,0
1506 TBLRDPOSTINC
1507 movff TABLAT,var2_b+1
1508 TBLRDPOSTINC
1509 movff TABLAT,var2_b
1510 TBLRDPOSTINC
1511 movff TABLAT,var2_b+3
1512 TBLRD
1513 movff TABLAT,var2_b+2
1514 addlw 0xC0
1515 movwf TBLPTRL,0
1516 incf TBLPTRH,1,0
1517 TBLRDPOSTINC
1518 movff TABLAT,var_e1min+1
1519 TBLRDPOSTINC
1520 movff TABLAT,var_e1min
1521 TBLRDPOSTINC
1522 movff TABLAT,var_e1min+3
1523 TBLRD
1524 movff TABLAT,var_e1min+2
1525 addlw 0x40
1526 movwf TBLPTRL,0
1527 TBLRDPOSTINC
1528 movff TABLAT,var2_e1min+1
1529 TBLRDPOSTINC
1530 movff TABLAT,var2_e1min
1531 TBLRDPOSTINC
1532 movff TABLAT,var2_e1min+3
1533 TBLRD
1534 movff TABLAT,var2_e1min+2
1535 _endasm
1536
1537 // N2 1450 // N2
1538 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_e1min; 1451 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_N2_e;
1539 temp_tissue_safety(); 1452 temp_tissue_safety();
1540 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue; 1453 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue;
1541 1454
1542 // He 1455 // He
1543 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var2_e1min; 1456 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var_He_e;
1544 temp_tissue_safety(); 1457 temp_tissue_safety();
1545 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue; 1458 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue;
1546 1459
1547 // pressure limit 1460 // pressure limit
1548 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16]; 1461 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16];
1549 var_a = (var_a * sim_pres_tissue[ci] + var2_a * sim_pres_tissue[ci+16]) / temp_tissue; 1462 var_N2_a = (var_N2_a * sim_pres_tissue[ci] + var_He_a * sim_pres_tissue[ci+16]) / temp_tissue;
1550 var_b = (var_b * sim_pres_tissue[ci] + var2_b * sim_pres_tissue[ci+16]) / temp_tissue; 1463 var_N2_b = (var_N2_b * sim_pres_tissue[ci] + var_He_b * sim_pres_tissue[ci+16]) / temp_tissue;
1551 sim_pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; 1464 sim_pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b;
1552 1465
1553 if (sim_pres_tissue_limit[ci] < 0) 1466 if (sim_pres_tissue_limit[ci] < 0)
1554 sim_pres_tissue_limit[ci] = 0; 1467 sim_pres_tissue_limit[ci] = 0;
1555 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit) 1468 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit)
1556 { 1469 {
1569 1482
1570 //-------------------- 1483 //--------------------
1571 // sim_tissue_10min // 1484 // sim_tissue_10min //
1572 //-------------------- 1485 //--------------------
1573 1486
1574 // Attention!! uses var_e1min und var2_e1min to load 10min data !!! 1487 // Attention!! uses var_N2_e und var_He_e to load 10min data !!!
1575 // is identical to sim_tissue_1min routine except for the different load of those variables 1488 // is identical to sim_tissue_1min routine except for the different load of those variables
1576 1489
1577 // optimized in v.101 1490 // optimized in v.101
1578 1491
1579 void sim_tissue_10min(void) 1492 void sim_tissue_10min(void)
1581 temp_pres_gtissue_limit = 0.0; 1494 temp_pres_gtissue_limit = 0.0;
1582 temp_gtissue_no = 255; 1495 temp_gtissue_no = 255;
1583 1496
1584 for (ci=0;ci<16;ci++) 1497 for (ci=0;ci<16;ci++)
1585 { 1498 {
1586 _asm 1499 read_buhlmann_compartment(2); // 10 minute interval
1587 movlw 0x02 1500
1588 movwf TBLPTRH,0
1589 movlb 5 // fuer ci
1590 movf ci,0,1
1591 addwf ci,0,1
1592 addwf ci,0,1
1593 addwf ci,0,1
1594 addlw 0x80
1595 movwf TBLPTRL,0
1596 TBLRDPOSTINC
1597 movff TABLAT,var_a+1
1598 TBLRDPOSTINC
1599 movff TABLAT,var_a
1600 TBLRDPOSTINC
1601 movff TABLAT,var_a+3
1602 TBLRD
1603 movff TABLAT,var_a+2
1604 addlw 0x40
1605 movwf TBLPTRL,0
1606 TBLRDPOSTINC
1607 movff TABLAT,var2_a+1
1608 TBLRDPOSTINC
1609 movff TABLAT,var2_a
1610 TBLRDPOSTINC
1611 movff TABLAT,var2_a+3
1612 TBLRD
1613 movff TABLAT,var2_a+2
1614 addlw 0x40
1615 movwf TBLPTRL,0
1616 incf TBLPTRH,1,0
1617 TBLRDPOSTINC
1618 movff TABLAT,var_b+1
1619 TBLRDPOSTINC
1620 movff TABLAT,var_b
1621 TBLRDPOSTINC
1622 movff TABLAT,var_b+3
1623 TBLRD
1624 movff TABLAT,var_b+2
1625 addlw 0x40
1626 movwf TBLPTRL,0
1627 TBLRDPOSTINC
1628 movff TABLAT,var2_b+1
1629 TBLRDPOSTINC
1630 movff TABLAT,var2_b
1631 TBLRDPOSTINC
1632 movff TABLAT,var2_b+3
1633 TBLRD
1634 movff TABLAT,var2_b+2
1635 addlw 0xC0 // different to 1 min
1636 movwf TBLPTRL,0
1637 incf TBLPTRH,1,0
1638 incf TBLPTRH,1,0 // different to 1 min
1639 TBLRDPOSTINC
1640 movff TABLAT,var_e1min+1
1641 TBLRDPOSTINC
1642 movff TABLAT,var_e1min
1643 TBLRDPOSTINC
1644 movff TABLAT,var_e1min+3
1645 TBLRD
1646 movff TABLAT,var_e1min+2
1647 addlw 0x40
1648 movwf TBLPTRL,0
1649 //incf TBLPTRH,1,0 // different to 1 min
1650 TBLRDPOSTINC
1651 movff TABLAT,var2_e1min+1
1652 TBLRDPOSTINC
1653 movff TABLAT,var2_e1min
1654 TBLRDPOSTINC
1655 movff TABLAT,var2_e1min+3
1656 TBLRD
1657 movff TABLAT,var2_e1min+2
1658 _endasm
1659
1660 // N2 1501 // N2
1661 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_e1min; 1502 temp_tissue = (temp_atem - sim_pres_tissue[ci]) * var_N2_e;
1662 temp_tissue_safety(); 1503 temp_tissue_safety();
1663 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue; 1504 sim_pres_tissue[ci] = sim_pres_tissue[ci] + temp_tissue;
1664 // He 1505 // He
1665 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var2_e1min; 1506 temp_tissue = (temp2_atem - sim_pres_tissue[ci+16]) * var_He_e;
1666 temp_tissue_safety(); 1507 temp_tissue_safety();
1667 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue; 1508 sim_pres_tissue[ci+16] = sim_pres_tissue[ci+16] + temp_tissue;
1668 1509
1669 // pressure limit 1510 // pressure limit
1670 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16]; 1511 temp_tissue = sim_pres_tissue[ci] + sim_pres_tissue[ci+16];
1671 var_a = (var_a * sim_pres_tissue[ci] + var2_a * sim_pres_tissue[ci+16]) / temp_tissue; 1512 var_N2_a = (var_N2_a * sim_pres_tissue[ci] + var_He_a * sim_pres_tissue[ci+16]) / temp_tissue;
1672 var_b = (var_b * sim_pres_tissue[ci] + var2_b * sim_pres_tissue[ci+16]) / temp_tissue; 1513 var_N2_b = (var_N2_b * sim_pres_tissue[ci] + var_He_b * sim_pres_tissue[ci+16]) / temp_tissue;
1673 1514
1674 sim_pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; 1515 sim_pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b;
1675 if (sim_pres_tissue_limit[ci] < 0) 1516 if (sim_pres_tissue_limit[ci] < 0)
1676 sim_pres_tissue_limit[ci] = 0; 1517 sim_pres_tissue_limit[ci] = 0;
1677 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit) 1518 if (sim_pres_tissue_limit[ci] > temp_pres_gtissue_limit)
1678 { 1519 {
1679 temp_pres_gtissue = temp_tissue; 1520 temp_pres_gtissue = temp_tissue;
1764 1605
1765 1606
1766 // ----------------------- 1607 // -----------------------
1767 // calc_gradient_factor // 1608 // calc_gradient_factor //
1768 // ----------------------- 1609 // -----------------------
1769 // optimized in v.101 (var_a) 1610 // optimized in v.101 (var_N2_a)
1770 // new code in v.102 1611 // new code in v.102
1771 1612
1772 void calc_gradient_factor(void) 1613 void calc_gradient_factor(void)
1773 { 1614 {
1774 // tissue > respiration (entsaettigungsvorgang) 1615 // tissue > respiration (entsaettigungsvorgang)
1833 int_O_desaturation_time = 0; 1674 int_O_desaturation_time = 0;
1834 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1675 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1835 1676
1836 for (ci=0;ci<16;ci++) 1677 for (ci=0;ci<16;ci++)
1837 { 1678 {
1838 _asm 1679 var_N2_halftime = buhlmann_ht[ci];
1839 movlw 0x04 1680 var_He_halftime = buhlmann_ht[ci + 16];
1840 movwf TBLPTRH,0
1841 movlb 5 // fuer ci
1842 movf ci,0,1
1843 addwf ci,0,1
1844 addwf ci,0,1
1845 addwf ci,0,1
1846 addlw 0x80
1847 movwf TBLPTRL,0
1848 TBLRDPOSTINC
1849 movff TABLAT,var_halftimes+1
1850 TBLRDPOSTINC
1851 movff TABLAT,var_halftimes
1852 TBLRDPOSTINC
1853 movff TABLAT,var_halftimes+3
1854 TBLRD
1855 movff TABLAT,var_halftimes+2
1856 addlw 0x40
1857 movwf TBLPTRL,0
1858 TBLRDPOSTINC
1859 movff TABLAT,var2_halftimes+1
1860 TBLRDPOSTINC
1861 movff TABLAT,var2_halftimes
1862 TBLRDPOSTINC
1863 movff TABLAT,var2_halftimes+3
1864 TBLRD
1865 movff TABLAT,var2_halftimes+2
1866 _endasm
1867 1681
1868 // saturation_time (for flight) and N2_saturation in multiples of halftime 1682 // saturation_time (for flight) and N2_saturation in multiples of halftime
1869 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1683 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time )
1870 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1684 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time )
1871 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations 1685 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations
1884 { 1698 {
1885 temp1 = log(1.0 - temp1); 1699 temp1 = log(1.0 - temp1);
1886 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary. 1700 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary.
1887 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. 1701 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
1888 // minus because log is negative 1702 // minus because log is negative
1889 temp2 = var_halftimes * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 10 percent) , new in v.101: float_desaturation_multiplier 1703 temp2 = var_N2_halftime * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 10 percent) , new in v.101: float_desaturation_multiplier
1890 } 1704 }
1891 else 1705 else
1892 { 1706 {
1893 temp1 = 0; 1707 temp1 = 0;
1894 temp2 = 0; 1708 temp2 = 0;
1907 { 1721 {
1908 temp3 = log(1.0 - temp3); 1722 temp3 = log(1.0 - temp3);
1909 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary. 1723 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary.
1910 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. 1724 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
1911 // minus because log is negative 1725 // minus because log is negative
1912 temp4 = var2_halftimes * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier 1726 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier
1913 } 1727 }
1914 else 1728 else
1915 { 1729 {
1916 temp3 = 0; 1730 temp3 = 0;
1917 temp4 = 0; 1731 temp4 = 0;
1989 char_O_gtissue_no = 255; 1803 char_O_gtissue_no = 255;
1990 pres_gtissue_limit = 0.0; 1804 pres_gtissue_limit = 0.0;
1991 1805
1992 for (ci=0;ci<16;ci++) 1806 for (ci=0;ci<16;ci++)
1993 { 1807 {
1994 _asm 1808 read_buhlmann_compartment(1); // 1 minute interval
1995 movlw 0x02
1996 movwf TBLPTRH,0
1997 movlb 5 // fuer ci
1998 movf ci,0,1
1999 addwf ci,0,1
2000 addwf ci,0,1
2001 addwf ci,0,1
2002 addlw 0x80
2003 movwf TBLPTRL,0
2004 TBLRDPOSTINC
2005 movff TABLAT,var_a+1
2006 TBLRDPOSTINC
2007 movff TABLAT,var_a
2008 TBLRDPOSTINC
2009 movff TABLAT,var_a+3
2010 TBLRD
2011 movff TABLAT,var_a+2
2012 addlw 0x40
2013 movwf TBLPTRL,0
2014 TBLRDPOSTINC
2015 movff TABLAT,var2_a+1
2016 TBLRDPOSTINC
2017 movff TABLAT,var2_a
2018 TBLRDPOSTINC
2019 movff TABLAT,var2_a+3
2020 TBLRD
2021 movff TABLAT,var2_a+2
2022 addlw 0x40
2023 movwf TBLPTRL,0
2024 incf TBLPTRH,1,0
2025 TBLRDPOSTINC
2026 movff TABLAT,var_b+1
2027 TBLRDPOSTINC
2028 movff TABLAT,var_b
2029 TBLRDPOSTINC
2030 movff TABLAT,var_b+3
2031 TBLRD
2032 movff TABLAT,var_b+2
2033 addlw 0x40
2034 movwf TBLPTRL,0
2035 TBLRDPOSTINC
2036 movff TABLAT,var2_b+1
2037 TBLRDPOSTINC
2038 movff TABLAT,var2_b
2039 TBLRDPOSTINC
2040 movff TABLAT,var2_b+3
2041 TBLRD
2042 movff TABLAT,var2_b+2
2043 addlw 0xC0
2044 movwf TBLPTRL,0
2045 incf TBLPTRH,1,0
2046 TBLRDPOSTINC
2047 movff TABLAT,var_e1min+1
2048 TBLRDPOSTINC
2049 movff TABLAT,var_e1min
2050 TBLRDPOSTINC
2051 movff TABLAT,var_e1min+3
2052 TBLRD
2053 movff TABLAT,var_e1min+2
2054 addlw 0x40
2055 movwf TBLPTRL,0
2056 TBLRDPOSTINC
2057 movff TABLAT,var2_e1min+1
2058 TBLRDPOSTINC
2059 movff TABLAT,var2_e1min
2060 TBLRDPOSTINC
2061 movff TABLAT,var2_e1min+3
2062 TBLRD
2063 movff TABLAT,var2_e1min+2
2064 _endasm
2065 1809
2066 // N2 1 min 1810 // N2 1 min
2067 temp_tissue = (temp_atem - pres_tissue[ci]) * var_e1min; 1811 temp_tissue = (temp_atem - pres_tissue[ci]) * var_N2_e;
2068 temp_tissue_safety(); 1812 temp_tissue_safety();
2069 pres_tissue[ci] = pres_tissue[ci] + temp_tissue; 1813 pres_tissue[ci] = pres_tissue[ci] + temp_tissue;
2070 1814
2071 // He 1 min 1815 // He 1 min
2072 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var2_e1min; 1816 temp_tissue = (temp2_atem - pres_tissue[ci+16]) * var_He_e;
2073 temp_tissue_safety(); 1817 temp_tissue_safety();
2074 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue; 1818 pres_tissue[ci+16] = pres_tissue[ci+16] + temp_tissue;
2075 1819
2076 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; 1820 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16];
2077 var_a = (var_a * pres_tissue[ci] + var2_a * pres_tissue[ci+16]) / temp_tissue; 1821 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * pres_tissue[ci+16]) / temp_tissue;
2078 var_b = (var_b * pres_tissue[ci] + var2_b * pres_tissue[ci+16]) / temp_tissue; 1822 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * pres_tissue[ci+16]) / temp_tissue;
2079 pres_tissue_limit[ci] = (temp_tissue - var_a) * var_b; 1823 pres_tissue_limit[ci] = (temp_tissue - var_N2_a) * var_N2_b;
2080 if (pres_tissue_limit[ci] < 0) 1824 if (pres_tissue_limit[ci] < 0)
2081 pres_tissue_limit[ci] = 0; 1825 pres_tissue_limit[ci] = 0;
2082 if (pres_tissue_limit[ci] > pres_gtissue_limit) 1826 if (pres_tissue_limit[ci] > pres_gtissue_limit)
2083 { 1827 {
2084 pres_gtissue_limit = pres_tissue_limit[ci]; 1828 pres_gtissue_limit = pres_tissue_limit[ci];
2100 md_state[md_i] = 0; 1844 md_state[md_i] = 0;
2101 char_O_hash[md_i] = 0; 1845 char_O_hash[md_i] = 0;
2102 } // for md_i 16 1846 } // for md_i 16
2103 1847
2104 _asm 1848 _asm
2105 movlw 0x01 1849 movlw 0x01 // md_pi address.
2106 movwf TBLPTRU,0 1850 movwf TBLPTRU,0
2107 movlw 0x06 1851 movlw 0x06
2108 movwf TBLPTRH,0 1852 movwf TBLPTRH,0
2109 movlw 0x00 1853 movlw 0x00
2110 movwf TBLPTRL,0 1854 movwf TBLPTRL,0
2111 _endasm; 1855 _endasm;
2112 for(md_i=0;md_i<=255;md_i++) 1856 md_i = 0;
2113 { 1857 do {
2114 _asm 1858 _asm
2115 TBLRDPOSTINC 1859 TBLRDPOSTINC
2116 movff TABLAT,md_temp 1860 movff TABLAT,md_temp
2117 _endasm 1861 _endasm
2118 md_pi_subst[md_i] = md_temp; 1862 md_pi_subst[md_i++] = md_temp;
2119 } // for md_i 256 1863 } while( md_i != 0 );
2120 1864
2121 _asm 1865 _asm
2122 movlw 0x00 1866 movlw 0x00
2123 movwf TBLPTRU,0 1867 movwf TBLPTRU,0
2124 movlw 0x00 1868 movlw 0x00
2125 movwf TBLPTRH,0 1869 movwf TBLPTRH,0