## use of trigonometric function in flowcode 4.3

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Rahul Kulkarni
Posts: 8
Joined: Fri Jan 20, 2012 5:46 am
Has thanked: 3 times
Contact:

### use of trigonometric function in flowcode 4.3

Hi. I am rahul kulkarni. I am developing an automotive application for fuel indicators. I am using PIC18F458 controller. I want to use relations which has trignometric functions. It involves inverse trig. function also. I am unable to use it in flowcode v4.3. Can anybody help me out in this?

JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 64 times
Been thanked: 306 times
Contact:

### Re: use of trigonometric function in flowcode 4.3

Hello. Due to the limited space and floating-point support in 8-bit pics, these functions are not supported by Flowcode v4.3.

Your best bet is to use lookup-tables and maybe 8 or 12 bit fixed point for trig, depending on how accurate you need to be.
There is a good lookup table tutorial here:
http://matrixmultimedia.com/mmforums/viewtopic.php?f=26&t=10066

Can you post more details on what kind of trig you would like to do and in what context and maybe there are workarounds as on an 8-bit pic using trig or floating point could slow things down noticeably.

Jonny
These users thanked the author JonnyW for the post:
Rahul Kulkarni (Wed Jan 25, 2012 11:25 am)
Rating: 5.88%

Rahul Kulkarni
Posts: 8
Joined: Fri Jan 20, 2012 5:46 am
Has thanked: 3 times
Contact:

### Re: use of trigonometric function in flowcode 4.3

Thanks for the reply. My functions are ang = atan(d/a) and h = a sin(ang). Lookup tables are such that they are not for all values e.g. 1st 0 then 0.5. But we want to measure between 0-0.5 also. So we are using relation. If you can provide me some alternate solution in which i can use relation then it would be good.

JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 64 times
Been thanked: 306 times
Contact:

### Re: use of trigonometric function in flowcode 4.3

Hello. Its a shame you can not use fixed-point values for your lookup, as this would by far be the easiest solution! (This would work with an accuracy of about 0.00025 for a 12-bit lookup table, or 0.004 for an 8 bit table).

Assuming 'ang' is a temporary variable needed for the calculation, you just want the height of the triangle, and that you have no trigonometric functions available...
Relationship of d and a
triangle.png (4.1 KiB) Viewed 2223 times

Code: Select all

`ang = atan(d / a)h = a . sin(ang)So...sin(ang) = d / r=> h = (a.d) / rr = sqrt(a^2 + d^2)=> h = sqrt((a.d)^2 / (a^2 + d^2))`

I do not know the scale for your values so I cant recommend a look-up table for square roots, but you could use something like Newtons approximation using the floating-point result of h^2 to find its root.

This finds the height of the triangle.

To be honest, how BoostC is with floats it might not be that much slower to do it this way than use trig. There may even be a direct C call you might use to a floating point library to find a floating-point square root, though I am not an expert here so cant really help too much.

I home this is of use and is close to the topic!

Jonny

Rahul Kulkarni
Posts: 8
Joined: Fri Jan 20, 2012 5:46 am
Has thanked: 3 times
Contact:

### Re: use of trigonometric function in flowcode 4.3

Thanks for the reply. I appreciate your solution. Even I thought of it. But when I saw that if single equation is going to solve problem then what is the need of lookup tables? Because AVR version of flowcode does support all trignometric functions. But this I came to know after buying PIC kit. So now I have converted these trignometric functions into simple algebric functions which gives me same output as them. The thing is I am using 5 relations in order out of which 2 are trignometric. Output of 1st function is input to second one and so on. Once again thanks.