Jump to content

Recommended Posts

Need to use FP in this app.

Can't get a simple mulltiply to work.

 

All I want to do is multipy 23.8609294 by 42345678.

Is is too many bytes?

 

I need some help!

 

Carlos

Share this post


Link to post
Share on other sites

Hi Carlos,

 

The floating point library is only single precision therefore there is a limit in the number of digits it can work with.

 

The manual indicates 7 digits.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Hi Carlos,

 

You could scale you numbers down to fit into a single precision but you would still lose resolution.

 

You could search the web for source code to impliment double precision (64 bit).

 

You could look at a hardware numeric processor chip such as the Micromega Corp. uM-FPU64.

You use an SPI or I2C interface and computation speeds are not to bad.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

OK Thanks Ill have to try something.

But I ran into another problem. This line produces an error in asm:

 

bcf STATUS,0 //; Start with Carry clear

 

using 18F2520

 

Any idea wha's wrong?

 

Carlos

Share this post


Link to post
Share on other sites

Try this

 

bcf _status,C

 

Page 64 of manual: prefix variables in assembler with underscore.

 

Register variables are also in lower case.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

My first FP is a failure

Need help with this...somebody.

I have to assign a variable to x.

 

 

void Calc()

}

Dialer = 1111111;

float x;

//x = 1111111; // This works!

x = Dialer; //This won't work!!!

//Error is "can't convert unsigned/signed long to float"

x = float32_mul(x,23.86892);

C0 = float32_to_int32(x);

}

 

 

Anyway to resolve this?

Carlos

Edited by Carlos

Share this post


Link to post
Share on other sites

Well I tried that but once you declare float the variable is blank.

I had to have Dialer set before the call. It was automatically set in other functions.

 

Tried and tried but no luck. Still I learned a lot about float. ha ha Forget it!

 

Thanks for your interest in my problems....

 

Carlos

Share this post


Link to post
Share on other sites

Hi Carlos,

 

You can give Dialer a value when you declare it.

 

float Dialer = 1111111;

 

or

 

You can delare Dialer as static and the compiler sets it to a value of zero (unless told otherwise).

 

static float Dialer; // Dialer is initialised to zero;

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

I guess I'm not saying it correctly.

Dialer is a long and is set to a value in the program at various places .

It must come into Calc() and remain set to it's value. OK

 

How can I keep Dialer unchanged?

Hope you have an answer...

 

Carlos

Share this post


Link to post
Share on other sites

How about somrthing like this:

#include <system.h>
#include <float.h>
long Dialer = 1111111;
long C0;
void Calc()
{
   C0 = float32_to_int32(float32_mul(float32_from_int32(Dialer), 23.86892));
}
void main()
{
   float_rounding_mode = float_round_up;
   Calc();
}

 

Reynard

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...