comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 260:bde83cac971f

BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
author JeanDo
date Sun, 10 Apr 2011 18:19:42 +0200
parents abbf9a2c2c48
children 9d4ab7c96885
comparison
equal deleted inserted replaced
259:cb95722a81a1 260:bde83cac971f
1885 RESET_C_STACK 1885 RESET_C_STACK
1886 1886
1887 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 ); 1887 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
1888 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 ); 1888 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
1889 1889
1890 #ifndef CROSS_COMPILE
1891 // Note: we don't use far rom pointer, because the
1892 // 24 bits is to complex, hence we have to set
1893 // the UPPER page ourself...
1894 // --> Set zero if tables are moved to lower pages !
1895 _asm
1896 movlw 1
1897 movwf TBLPTRU,0
1898 _endasm
1899 #endif
1900
1890 N2_ratio = 0.7902; // FIXED sum as stated in bühlmann 1901 N2_ratio = 0.7902; // FIXED sum as stated in bühlmann
1891 pres_surface = int_I_pres_surface * 0.001; 1902 pres_surface = int_I_pres_surface * 0.001;
1892 ppN2 = N2_ratio * (pres_surface - ppWVapour); 1903 ppN2 = N2_ratio * (pres_surface - ppWVapour);
1893 int_O_desaturation_time = 0; 1904 int_O_desaturation_time = 0;
1894 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1905 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1899 overlay float temp1; 1910 overlay float temp1;
1900 overlay float temp2; 1911 overlay float temp2;
1901 overlay float temp3; 1912 overlay float temp3;
1902 overlay float temp4; 1913 overlay float temp4;
1903 1914
1904 overlay float var_N2_halftime = buhlmann_ht[ci];
1905 overlay float var_He_halftime = (buhlmann_ht+16)[ci];
1906
1907 // saturation_time (for flight) and N2_saturation in multiples of halftime 1915 // saturation_time (for flight) and N2_saturation in multiples of halftime
1908 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1916 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time )
1909 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1917 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time )
1910 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations 1918 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and NoFly calculations
1911 // N2 1919 // N2
1912 temp1 = 1.05 * ppN2; 1920 temp1 = 1.05 * ppN2 - pres_tissue[ci];
1913 temp1 = temp1 - pres_tissue[ci];
1914 temp2 = ppN2 - pres_tissue[ci]; 1921 temp2 = ppN2 - pres_tissue[ci];
1915 if (temp2 >= 0.0) 1922 if (temp2 >= 0.0)
1916 { 1923 {
1917 temp1 = 0.0; 1924 temp1 = 0.0;
1918 temp2 = 0.0; 1925 temp2 = 0.0;
1919 } 1926 }
1920 else 1927 else
1921 temp1 = temp1 / temp2; 1928 temp1 = temp1 / temp2;
1922 if( 0.0 < temp1 && temp1 < 1.0 ) 1929 if( 0.0 < temp1 && temp1 < 1.0 )
1923 { 1930 {
1924 temp1 = log(1.0 - temp1); 1931 overlay float var_N2_halftime = buhlmann_ht[ci];
1925 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary. 1932 assert( 4.0 <= var_N2_halftime && var_N2_halftime <= 635.0 );
1926 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. 1933
1927 // minus because log is negative 1934 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
1928 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 1935 // minus because log is negative.
1929 1936 temp1 = log(1.0 - temp1) / -0.6931; // temp1 is the multiples of half times necessary.
1930 // HERE ==> This assert fails during simulated dives, and should not.... 1937 temp2 = var_N2_halftime * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 5 percent) , new in v.101: float_desaturation_multiplier
1931 assert( temp2 < 28800.0 ); // 480h !! 1938
1932 } 1939 }
1933 else 1940 else
1934 { 1941 {
1935 temp1 = 0.0; 1942 temp1 = 0.0;
1936 temp2 = 0.0; 1943 temp2 = 0.0;
1942 { 1949 {
1943 temp3 = 0.0; 1950 temp3 = 0.0;
1944 temp4 = 0.0; 1951 temp4 = 0.0;
1945 } 1952 }
1946 else 1953 else
1947 temp3 = -1.0 * temp3 / (pres_tissue+16)[ci]; 1954 temp3 = - temp3 / (pres_tissue+16)[ci];
1948 if( 0.0 < temp3 && temp3 < 1.0 ) 1955 if( 0.0 < temp3 && temp3 < 1.0 )
1949 { 1956 {
1950 temp3 = log(1.0 - temp3); 1957 overlay float var_He_halftime = (buhlmann_ht+16)[ci];
1951 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary. 1958 assert( 1.51 <= var_N2_halftime && var_N2_halftime <= 240.03 );
1959
1960 temp3 = log(1.0 - temp3) / -0.6931; // temp1 is the multiples of half times necessary.
1952 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. 1961 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
1953 // minus because log is negative 1962 // minus because log is negative
1954 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier 1963 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier
1955 } 1964 }
1956 else 1965 else