Not applicable
May 04, 2016
01:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 04, 2016
01:21 AM
Hi,
The XMC_MATH_CORDIC_ArcTanNB function in xmc_math.c assumes XMC_MATH_Q8_15_t types for arguments. It means all operations in circular & vectoring mode
operations assumes XMC_MATH_Q8_15_t typed arguments?
Is this code correct to calculate arctan(1/1) ?
The XMC_MATH_CORDIC_ArcTanNB function in xmc_math.c assumes XMC_MATH_Q8_15_t types for arguments. It means all operations in circular & vectoring mode
operations assumes XMC_MATH_Q8_15_t typed arguments?
Is this code correct to calculate arctan(1/1) ?
#include
#include "XMC1300.h"
int main(void)
{
int a;
XMC_MATH_Q8_15_t x = 1 << 16;
XMC_MATH_Q8_15_t y = 1 << 16;
XMC_MATH_CORDIC_ArcTanNB(x, y);
while(XMC_MATH_CORDIC_IsBusy()); // wait for calculation to end
a = 1; // set breakpoint here to check CORRZ
while(1);
}
- Tags:
- IFX
5 Replies
May 04, 2016
02:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 04, 2016
02:11 AM
Hello,
I think it should be 1 << 15 right? Because you have 15 fractional bits.
I think it should be 1 << 15 right? Because you have 15 fractional bits.
Not applicable
May 04, 2016
06:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 04, 2016
06:02 AM
Ok, the result seems good this way, I have got 0x200000 (24bit) which is pi/4.
How to compute atan(-1,1) ? So what is -1 in Q8_15 ?
How to compute atan(-1,1) ? So what is -1 in Q8_15 ?
May 04, 2016
06:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 04, 2016
06:47 AM
Following the same approach:
-1*2^15 = -32768 (0xffff8000). As the format only has 24 bits, just remove the 8 MSBs.
-1*2^15 = -32768 (0xffff8000). As the format only has 24 bits, just remove the 8 MSBs.
Not applicable
May 05, 2016
02:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 05, 2016
02:28 AM
Can I use this macro? I'm not sure because this macro contains floating point constants.
I have found a similar macro (XMC_MATH_Q0_23) in xmc_math.h
The argument can be integer only?
#define XMC_MATH_Q8_15(x) ((XMC_MATH_Q8_15_t)(((x) >= 0) ? ((x) * (1 << 15) + 0.5) : ((x) * (1 << 15) - 0.5)))
I have found a similar macro (XMC_MATH_Q0_23) in xmc_math.h
The argument can be integer only?
May 05, 2016
04:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 05, 2016
04:13 AM
Yes, I think that you can. This is basically the procedure to convert to fixed point:
- Multiply the floating point number by 2^(numberOffractionalBits)
- Round to the nearest integer
Considering this the argument can be float also.
Then it will be typecasted to int32 (XMC_MATH_Q8_15_t)
- Multiply the floating point number by 2^(numberOffractionalBits)
- Round to the nearest integer
Considering this the argument can be float also.
Then it will be typecasted to int32 (XMC_MATH_Q8_15_t)