2021-03-16 09:16 PM
How to use the hardware CORDIC of STM32G4 to solve the natural logarithm? Are there any examples?
Solved! Go to Solution.
2021-03-17 05:15 AM
Hello @one V (Community Member) ,
You can use example:
"STM32Cube_FW_G4_V1.4.0\Projects\NUCLEO-G474RE\Examples\CORDIC\CORDIC_Sin_DMA"
but you replace the sine function "sCordicConfig.Function" from "CORDIC_FUNCTION_SINE" to function "CORDIC_FUNCTION_NATURALLOG"
and tune the "sCordicConfig.Scale" parameter according reference manual : see there Table 112. Natural log scaling factors and corresponding ranges.
Regards
Igor
2021-03-17 02:04 AM
Hello @one V ,
Have a look at this AN5325 Getting started with the CORDIC accelerator using STM32CubeG4 MCU Package.
You can get inspired from the CORDIC example within STM32CubeG4 MCU package:
STM32Cube_FW_G4_V1.4.0\Projects\STM32G474E-EVAL\Examples\CORDIC\
Hope this helps you :smiling_face_with_smiling_eyes:
Imen
2021-03-17 05:15 AM
Hello @one V (Community Member) ,
You can use example:
"STM32Cube_FW_G4_V1.4.0\Projects\NUCLEO-G474RE\Examples\CORDIC\CORDIC_Sin_DMA"
but you replace the sine function "sCordicConfig.Function" from "CORDIC_FUNCTION_SINE" to function "CORDIC_FUNCTION_NATURALLOG"
and tune the "sCordicConfig.Scale" parameter according reference manual : see there Table 112. Natural log scaling factors and corresponding ranges.
Regards
Igor
2021-03-17 07:34 PM
Thank you very much for your reply. I have already studied the examples and documents you mentioned. I have solved this problem, but I still need to refer to this document https://www.st.com/content/ccc/resource/training/technical/product_training/group0/df/3d/f3/88/05/ae/42/67/STM32G4-Peripheral-Cordic_Coprocessor_CORDIC/files/STM32G4-Peripheral-Cordic_Coprocessor_CORDIC.pdf/jcr:content/translations/en.STM32G4-Peripheral-Cordic_Coprocessor_CORDIC.pdf.
2021-03-17 07:34 PM
Thank you very much for your reply. I have already studied the examples and documents you mentioned. I have solved this problem, but I still need to refer to this document https://www.st.com/content/ccc/resource/training/technical/product_training/group0/df/3d/f3/88/05/ae/42/67/STM32G4-Peripheral-Cordic_Coprocessor_CORDIC/files/STM32G4-Peripheral-Cordic_Coprocessor_CORDIC.pdf/jcr:content/translations/en.STM32G4-Peripheral-Cordic_Coprocessor_CORDIC.pdf.
2021-03-18 04:20 AM
Hello @one V ,
The necessary information are also in reference manual RM0440 or application note AN5325 .
I have tested the modified CORDIC_Sin_DMA example and it is working fine: ln(x) is calculated correctly.
Just change input and output values for check:
/* Array of angles in Q1.31 format, regularly incremented from 0 to 1 */
static int32_t aAngles[ARRAY_SIZE] =
{
0x10000000, 0x20000000, 0x30000000, 0x40000000 //0.25 , 0.5 , 0.75 , 1.0 (x: arguments for ln(x) divided by SCALE=2 factor)
};
/* Array of reference sines in Q1.31 format */
static int32_t aRefSin[ARRAY_SIZE] =
{
0xD3A37A02, 0xE9D1BD01, 0xF6CB4EF7, 0x00000000 // results: ln(x) * 1/4
};
...
//sCordicConfig.Function = CORDIC_FUNCTION_SINE; /* sine function */
sCordicConfig.Function = CORDIC_FUNCTION_NATURALLOG; /* ln(x) function */
sCordicConfig.Precision = CORDIC_PRECISION_6CYCLES; /* max precision for q1.31 sine */
//sCordicConfig.Scale = CORDIC_SCALE_0; /* no scale */
sCordicConfig.Scale = CORDIC_SCALE_1; /* no scale */
...
Regards
Igor