TRAVEO™ T2G: Using sin and cos functions in CYT2B7 - KBA236187
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Version: **
Refer to the corresponding IDE document for using sin and cos functions in TRAVEO™ T2G CYT2B7. For IAR, refer to EWARM development guide. For GHS, refer to MULTI: Building application for Embedded Arm®.
A sample code for IAR is provided, to show different CPU loading using different option settings.
Standard library math functions for C/C++ are provided by IAR.
There are three different versions; default version, small version, and more accurate version. And, three different variant types are used; double, float, and long double.
The following table shows the sample code and the total time consumed for executing sin, cos, and tan functions for 100 times.
Sample code |
Total time consumed for 100 times execution |
for (i = 0; i < 100; i++) { fresult = __iar_sin_smallf(f_test); fresult = __iar_cos_smallf(f_test); fresult = __iar_tan_smallf(f_test); f_test += 0.01f; } |
Total time = 204us |
Cy_GPIO_Inv(USER_LED_PORT, USER_LED_PIN); for (i = 0; i < 100; i++) { fresult = __iar_sin_accuratef(f_test); fresult = __iar_cos_accuratef(f_test); fresult = __iar_tan_accuratef(f_test); f_test += 0.01f; } |
Total time = 384us |
Cy_GPIO_Inv(USER_LED_PORT, USER_LED_PIN); for (i = 0; i < 100; i++) { double_result = __iar_sin_small(double_test); double_result = __iar_cos_small(double_test); double_result = __iar_tan_small(double_test); double_test += 0.01f; } |
Total time = 2.62ms |
Cy_GPIO_Inv(USER_LED_PORT, USER_LED_PIN); for (i = 0; i < 100; i++) { double_result = __iar_sin_accurate(double_test); double_result = __iar_cos_accurate(double_test); double_result = __iar_tan_accurate(double_test); double_test += 0.01f; } |
Total time = 3.86ms |
Cy_GPIO_Inv(USER_LED_PORT, USER_LED_PIN); for (i = 0; i < 100; i++) { long_double_result = __iar_sin_smalll(long_double_test); long_double_result = __iar_cos_smalll(long_double_test); long_double_result = __iar_tan_smalll(long_double_test); long_double_test += 0.01f; } |
Total time = 2.64ms |
Cy_GPIO_Inv(USER_LED_PORT, USER_LED_PIN); for (i = 0; i < 100; i++) { long_double_result = __iar_sin_accuratel(long_double_test); long_double_result = __iar_cos_accuratel(long_double_test); long_double_result = __iar_tan_accuratel(long_double_test); long_double_test += 0.01f; } Cy_GPIO_Inv(USER_LED_PORT, USER_LED_PIN); |
Total time = 3.86ms |
Since theTRAVEO™ CY2B7’s CM4 core includes a single precision FPU, for the CPU performance to use float is much better than double and long double variant types. Besides, small and accurate version also has a significant difference in the CPU performance.
Different version can be used based on the application requirement.
Note: This KBA applies to the following series of TRAVEO™ MCUs:
- CYT2B series