Jump to content
Sparky1039

Pow(X,y) Function Supported?

Recommended Posts

Sparky1039    0

I couldn't find anything in the documentation indicating that SB supports the C math library which has the POW(x,y) function.

 

What I'm trying to do is compute this equation... y = 52080 x^-0.8754 (note X is an unsigned integer variable)

 

It is a curve fit formula of a non-linear transform. My goal is to see how computationally intensive this is and if it's worth developing a look-up table as an alternative approach. The issue with the lookup table is the amount of memory I have available (both ROM or RAM). External RAM/EEPROM may work but the timing delay involved scanning a couple hundred points could be prohibitive.

 

On the other hand perhaps someone has a better approach to efficiently compute this equation.

 

Thanks

Edited by Sparky1039

Share this post


Link to post
Share on other sites
JorgeF    0

Hi

 

I would not expect to find a math library for an 8 bit PIC with more than the 4 basic operations and even so only for integers.

Floating point powers are a bit too hard for an 8 bit PIC.

That is a job for a 16 or 32 bit PIC.

 

Given that, I already faced such a chalenge in a real world application (a lab tool).

But by looking at the forest rather than the tree, I end up with a PIC for raw data aquisition and a PC for the heavy processing.

I've also seen another approach by someone else, an 8 bit PIC for data aquisition and a "Raspeberry Pi" for the heavy work (maths+storage+network).

 

If you "really" need to use the PIC for the maths, than a mix of processing and data tables can do the trick.

 

Remember your maths, in special logarithms and exponentiation.

You can reduce the "pow" to product/quotient and the product/quotient to sum/subbtration.

Also the floating point numbers can be reduced to fixed point integers to a given precision.

This way you may be able to do the trick with only a logarithmic table.

 

In terms of table sizes, I frequently manage to keep them in a controled size by simulating the problem in a spreadsheet and reducing the ranges and resolution to what is really needed for a given project.

Another thing that helps in saving processing time is to keep in mind what kind of precision is "really" necessary for a given application.

 

Just in case you need a quick refresh.... https://mathvault.ca/logarithm-theory/#scale

 

 

HIH

 

 

Best regards

Jorge

Edited by JorgeF

Share this post


Link to post
Share on other sites
Sparky1039    0

Thanks Jorge. After pondering the issues it became very obvious that it wasn't possible to do this kind of number crunching with a small 8-bit PIC. Exponentiation generates such enormous sized numbers that 64-bit variables are a must. Even if I could get the 8-bit PIC to deal with this math it would take equally large amounts of time to process it, completely negating the whole purpose of the exercise. Even a big lookup table would seen lightning fast in comparison. So that was the route I have taken, and by applying a binary tree search process it actually isn't so bad time wise.

Cheers.

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum 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...

×