cancel
Showing results for 
Search instead for 
Did you mean: 

Floating point and LCD

abhishek2
Associate II
Posted on September 10, 2008 at 05:49

Floating point and LCD

6 REPLIES 6
jaroslaw2
Associate II
Posted on May 17, 2011 at 12:44

1. Cortex M3 does not have hardware support for floating point arithmetic.

2. However, It is possible to use float numbers and do all arithmetic operations but compiler do in software and it needs hundreds of instructions to do it. Comparing to arithmetic on integers when it needs only few instructions.

3.Standard printf can print floats but much simpler way is to multiply by eg. 10000 and cast to int.

iTemp=(int)(fTem*10000.0);

[ This message was edited by: jaroslaw.oska on 09-09-2008 13:31 ]

abhishek2
Associate II
Posted on May 17, 2011 at 12:44

Does STM32F10 controller support floating point arithmetic? Is is possible to display the floating point number in the LCD?

Thanks

AR

st3
Associate II
Posted on May 17, 2011 at 12:44

Quote:

but compiler do in software and it needs hundreds of instructions to do it. Comparing to arithmetic on integers when it needs only few instructions.

Very true!

A little thought will usually remove the ''need'' (sic) for floating point;

eg, instead of using a floating point number to represent a length of 1.23m, just represent it as 1230mm - and floating point is no longer required!

To display it in metres is simply a matter of adjusting the position of the decimal point...

For another example, see

http://www.8052.com/forum/read.phtml?id=108347

jaroslaw2
Associate II
Posted on May 17, 2011 at 12:44

/* This defines are for Fix type calculations */

#define _FIX_Type long long int

#define _FIX_Precision 23

#define _FIX_DivPrecision_0 8388608.0

#define _FIX_DivPrecision 8388608

#define _FIX_itofx(x) ((long long)(x) << _FIX_Precision)

#define _FIX_fxtoi(x) ((x) >> _FIX_Precision)

#define _FIX_ftofx(x) ((x) * _FIX_DivPrecision)

#define _FIX_fxtof(x) ((float) (x) / _FIX_DivPrecision)

#define _FIX_Mulfx(x,y) (((y) * (x)) >> _FIX_Precision)

#define _FIX_Divfx(x,y) ((x << _FIX_Precision) / (y))

#define _FIX_TEXT(x) ((float)x/(_FIX_DivPrecision_0))

You can use Fix point arithmetic using this macros.

[ This message was edited by: jaroslaw.oska on 09-09-2008 22:50 ]

st3
Associate II
Posted on May 17, 2011 at 12:44

Quote:

#define _FIX_Type long long int

Why would you use a #define rather than a typedef for this?

jaroslaw2
Associate II
Posted on May 17, 2011 at 12:44

Quote:

Why would you use a #define rather than a typedef for this?

You are right st7 your proposition is safer.

thx,

J.O.