STM32G474测试IQmathLib
1 获取IQmathLib
参考博客:支持arm3-arm4的IQmathLib
2 链接IQmarhLib
创建IQmathLib文件夹存放获取的头文件和库文件
右键IQmathLib文件夹,分别添加IQmathLib.h(C语言开发选这个头文件)和IQmathLib-cm4f.a(根据自己开发板芯片选择)。
添加IQmathLib的路径(lib文件夹是静态库存放的位置),点击魔术棒---->C/C+±—>IncludePaths
链接配置完成了,此时编译工程会报以下错误:
需要更改静态库的文件类型,步骤如下(右键.a文件,点击魔术棒,将File Type修改如图所示):
再编译就无报错了
3 测试IQmathLib
添加头文件
添加测试代码(测试代码大致如下)
/* 添加头文件 */
#include “time.h”
#include “IQmathLib.h”
/* 定义全局变量 */
#define pi 3.1415926535897f
volatile float Input1,Input2,Input3;
volatile float Output;
volatile _iq IQ_Input1,IQ_Input2,IQ_Input3;
volatile _iq IQ_Output;
/* 测试代码 */
void Test_IQmath()
{
srand(clock ());
while(1)
{
Input1 = 1.0f*(rand()%(2*100 - 0+1) + 0);
Input1 = (Input1 - 100.0f)/100.0f;
Input2 = 1.0f*(rand()%(2*100 - 0+1) + 0);
Input2 = (Input2 - 100.0f)/100.0f;
Input3 = 1.0f*(rand()%(2*100 - 0+1) + 0);
Input3 = (Input3 - 100.0f)/100.0f;
Input1 = pi*Input1;
Input2 = pi*Input2;
Input3 = pi*Input3;
printf("Input1 Input2 Input3 %.12f %.12f %.12f\r\n",Input1,Input2,Input3);
IQ_Input1 = _IQ(Input1);// 浮点转定点
IQ_Input2 = _IQ(Input2);
IQ_Input3 = _IQ(Input3);
printf("IQ_Input1 IQ_Input2 IQ_Input3 %ld %ld %ld\r\n",IQ_Input1,IQ_Input2,IQ_Input3);
// Test mathLib
DWT_CYCCNT = 0;// DWT计时模块
s_cycle = DWT_CYCCNT;
e_cycle = DWT_CYCCNT;
delta_cycle = e_cycle - s_cycle;
s_cycle = DWT_CYCCNT;
Output = sinf(Input1);
e_cycle = DWT_CYCCNT;
printf("Value = %.4f mathLib_Cycle = %d \r\n", Output, e_cycle-s_cycle-delta_cycle);
// Test IQmathLib
DWT_CYCCNT = 0;// DWT计时模块
s_cycle = DWT_CYCCNT;
e_cycle = DWT_CYCCNT;
delta_cycle = e_cycle - s_cycle;
s_cycle = DWT_CYCCNT;
IQ_Output = _IQsin(IQ_Input1);
e_cycle = DWT_CYCCNT;
Output = _IQtoD(IQ_Output);// 定点转浮点
printf("Value = %.4f IQmathLib_Cycle = %d \r\n", Output, e_cycle-s_cycle-delta_cycle);
printf("\n");
HAL_Delay(2000);
}
}
测试结果如下: