Hi shurikn,
ich versuchs mal ...
also im Datenblatt steht ja folgendes ...
OPERATION – MEASURING TEMPERATURE
The core functionality of the DS18S20 is its direct-to-digital temperature sensor. The temperature sensor
output has 9-bit resolution, which corresponds to 0.5°C steps. The DS18S20 powers-up in a low-power
idle state; to initiate a temperature measurement and A-to-D conversion, the master must issue a Convert
T [44h] command. Following the conversion, the resulting thermal data is stored in the 2-byte
temperature register in the scratchpad memory and the DS18S20 returns to its idle state. If the DS18S20
is powered by an external supply, the master can issue “read time slots” (see the 1-WIRE BUS SYSTEM
section) after the Convert T command and the DS18S20 will respond by transmitting 0 while the
temperature conversion is in progress and 1 when the conversion is done. If the DS18S20 is powered
with parasite power, this notification technique cannot be used since the bus must be pulled high by a
strong pullup during the entire temperature conversion. The bus requirements for parasite power are
explained in detail in the POWERING THE DS18S20 section of this datasheet.
The DS18S20 output data is calibrated in degrees centigrade; for Fahrenheit applications, a lookup table
or conversion routine must be used. The temperature data is stored as a 16-bit sign-extended two’s
complement number in the temperature register (see Figure 2). The sign bits (S) indicate if the
temperature is positive or negative: for positive numbers S = 0 and for negative numbers S = 1. Table 2
gives examples of digital output data and the corresponding temperature reading.
Resolutions greater than 9 bits can be calculated using the data from the temperature, COUNT REMAIN
and COUNT PER °C registers in the scratchpad. Note that the COUNT PER °C register is hard-wired to
16 (10h). After reading the scratchpad, the TEMP_READ value is obtained by truncating the 0.5°C bit
(bit 0) from the temperature data (see Figure 2). The extended resolution temperature can then be
calculated using the following equation:
TEMPERATURE = TEMP_READ - 0,25 + ( COUNT_PER_C - COUNT_REMAIN ) / COUNT_PER_C
Additional information about high-resolution temperature calculations can be found in Application Note
105: “High Resolution Temperature Measurement with Dallas Direct-to-Digital Temperature Sensors”.
und ...
Byte0 - Sc(1) - Temperature LSB (AAh
Byte1 - Sc(2) - Temperature MSB (00h)
Byte2 - Sc(3) - TH Register or User Byte 1*
Byte3 - Sc(4) - TL Register or User Byte 2*
Byte4 - Sc(5) - Reserved (FFh)
Byte5 - Sc(6) - Reserved (FFh)
Byte6 - Sc(7) - COUNT REMAIN (0Ch)
Byte7 - Sc(8) - COUNT PER °C (10h)
Byte8 - Sc(9) - CRC*
und ...
LSB Sc(1) - 2^6, 2^5, 2^4, 2^3, 2^2, 2^1, 2^0, 2^-1
MSB Sc(2) - S , S , S , S , S , S , S , S
also ...
Temp = Sc(1) - 0,25 + ( Sc(8) - Sc(7) ) / Sc(8)
(hoffentlich richtig
)
Code:
Sc(1) = 1wread(9)
If Sc(9) = Crc8(sc(1) , 8) Then
' Genauere Temperaturberechnung auf 0,1 °C
I = Sc(1) And 1
If I = 1 Then Decr Sc(1)
T01 = Sc(1) / 2
T01 = T01 - 0.25
T0 = Sc(8) - Sc(7)
T0 = T0 / Sc(8)
T0 = T0 + T01
'Temperatur in 0,1 Grad Schritten ausgeben
Print "Temperatur 2: " ; Fusing(t0 , "##.#") ; " Grad"
Also ...
I = Sc(1) And 1 .... => Bit0 von Sc(1) ausmaskieren und Ergebnis nach I
Es werden also die halben GradC nach I gespeichert.
Wenn es ein halbes Grad gibt dann wird Sc(1) um 1 vermindert.
Dann wird in T01 mit Sc(1)/2 geladen (könnte man auch mit nem shift machen).
Es werden also die vollen GradC berechnet und in T01 gespeichert.
.....
Aha ... es wird also über einen ziemlich komplizierten Umweg das Bit0 des
Bytes vom LSB-Scratchpad gelöscht. Manoman. Warum machen die das
nicht mit ...
Sc(1).0 = 0
geht das in Bascom nicht ? Einfach ddas Bit auf 0 setzen ?
Das machen die um bei dem folgenden /2 keine 0.5 zu bekommen. Also nur
ganzzahlige Ergebnisse. Das ganze ...
T01 = T01 - 0.25
T0 = Sc(8) - Sc(7)
T0 = T0 / Sc(8)
T0 = T0 + T01
dahinter ist dann die Berechnung aus der Formel.
Ich würde sagen ... von hinten durch die Brust ins Auge. Das ganze ...
I = Sc(1) And 1
If I = 1 Then Decr Sc(1)
T01 = Sc(1) / 2
könnte man mit...
T01 = SHIFT Sc(1) , RIGHT , 1
in einem Befehl erledigen der bestimmt auch noch wesentlich schneller und
speicherplatzsparender ist.
When shifting to the RIGHT, the least significant bit will be shifted out of the variable.
The MS bit becomes zero. Shifting a variable to the right, divides the variable by two.
Gruß
Dino