Skip to main content
one V
Associate III
March 17, 2021
Solved

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

  • March 17, 2021
  • 5 replies
  • 2517 views

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

This topic has been closed for replies.
Best answer by Igor Cesko

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

5 replies

ST Technical Moderator
March 17, 2021

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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
one V
one VAuthor
Associate III
March 18, 2021
Igor Cesko
Igor CeskoBest answer
ST Employee
March 17, 2021

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

one V
one VAuthor
Associate III
March 18, 2021
Igor Cesko
ST Employee
March 18, 2021

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