Buongiorno....
sto realizzando un progetto dove mi serve tenere sotto controllo la temperatura di carica/scarica di una batteria 18650. Ho impostato temporaneamente la soglia di 40 gradi e il progetto funziona bene. Però in maniera random si blocca perche' il 18B20 fornisce una lettura sballata che e' ben superiore ai 40 gradi impostati (51....61....): in realtà la temperatura è ben al di sotto di tale valore. Di seguito il codice scritto in Positron (ex proton basic) trovato in rete.
'*************************************************************************
'******************** LEGGI Temperatura ********************
'*************************************************************************
Proc GetDegree(), SDword
' Read the DS18S20 chip
Dim tmpVal As Dword
Dim Temp As Word ' Holds the temperature value
Dim bCounts As Byte ' Holds the counts remaining value
Dim negative As Temp.15 ' the sign bit
OWrite DQ_Pin, 1, [$CC, $44] ' Send a Calculate Temperature command
Repeat
DelayMS 100 ' Wait until conversion is complete
ORead DQ_Pin, 4, [bCounts] ' Keep reading low pulses until
Until bCounts <> 0 ' the DS1820 is finished.
OWrite DQ_Pin, 1, [$CC, $BE] ' Send a Read ScratchPad command
DelayMS 50
ORead DQ_Pin, 2,[Temp.LowByte, Temp.HighByte]
If FirstRead = False Then ' Non scrive prima misura +85.00
FirstRead = True
ExitProc
End If
' Calculate the temperature in degrees Centigrade
If negative = 1 Then
Temp = ~Temp + 1
Set negate
Else
Clear negate
End If
tmpVal = (Temp >> 4) * 10000
tmpVal = tmpVal + (Temp & $000f) * 625
Result = tmpVal / 10
If negate = 1 Then
Result = -Result
End If
EndProc
'*************************************************************************
la lettura sballata, può avvenire dopo pochi minuti o piu' di un'ora....
Come può essere? Qualche suggerimento?