Go Down

Topic: uint32_t to int32_t conversion help needed (Read 2356 times) previous topic - next topic

_Leo_

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
Leo

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

pYro_65

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.

_Leo_

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

The int vlaues are:

16777120
16777118
16777095

Sorry about that.
Leo

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

pYro_65

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.

_Leo_

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.
Leo

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

PaulS

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.

robtillaart

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,
Rob Tillaart

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

_Leo_


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.
Leo

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

_Leo_


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.
Leo

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

_Leo_

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

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

Thanks!
Leo

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

robtillaart

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 :)
Link datasheet?
Rob Tillaart

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy