Solved

How to manipulate floating point number in ARM 7 ?

Posted on 2014-01-29
3
485 Views
Last Modified: 2014-01-29
How do I manipulate floating point numbers in ARM 7 based target ?
Our embedded application is based on ARM 7 Microcontroller.  This microcontroller does not have floating point unit.  
We are using Keil's compiler, assembler, linker, and Real-Time Operating System.

I'm getting unsigned32 minutes over modbus.  I need to convert them to hours and send over USB to PC application.

i.e.
Given:  5351 minutes
My embedded application needs to:  5351 / 60 = 89.18333...
Then, I would send 891 or 892 to PC application.  They would divide by 10 to display 891 or 892 hours.

What are my options ?

1)  Does Keil provide any floating point library ?
2)  Floating point math is usually eliminated in embedded systems.  Instead, fixed-point math is used.  Does Keil provide fixed point math library?
3)  Use shift operations to achieve my goal?

What would be the best way to convert minutes to hours in my embedded application?
0
Comment
Question by:naseeam
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39819316
Just use your compiler's built-in support: http://www.keil.com/support/docs/1879.htm

QUESTION

We are changing software that currently uses integer math to use floating-point math. Does the Keil C166 Compiler support floating-point math and are there include files or libraries we need to declare in order for it to compile successfully with float variables?
ANSWER

The C166 compiler supports both single-precision (32-bit) and double-precision (64-bit) floating-point. To use either, all you have to do is start declaring and using floating-point variables just like in ANSI C.

By default, all float and double variables are stored in 32-bit IEEE format. This gives a precision of 7 decimal digits. When you require higher precision (than 7 digits) you may use the C166 FLOAT64 directive to enable 64-bit doubles. Enable this option in µVision under Project - Options for Target - C166 - Double-precision floating-point. If you enable FLOAT64, all double variables are stored in 64-bit IEEE format. This provides a precision of 15 decimal digits.

IOW, even though your CPU does not have a FPU, the compiler supplied runtime will take care of that.

See also http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471j/pge1358786964007.html ("1.8 ARM and Thumb floating-point build options (ARMv7 and later)")
0
 
LVL 1

Author Comment

by:naseeam
ID: 39819357
Thank you very much for great answer.   If I use Keil's floating point library, I'll get floating point hours.  I need integer hours because I need to send them to PC application as integer.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39819374
Well, then cast the result back to integer, e.g.

int nMin = 5351;
float fMin = (float) nMin;

float fHrs = fMin / 60.0;

int nHrs = (int) fHrs * 10.0;

Open in new window


But: If that is all your calculation requirement, you can elominate the whole floating point thing with a simple trick: First multiply the minutes by 10 and then divide by 60, the results will be the same, e.g.

int nMin = 5351;

int nHrs = (nMin * 10) / 60; // or: int nHrs = nMin / 6;

Open in new window

0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
stack 22 164
libcurl and C++ - Post JSON Data 8 1,292
Exception thrown at 0x53730ED0 (ucrtbased.dll) in  0xC0000005: Access violation reading location 0xCDA9C0F0 3 827
List out all word 7 289
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question