2022-12-17 09:04:42 -05:00
|
|
|
// FILE: isincos.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2022-12-09
|
|
|
|
// PURPOSE: R&D
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "FastTrig.h"
|
|
|
|
|
|
|
|
uint32_t start, stop;
|
|
|
|
volatile float x;
|
|
|
|
volatile int y;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
while (!Serial);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
delay(10);
|
|
|
|
|
|
|
|
start = micros();
|
|
|
|
for (uint32_t r = 0; r < 1000; r++)
|
|
|
|
{
|
|
|
|
x = sin(r);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("SIN: \t\t");
|
2022-12-22 07:44:04 -05:00
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println(" us");
|
2022-12-17 09:04:42 -05:00
|
|
|
delay(10);
|
|
|
|
|
|
|
|
|
|
|
|
start = micros();
|
|
|
|
for (uint32_t r = 0; r < 1000; r++)
|
|
|
|
{
|
|
|
|
x = isin(r);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("ISIN: \t\t");
|
2022-12-22 07:44:04 -05:00
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println(" us");
|
2022-12-17 09:04:42 -05:00
|
|
|
delay(10);
|
|
|
|
|
|
|
|
start = micros();
|
|
|
|
for (uint32_t r = 0; r < 1000; r++)
|
|
|
|
{
|
|
|
|
x = cos(r);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("COS: \t\t");
|
2022-12-22 07:44:04 -05:00
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println(" us");
|
2022-12-17 09:04:42 -05:00
|
|
|
delay(10);
|
|
|
|
|
|
|
|
|
|
|
|
start = micros();
|
|
|
|
for (uint32_t r = 0; r < 1000; r++)
|
|
|
|
{
|
|
|
|
x = icos(r);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("ICOS: \t\t");
|
2022-12-22 07:44:04 -05:00
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println(" us");
|
2022-12-17 09:04:42 -05:00
|
|
|
delay(10);
|
|
|
|
|
|
|
|
for (uint32_t r = 0; r <= 360; r++)
|
|
|
|
{
|
2022-12-22 07:44:04 -05:00
|
|
|
x = cos(r * (PI / 180.0));
|
2022-12-17 09:04:42 -05:00
|
|
|
y = icos(r);
|
|
|
|
if (abs(x - y) >= 1)
|
|
|
|
{
|
|
|
|
Serial.print(r);
|
|
|
|
Serial.print('\t');
|
|
|
|
Serial.print(x);
|
|
|
|
Serial.print('\t');
|
|
|
|
Serial.print(float(y));
|
2022-12-22 07:44:04 -05:00
|
|
|
Serial.print('\t');
|
|
|
|
Serial.print(100.0 - 100.0 * float(y) / x);
|
|
|
|
Serial.print("%");
|
2022-12-17 09:04:42 -05:00
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
volatile float sum = 0;
|
|
|
|
start = micros();
|
|
|
|
for (uint32_t r = 0; r < 1000; r++)
|
2022-12-22 07:44:04 -05:00
|
|
|
{
|
|
|
|
sum += sin(r * (PI / 180.0)) + cos(r * (PI / 180.0));
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("SIN + COS: \t");
|
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println(" us");
|
|
|
|
Serial.println(sum, 4);
|
|
|
|
delay(10);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
start = micros();
|
|
|
|
for (uint32_t r = 0; r < 1000; r++)
|
2022-12-17 09:04:42 -05:00
|
|
|
{
|
|
|
|
sum += isin(r) + icos(r);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("ISIN + ICOS: \t");
|
2022-12-22 07:44:04 -05:00
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println(" us");
|
|
|
|
Serial.println(sum, 4);
|
2022-12-17 09:04:42 -05:00
|
|
|
delay(10);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
start = micros();
|
|
|
|
for (uint32_t r = 0; r < 1000; r++)
|
|
|
|
{
|
|
|
|
float p, q;
|
2022-12-22 07:44:04 -05:00
|
|
|
isincos(r, &p, &q);
|
2022-12-17 09:04:42 -05:00
|
|
|
sum += p + q;
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print("ISINCOS: \t");
|
2022-12-22 07:44:04 -05:00
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println(" us");
|
|
|
|
Serial.println(sum, 4);
|
2022-12-17 09:04:42 -05:00
|
|
|
delay(10);
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t r = 0; r < 100; r++)
|
|
|
|
{
|
|
|
|
float p, q, s, t;
|
2022-12-22 07:44:04 -05:00
|
|
|
isincos(r * 0.1, &p, &q);
|
|
|
|
s = isin(r * 0.1);
|
|
|
|
t = icos(r * 0.1);
|
|
|
|
if ((abs(p - s) > 0.0001) || (abs(q - t) > 0.0001))
|
2022-12-17 09:04:42 -05:00
|
|
|
{
|
|
|
|
Serial.print(r);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print(s, 6);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print(p, 6);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print(t, 6);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print(q, 6);
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delay(10);
|
|
|
|
|
|
|
|
Serial.println("\ndone...");
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|