Pages: [1]   Go Down
Author Topic: uint32_t to int32_t conversion help needed  (Read 1532 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Jr. Member
**
Karma: 3
Posts: 81
I'm a newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

today I did some tests with a sensor in temperatures below 0 Celsius.

Unfortunately I made the mistake in declaring the temperature variable with uint32_t instead of int32_t.

Arduino shows these 3 measurements:

167771.20
167771.18
167770.95

Can anyone tell me what minus values these are? It should be somewhere around -1 Celsius or so.

Thanks.

Leo
Logged

Leo

Project "ALTDuino" - A homemade altimeter for model rockets.
http://www.altduino.de


North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 65
Posts: 2107
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this: http://arduino.cc/forum/index.php/topic,97455.0.html

You'll have to post some code as 167771.20 is neither an unsigned or signed integer.
Logged


Germany
Offline Offline
Jr. Member
**
Karma: 3
Posts: 81
I'm a newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You are correct. The ones I posted are converted to float values (/100).

The int vlaues are:

16777120
16777118
16777095

Sorry about that.
Logged

Leo

Project "ALTDuino" - A homemade altimeter for model rockets.
http://www.altduino.de


North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 65
Posts: 2107
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the values you posted are unsigned and you need signed, then there is no conversion. 16777120 will not overflow a signed 32-bit int. Which also means the reverse is true.
Logged


Germany
Offline Offline
Jr. Member
**
Karma: 3
Posts: 81
I'm a newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much for the help and opening my eyes!

I am now realizing that it's a lot more complicated than I had thought.

I'm going to reverse engineer my code to find the correct value.

If that doesn't work then no big deal. It was only a "nice to have" for knowing.

I found the error in my code which is the most important thing.

Thanks again.
Logged

Leo

Project "ALTDuino" - A homemade altimeter for model rockets.
http://www.altduino.de


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm going to reverse engineer my code to find the correct value.
Why?

Quote
Unfortunately I made the mistake in declaring the temperature variable with uint32_t instead of int32_t.
So, fix the mistake.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the numbers sound like a 24 bit int - can that be possible?
Can you tell more about the sensor ?
Link datasheet?


16777216 = 2^24
=>
16777120 = -96
16777118 = -98
16777095 = -121

If the number is to be interpreted with 2 decimals it would be -0.96, -0.98, -1.21 which looks like a stable T measurement

Post your code if you need help with reverse engineering,
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Germany
Offline Offline
Jr. Member
**
Karma: 3
Posts: 81
I'm a newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm going to reverse engineer my code to find the correct value.
Why?

Because I'm nosey.

Quote
Unfortunately I made the mistake in declaring the temperature variable with uint32_t instead of int32_t.
So, fix the mistake.

There is a saying: "He who can read has a clear advantage"

This thread isn't to long. Give it a try.
Logged

Leo

Project "ALTDuino" - A homemade altimeter for model rockets.
http://www.altduino.de


Germany
Offline Offline
Jr. Member
**
Karma: 3
Posts: 81
I'm a newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

the numbers sound like a 24 bit int - can that be possible?
Can you tell more about the sensor ?
Link datasheet?


16777216 = 2^24
=>
16777120 = -96
16777118 = -98
16777095 = -121

If the number is to be interpreted with 2 decimals it would be -0.96, -0.98, -1.21 which looks like a stable T measurement

Post your code if you need help with reverse engineering,


Thanks Rob. I think you may have goten it! I will verify.

Again, knowing the values was only a "nice to know" for me. I've already corrected my code. Problem is sovled.

Case closed.
Logged

Leo

Project "ALTDuino" - A homemade altimeter for model rockets.
http://www.altduino.de


Germany
Offline Offline
Jr. Member
**
Karma: 3
Posts: 81
I'm a newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Rob, if I could I'd send you some Bavarian beer.

I just verified your numbers with my code -> Bull's-eye  smiley

Thanks!
Logged

Leo

Project "ALTDuino" - A homemade altimeter for model rockets.
http://www.altduino.de


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Rob, if I could I'd send you some Bavarian beer.
I'll drink one here on your health,

Still open question:
Can you tell more about the sensor ?  I really want to know what does 24 bit smiley
Link datasheet?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: