2023-06-02 04:50 PM
I am using the CORDIC engine on an STM32G474 to perform an atan2, sin, and cos operations sequentially. Running the code below and testing different inputs yields expected results for atan2, but does not yield expected results for sin and cos. However, the sin/cos operation does yield expected results when commenting out the first CORDIC operation. Essentially, it appears that reconfiguring the CORDIC engine and running a different operation in quick succession yields incorrect results for the second operation. I didn't notice any examples in AN5325 that discussed reconfiguring the CORDIC engine, so I'm not sure how to deal with this issue.
LL_CORDIC_Config(hcordic.Instance,
LL_CORDIC_FUNCTION_PHASE,
LL_CORDIC_PRECISION_6CYCLES,
LL_CORDIC_SCALE_0,
LL_CORDIC_NBWRITE_2,
LL_CORDIC_NBREAD_1,
LL_CORDIC_INSIZE_32BITS,
LL_CORDIC_OUTSIZE_32BITS);
LL_CORDIC_WriteData(hcordic.Instance, cordic_input_x);
LL_CORDIC_WriteData(hcordic.Instance, cordic_input_y);
cordic_angle_result = (int32_t)LL_CORDIC_ReadData(hcordic.Instance);
LL_CORDIC_Config(hcordic.Instance,
LL_CORDIC_FUNCTION_SINE,
LL_CORDIC_PRECISION_6CYCLES,
LL_CORDIC_SCALE_0,
LL_CORDIC_NBWRITE_1,
LL_CORDIC_NBREAD_2,
LL_CORDIC_INSIZE_32BITS,
LL_CORDIC_OUTSIZE_32BITS);
LL_CORDIC_WriteData(hcordic.Instance, cordic_angle_input);
cordic_sin = (int32_t)LL_CORDIC_ReadData(hcordic.Instance);
cordic_cos = (int32_t)LL_CORDIC_ReadData(hcordic.Instance);
Solved! Go to Solution.
2023-09-06 01:22 AM - last edited on 2023-09-07 12:31 AM by Nicolas P.
2023-06-03 02:43 PM
While waiting for more helpful answers, please test your case using HAL functions instead of LL.
If this works, then find the difference between HAL and LL implementation.
2023-08-26 11:42 PM
I finally got around to implementing the HAL version of this test. I basically copied the inline functions from the ST CORDIC tutorial videos on youtube (see the link below). It looks like the HAL version suffers from the same issues as the low level implementation. The results of the sine function appear to corrupted when called immediately after the phase. The results are as expected when only one of the CORDIC functions is used.
https://www.youtube.com/watch?v=zR5oCBNpqfQ&t=335s
2023-08-27 12:52 AM
2023-09-06 01:22 AM - last edited on 2023-09-07 12:31 AM by Nicolas P.
2023-09-11 10:21 PM
Thanks, I was able to implement the recommended workarounds successfully. I did see the reference manual refers to inputting two arguments. However, the examples in AN5325 for sine and cosine all show only the single angle input. It might prove useful for others to update it to be consistent with the reference manual.