cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the hardware CORDIC of STM32G4 to solve the natural logarithm? Are there any examples?

one V
Associate III

How to use the hardware CORDIC of STM32G4 to solve the natural logarithm? Are there any examples?

1 ACCEPTED SOLUTION

Accepted Solutions
Igor Cesko
ST Employee

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

View solution in original post

5 REPLIES 5
Imen.D
ST Employee

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Igor Cesko
ST Employee

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

Igor Cesko
ST Employee

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