Error in one-wire example in the library manager

Beta Testing discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Error in one-wire example in the library manager

#1 Post by Dany » 11 Nov 2013 21:19

Hi, in the compiler's one-wire example in the library manager I think I found 2 issues:

a.

Code: Select all

//  Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:
//  18S20: 9  (default setting; can be 9,10,11,or 12)
//  18B20: 12
In above it is the 18S20 that has always a resolution of 9 byte, and the 18B20 has a programmable resolution of 9, 10, 11 or 12 bits.

b.

Code: Select all

const TEMP_RESOLUTION : byte = 9;
const RES_SHIFT = TEMP_RESOLUTION - 8;

Code: Select all

// Extract temp_whole
    temp_whole := word(temp2write shr RES_SHIFT);
Above code will only work well for the DS18S20, not for the DS18B20. The datasheet states that the shift to be used for the 18B20 is always 4, irrespective of the resolution set.
For the 18S20 the shift is always 1.

Code: Select all

// Extract temp_fraction and convert it to unsigned int
    temp_fraction  :=  word(temp2write shl (4-RES_SHIFT));
In above code the shift is only needed for the DS18S20, and only if a 4 digits after the decimal point -- of which 3 will be zero -- are needed in the string result. If only 1 decimal point is needed in the string result then no shift is needed at all.
For the DS18B20 a shift is never needed and above code gives an incorrect result.

Thanks for the adaptation! Keep up the good work! :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Error in one-wire example in the library manager

#2 Post by filip » 12 Nov 2013 12:09

Hi,

Thank you for this observation, I have forwarded this to the guys in charge. :)

Regards,
Filip.

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”