ds18b20 code for psoc5lp gives 7degree drift in reading

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
prbh_3338016
Level 4
Level 4
10 likes given 5 likes given First like received

Dear Developers,

I am using ds18b20 for reading temperature  using the library shared on psoc community. I am able to successfully interface the ds18b20 (dallas) ic . But comparing the result

i found that my ds18b20 is giving 7-8 degress increased drift in the reading. I thought it was sensor fault so i retested the sensor on the arduino where is gives proper reading. I have RTD Pt100 sensor using which i compared ds18b20 is giving proper result on arduino but not on psoc5lp ( kit 59).

This below library is shared in psoc community.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
prbh_3338016
Level 4
Level 4
10 likes given 5 likes given First like received

FINALLY GOT THIS WORKING. WE HAVE TO ALWAYS CHECK THE LASERMARK ON IC ITSELF. WHETHER IT IS DS1820 OR DS18S20 OR DS18B20. ALWAYS GO THROUGH THE APPLICATION NOTE AND DATASHEET.

I am sharing the working code which will auto detect all these sensors according to their ROM CODES.

CODE WRITTEN WITH HELP OF COMMUNITY GURU'S .

THANKS TO ALL WHO HAVE HELPED ME.

HOPE NEW USER LIKE ME WILL GET DIRECT HELP FROM THIS CODE.

View solution in original post

13 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I have this program running on a PSOC 4 device and it works great.  I have not tried it on a PSOC 5lp device but it should work ok on that device also.  If you are getting bogus data it could be a timing issue with the one wire on the PSOC 5lp/  see attached screen shot of my one wire ds18x8.2018-09-07.png

Thanks sir,

I will check it once

On Fri, Sep 7, 2018, 8:29 PM user_242978793 <community-manager@cypress.com>

0 Likes
lock attach
Attachments are accessible only for community members.

I tried but same result. Today i rebuilded the code using two different  programs shared by two different GURU's on psoc community.

My code is running fine but temparature from ds18b20 is again giving result like 54 and this varies when i apply heat or i touch the sensor.

I have attached the code. Please note that I am trying to display the temperature on 16X2 lcd.

Please check and verify what the problems is in my code. I am not able to verify it. I know i am getting the temperature from ds18b20 but not in useful manner.

Please help

0 Likes

quadratechinfo,

Try to change 1-wire pin from "resistive pull up" to "open drain drives low".

The DS18B20 component works for both settings (on my end), the <pavloven> example uses "open drain drives low".

I believe that 1-wire timing parameters in bots example is the same

Check if you have 3-5k pull-up resistor on 1-wire pin as shown in the demo. PSoC pin internal pull-up resistor of 5-10k is not enough.

/odissey1

Also do you have a O scope and have you checked the data against the data sheet I just sent you?

Thanks for reply. I will recheck and reverify.

But my code is detecting the ds1820 then how it is not giving useful

temperature reading . Can we directly display the register read. Or we have

to do some processing before displaying the data.

Also 4.7k extern pull-up has been used in my case. And pin is in open drive

low mode only.

Please Try to display the temperature on 16x2 lcd using gettemperatureInt

function. You will get drifted result.

In the int temperature fucntion if we remove rounding function at the time

of returning value we get result like 54 56 57 which is 27 28 29 degrees

centigrade.

On Sun, Sep 9, 2018, 2:27 AM user_242978793 <community-manager@cypress.com>

0 Likes

I don't have oscilloscope .

Can you suggest an USB scope cost effective and good.

0 Likes

I have gone through the datasheet.

I just want to know first and second byte of scratchpad sram are Tobe read

as it is and displayed , or we have to process the data first in usable

format

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Okay I have modified my program for you.  You will need to debug it a little as it only gives one reading instead of one every Second or so. 

user_242978793 wrote:

Okay I have modified my program for you.  You will need to debug it a little as it only gives one reading instead of one every Second or so. 

I tried the code. it is giving garbage output on 16X2 lcd. i modified the code for just displaying sensor 1 output as i have only on sensor. I am sharing the image of output.

void ReportTemperature(void)

{ char strMsg[12]={"\0"};         // output UART buffer

    char buf[8];                // temp buffer

    static uint32 counter = 0;  // sample counter

    float res;

    counter++;

     strcat(strMsg, OneWire_GetTemperatureAsString(0)); strcat(strMsg, "\t");

     LCD_Position(0,1);

    LCD_PrintString(strMsg);   }

resultusingstring.jpg

if i use gettemperatureint100 function i get below result. which also wrong and drifted. I am in Ac room where temperature is 26 degree centigrade.

void ReportTemperature(void)

{

    char strMsg[12]={"\0"};         // output UART buffer

    char buf[8];                // temp buffer

    static uint32 counter = 0;  // sample counter

    float res;

    counter++;

     

    strcat(strMsg, OneWire_GetTemperatureAsString(0)); strcat(strMsg, "\t");

        

   // UART_1_PutString(strMsg);

    LCD_Position(0,1);

    LCD_PrintNumber(OneWire_GetTemperatureAsInt100(0)); //for displaying int temp

   

}

I get Below result drifted. This resulted temperature do change.

resultusing INTtemp.jpg

Also need to know what is this fucntion exactly doing why 8u is added. Even if i remove 8u result doesnt change

//==============================================================================

// Convert DS18B20 temperature (degC) as *100 value rounded to integer

// e.g. -38.0625 -> "-3806"

//==============================================================================

int16 OneWire_GetTemperatureAsInt100 (uint8 index)

{

    int16 Val = OneWire_Sensor[index].Temperature;

    return ((Val * 100u + 8u) >> 4); //rounding

}

Please display your code result on lcd 16x2 and please verify the gettemperatureINT100 is working for you aswell.

0 Likes

I just found that i am using ds1820 sensor and not ds18b20.

0 Likes
lock attach
Attachments are accessible only for community members.
prbh_3338016
Level 4
Level 4
10 likes given 5 likes given First like received

FINALLY GOT THIS WORKING. WE HAVE TO ALWAYS CHECK THE LASERMARK ON IC ITSELF. WHETHER IT IS DS1820 OR DS18S20 OR DS18B20. ALWAYS GO THROUGH THE APPLICATION NOTE AND DATASHEET.

I am sharing the working code which will auto detect all these sensors according to their ROM CODES.

CODE WRITTEN WITH HELP OF COMMUNITY GURU'S .

THANKS TO ALL WHO HAVE HELPED ME.

HOPE NEW USER LIKE ME WILL GET DIRECT HELP FROM THIS CODE.