Inverse Sin

I have built an variable frequency AC induction motor drive controlled by three Arduinos the program(s) do all kinds of things! but seeing how its an hysteresis drive the step time needs to change which requires an inverse Sin originally I had tried to do this online using Maclaurin series but due to all the other things that also need to happen this proved too much so I decided to go with a lookup table pre calculated at boot up

The great news is it now works much better than I expected it to! the bad news is the error from the seriously truncated series however this error only means a faster cycle it doesnt affect the performance just a faster frequency than commanded

So I need to get rid of the series (I don’t need it as I’m offline now) and just do a direct inverse sin which is the reason for the thread!

How can I change my code below and do an inverse sine?

I have read this

double asin ( double __x )

The asin() function computes the principal value of the arc sine of __x. The returned value is in the range [-pi/2, pi/2] radians. A domain error occurs for arguments not in the range [-1, +1].

But I dont understand how to use it!

Heres my code

index = 30;
   for(index=30; index<= 30+ NUM/2; index++)
  {
   X_NEW = ((index-30)/(30));
  INV_SIN = X_NEW + (0.166666666*pow(X_NEW, 3)) +(0.075*pow(X_NEW, 5))+ 
 (0.059523809*pow(X_NEW, 7)) +(0.060763888*pow(X_NEW, 9));
  T_NEW = (1000000)*(INV_SIN/OMEGA);
  INDEX_TIME [index] = T_NEW;
  }

Why not use the one available in math.h?

#include "math.h"

void setup()
{
  Serial.begin(115200);

  float x = -1;
  while (x < 1)
  {
    Serial.print(x,3);
    Serial.print("\t");
    Serial.println(asin(x),6);
    x += 0.001;
  }
}

void loop()
{
}
X_NEW = ((index-30)/(30));
  INV_SIN = X_NEW + (0.166666666*pow(X_NEW, 3)) +(0.075*pow(X_NEW, 5))+(0.059523809*pow(X_NEW, 7)) +(0.060763888*pow(X_NEW, 9));

How was X_NEW defined, as double or integer? The first line of code makes no sense if index is an integer unless all you want is X_NEW=0 for all index values less than 30.

The next line can be replaced with INV_SIN=asin(X_NEW); if X_NEW is double.

X_NEW was defined as a float

index is a number starting at 30 up to 60 (For 25Hz) so that X_NEW takes the values

0, 1/30,2/30…29/30 …1

And the code does work

So if I include the math.h library and change X_NEW into a double would this code work

index = 30;
for(index=30; index<= 30+ NUM/2; index++)
{
X_NEW = ((index-30)/(30));
INV_SIN=asin(X_NEW);
T_NEW = (1000000)*(INV_SIN/OMEGA);
INDEX_TIME [index] = T_NEW;
}

X_NEW won't be 1/30,2/30 ... unless index is float, or you do /30.0 instead of /30.