Page 1 of 1

Anybody have ideas how to fix this

Posted: Thu Nov 03, 2011 8:15 pm
by Jordy101091
Hi all,

I i'm working on a project that requires a DS18B20 Temp sensor from maxim.
I can read the and display the temperature but when it comes over 32.76 degrees, it shows negative numbers.
I know what the problem is, and it is because im using integers but how im do i fix this.

does somebody have any ideas.

Regards Jordy

Re: Anybody have ideas how to fix this

Posted: Thu Nov 03, 2011 10:41 pm
by Mikat
Hi.
This is just from memory, but try like this.
Start conversion
Delay 750
OO read device(device number)
Ds1820 get temp(device number)
The get temp macro givers the scratchpad bytes 0 and 1 and if the device is 18b20, the value is 16bit signed integer, so the 4msb bits is -/+ sign so the Fxxxh is negative temp , and rest 12bit is the temp value 0,0625 deg per bit...
And the FFFFh is -0,0625,the 0001h +0,0625, so the negative value starts at FFFFh, and every -0,0625 subtract one bit..


Mika

Re: Anybody have ideas how to fix this

Posted: Fri Nov 04, 2011 10:27 pm
by JonnyW
Hi Jordy.

The number you describe, 32.76 looks like the upper limit to an 'int' - 32768 is hex 8000, which is the signed lowest value available. Im afraid I dont have access to Flowcode v4 at the moment but if you ammend your code from:

Code: Select all

temp_calculated = (onewire_temp_lowbyte << 8) + onewire_temp_highbyte
To:

Code: Select all

temp_calculated = (onewire_temp_lowbyte << 7) + (onewire_temp_highbyte >> 1)
onewire_temp_lowint = (temp_calculated % 500)
onewire_temp_highint = (temp_calculated / 500)
Then you can do a string manipulation:

Code: Select all

temp_calc_high = ToString$(onewire_temp_highint)
temp_calc_low = ToString$(onewire_temp_lowint)
And hopefully get the result you want. This should have a range 2 times higher than the current range, though 'temp_calc_low' will need left-padding with zeros if its less than 100 (3 digits):

Code: Select all

temp_calc_low = "000" + temp_calc_low
temp_calc_low = Right$(temp_calc_low, 3)
Like I say, I dont have access to FCv4 right now so all this is off the top of my head, but hopefully it should work OK (barring any typos!).

Hope this makes enough sense,

Jonny

Re: Anybody have ideas how to fix this

Posted: Sun Nov 06, 2011 10:48 pm
by Jordy101091
Hi JonnyW

I have found the problem with the temperature reading. I have fixed and it works perfectly.
The problem was that I have put an integer value in a byte variable.

Know a want to go a step further in my project and make a menu with some settings, my goal is to navigate trough the menu and
alter the different settings with a rotary encoder.
I have been playing a round with this thing, but I can get it to work proparly.

here are some pics of my scope output ad counter-clock-wise(1) and clock-wise(2) rotation(one-click)

(1)
Image (http://imageshack.us/photo/my-images/513/img0022uu.jpg)
(2)
Image (http://imageshack.us/photo/my-images/46/img0023ev.jpg)

When going trough the menu I need to turn one-click at a time otherwise I see 2 poiting arrows or more.
Also in the video you can see the value of 189 it wont increase or decrease I dont know why it is.

http://youtu.be/uL4lr8ROW_0?hd=1

I hope you want and can help me with this,
Regards,

Jordy

Re: Anybody have ideas how to fix this

Posted: Mon Nov 07, 2011 2:50 pm
by JonnyW
Hi Jordy. I'm not an embedded engineer so cant help with your oscilloscope problem, but I'll ask someone here (probably Ben or Sean) to take a look.

One point, you mentioned your arrows sometimes display twice - I cant simulate or test your program as you are using a custom component for the LCD but you have a point in your code that either increases or decreases 'count'. Yet the code to hide the previous menu item (writing " " to the LCD) always assumes you are moving down the menu. Is this right?

Also, the code 'encoder_A = encoder_A_old' - is this checking for debounce or should this be 'encoder_A != encoder_A_old'?

Anyway, on a check for 'encoder_A_old' this is never being assigned a value in Time_Date_Settings. This might be your problem. You could also do with initialising some of your variables on startup too - 'rtc_set_hour' is never initialised so 189 is probably whatever value was in RAM on startup, and never changes.

Cheers, lemme know if this fixes anything,

Jonny