Embedded system, Floating point math, C

Status
Not open for further replies.

Blaze

Seniorius Lurkius
20
I'm having a little trouble with some floating point math in an embedded system project I'm working on. This little bit of code from a listing file relating to a motion control algorithm.

; LSPEED = (int)(K_w*K_s*K_e*((float)LCOUNTS));
0DFB EC12 ldd -14,x
0DFD 49 lsrd
0DFE 1614F6 jsr __d2lreg ß
0E01 160F50 jsr __long2fp
0E04 161232 jsr __fpmov
0E07 CD0F10 ldy #L16

The C variables: K_w, K_s, K_e, are floats, LCOUNTS is an unsigned integer, and LSPEED is a regular int.

First, is my type casting correct?

Second, Something very odd is happening, either I don't have the complete floating-point libraries <float.h> or they are not linking correctly. If you notice the line pointed out with the arrow, jump to subroutine __d2lreg. The problem is, there is no subroutine __d2lreg. In fact none of those subroutine exist. __d2lreg is something created by the compiler and I assume it has something to do with handling floating point numbers. I would expect it to be in one of the libraries included with the compiler. It is not, or I can't find it.

I was hoping that someone would have some insight into this problem.

I have a Motorola 68hc12-development board and I'm using the ImageCraft C compilers.

A little info about me: I am a Mechanical engineering senior a CalPoly, SLO. I'm working on my senior project, a small autonomous robot.

geoff
 

wb

Ars Legatus Legionis
25,208
Subscriptor
Your type casting looks ok to me, but if you want to make it clearer why don't you break it up into a couple different lines of code to make sure the casting is happening the way you want it to? i.e. one line does all the floating point operations, the other line does the integer operations.



I'm not familiar with the hc12, but I assume it's a variant of the hc11.

I found the following in the ImageCraft HC11 compiler FAQ here:

printf does not print floating point number:
You must explicitly link in the libfp.a library. "#include <stdio.h>" in your source code is not sufficient.


Hope that helps.
 
Status
Not open for further replies.