The Godfather talking
You can run, but you can't hide.
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 09, 2016, 10:08:52 22:08


Login with username, password and session length


Pages: [1]
Print
Author Topic: Attiny2313 + DS18B20P  (Read 1817 times)
0 Members and 1 Guest are viewing this topic.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« on: January 26, 2013, 07:09:58 19:09 »

Here is a simple quick project. Look at the files attached.
It has 0.1C resolution, very accurate indeed.
I also modified ds18b20 library, much better and stable.. When interrupts were used th original library had problems, I fixed them. Most of the code in main.c is mine!
Logged

nothing to say..
Bobbla
Newbie
*
Offline Offline

Posts: 22

Thank You
-Given: 2
-Receive: 16


« Reply #1 on: January 27, 2013, 03:20:59 03:20 »

Uhm, sorry for the inconvenience. But how is the 0.1C accuracy achieved?

I took a look at the maxim website and the datasheet of the DS18B20 but as far as I can see, they both say:
Quote
0.5C Accuracy from -10C to +85C

cheers!

edit: fixed the url's.
« Last Edit: January 27, 2013, 08:26:47 20:26 by Bobbla » Logged
Old_but_Alive
V.I.P
Active Member
*****
Offline Offline

Posts: 211

Thank You
-Given: 154
-Receive: 56


« Reply #2 on: January 27, 2013, 05:18:50 05:18 »

metal's post is quite correct.

He states the resolution as 0.1C, not the accuracy, which is 0.5C

why are you criticising metal ?
Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1446

Thank You
-Given: 591
-Receive: 851



« Reply #3 on: January 27, 2013, 06:31:15 06:31 »

Grammatically, accuracy and resolution were equated, OBA

That said, you can calibrate it close to the resolution
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #4 on: January 27, 2013, 10:33:38 10:33 »

over the range from -10C to +85C, reading error can be +/-0.5C, which is the accuracy over the whole range. resolution is actually 0.0625C, so 0.0625C is the steps at which temperature is converted (incremented/decremented), hence resolution, and when the decimal part is calculated, it is divided by 1000 to display only xx.x, instead of xx.xxxx... so accuracy and resolution are not the same.. Bobbla, read the datasheets again. In p.8 in the datasheet, you can configure the sensor's resolution, as shown in the attached figure. then you have to manipulate the reading you obtained from the sensor depending on the resolution you selected..

BAZINGA!!
Logged

nothing to say..
Bobbla
Newbie
*
Offline Offline

Posts: 22

Thank You
-Given: 2
-Receive: 16


« Reply #5 on: January 27, 2013, 08:25:02 20:25 »

He states the resolution as 0.1C, not the accuracy, which is 0.5C

metal stated that

It has 0.1C resolution, very accurate indeed.

and when metal said "very accurate indeed" I figured metal emphasized that the 0.1C resolution was very accurate. What else could metal be emphasizing?

why are you criticising metal ?

I'm sorry you thought it was criticism, but it wasn't. I simply looked at what metal said, then thought thats a nice temperature sensor and looked it up. I then asked because I didn't understand/I was confused about what metal meant.

over the range from -10C to +85C, reading error can be +/-0.5C, which is the accuracy over the whole range.

Technically, the +/-0.5C is in the -10C to +85C which is not the whole operating range. I also note that the datasheet has a figure(17) called "Typical Performance Curve" which displays temperature error over a temperature range of -20 to +70 as far I can see. Why they don't show "performance" over the whole operating range I can only speculate on, never mind the meaning of the "mean" error" curve and its purpose.

resolution is actually 0.0625C, so 0.0625C is the steps at which temperature is converted (incremented/decremented), hence resolution, and when the decimal part is calculated, it is divided by 1000 to display only xx.x, instead of xx.xxxx... so accuracy and resolution are not the same.. Bobbla, read the datasheets again. In p.8 in the datasheet, you can configure the sensor's resolution, as shown in the attached figure. then you have to manipulate the reading you obtained from the sensor depending on the resolution you selected..

I now understand that the temperature sensors datasheet says, 0.0625C resolution and that you want to only display 3 numbers.

I'm still a little confused, how is the 0.0625C derived? I would think that they would take the operating range divided by 12 bit resolution. I mean, 12 bit resolution = 4095 steps, but 4095 steps of 0.0625C increments gives about 255C which is not equal to the 180C temperature range.

Also, as I understand it the ADC can supposedly deliver 0.0625C accurate temperature measurements. But whatever it is measuring from seems to only deliver 0.5C precision. Is this a good assumption?

edit: also, the accuracy and resolution are not exactly the same. BUT a higher resolution gives the opportunity for greater accuracy. The resolution comes from ADC, which measures voltage. The accuracy in degrees Celsius is a result voltage change over "something", so the accuracy is a result of both the ADC resolution and the accuracy of "something" to generate a specific voltage as a result of temperature. DERP!  Huh
« Last Edit: January 27, 2013, 08:38:53 20:38 by Bobbla » Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #6 on: January 27, 2013, 10:46:21 22:46 »

I was not thinking that you were criticizing, rather you did not read the datasheet. I am also not defending my project, what really matters is that you still can't get the idea behind the 0.1C on the display. An accuracy of +/-0.5C over the range of -10C to 85C is not bad IMHO. From the datasheet:
"The core functionality of the DS18B20 is its direct-to-digital temperature sensor. The resolution of the temperature sensor is user-configurable to 9, 10, 11, or 12 bits, corresponding to increments of 0.5C, 0.25C, 0.125C, and 0.0625C, respectively. The temperature data is stored as a 16-bit sign-extended twos complement number in the temperature register. If the DS18B20 is configured for 12-bit resolution, all bits in the temperature register will contain valid data. For 11-bit resolution, bit 0 is undefined. For 10-bit resolution, bits 1 and 0 are undefined, and for 9-bit resolution bits 2, 1, and 0 are undefined. Table 1 gives examples of digital output data and the corresponding temperature reading for 12-bit resolution conversions." Look at the temperature sensor Temp_Reg.png attachment..

To be able to extract the readable temperature (12-bit example) from the sensor, you need to do something like this:

Code:
uint8_t digit
uint8_t decimal
uint8_t sign;
int16_t temperature

// for example read_ds18b20()
temperature = read_ds18b20();
// check for temperature < 0
if (temperature < 0) {
   temperature = -temperature;
   sign = 1;
   }
else
   sign = 0;

digit = temperature >> 4;
decimal = temperature & 0x0F;
decimal *= 625;
decimal /= 1000;

The resulting temperature measurement is in 0.0625C steps. What is did was actually taking the decimals, multiply them by 625 and then divide by 1000:

decimal   x   625      result/1000   
--------------------------------------------         
1              625                0.63
2              1250                1.25
3              1875                1.88
4              2500                2.50
5              3125                3.13
6              3750               3.75
7              4375               4.38
8              5000               5.00
9              5625               5.63
10              6250               6.25
11              6875               6.88
12              7500               7.50
13              8125               8.13
14              8750               8.75
15              9375               9.38

The numbers you see in red are the ones that are finally stored in decimal variable and then displayed as yy.x. End of story I think, this is the best way to get 0.1 steps from this sensor. Practically speaking, if you will criticize the fact that there are similar digits in red, you will find out that the reading is more stable as well, the decimal digit rarely flips ;- )

The main idea was to use a digital temperature sensor from which I can get yy.x reading and avoid using, for example, LM35 which will eventually trick me into using either 12 or 13 bit ADC, or even tweak the ADC's reference voltage. The real task was to use this existing board that already has ATtiny2313 (comes without ADC inside it..) and make the code compact, and still get the job done. If you look at cnt variable in the code attached earlier which is responsible for deciding how many digits to light and how I managed to display the '-' sign, you rarely see such methods implemented in recent codes! The nice thing is that even if the reading is 0, the display will show 0.0, this was not easy for me to achieve at the beginning because I wanted to keep the code as compact as possible, and I think I succeeded..
« Last Edit: January 27, 2013, 11:05:10 23:05 by metal » Logged

nothing to say..
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC