Hi All,
I am having an problem with a unsigned divide I am not sure what I am missing or doing wrong
Variable Raw is a unsigned int and factor is also an unsigned int value 32768 by dividing it to get the Resistance send from the MAX31865 SPI as per datasheet my result is always 0.0 ,Resistance is a float variable ,
when I just use a value of 32 for the factor then I get a result it is somehow connected to the 32768 number ,
How can I solve this or how can I use the type conversion component to do this
Divide by 32 give a correct result but using the factor of 32768 does not work what Am I doing wrong
Problem with unsigned divide
- p.erasmus
- Posts: 434
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 03, 2020 12:01 pm
- Location: Russia / Россия
- Has thanked: 104 times
- Been thanked: 88 times
-
- Matrix Staff
- Posts: 1310
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 175 times
- Been thanked: 299 times
Re: Problem with unsigned divide
Raw and Factor are both integers, and so the result of their division will also (initially) be an integer. This will be zero because Factor is high. Only then is it converted to a float.
Instead, you should do the divide using at least one float number.
One way to do this is to first set Resistance = Raw. Then perform Resistance = Resistance / Factor.
(edit: Martin beat me to it!)
Instead, you should do the divide using at least one float number.
One way to do this is to first set Resistance = Raw. Then perform Resistance = Resistance / Factor.
(edit: Martin beat me to it!)
- p.erasmus
- Posts: 434
- Joined: Thu Dec 03, 2020 12:01 pm
- Location: Russia / Россия
- Has thanked: 104 times
- Been thanked: 88 times
Re: Problem with unsigned divide
Hi Martin / Steve
Thanks so much you pulled me out of this loop
I almost have no hair left
Many thanks again it is working spot on now
Thanks so much you pulled me out of this loop
I almost have no hair left
Many thanks again it is working spot on now
Regards Peter - QME Electronics