STM32G4使用IQmathLib

STM32G474测试IQmathLib

1 获取IQmathLib

参考博客:支持arm3-arm4的IQmathLib

2 链接IQmarhLib

创建IQmathLib文件夹存放获取的头文件和库文件

image-20240123145141354

右键IQmathLib文件夹,分别添加IQmathLib.h(C语言开发选这个头文件)和IQmathLib-cm4f.a(根据自己开发板芯片选择)。

image-20240123145532245

添加IQmathLib的路径(lib文件夹是静态库存放的位置),点击魔术棒---->C/C+±—>IncludePaths

image-20240123145916654

链接配置完成了,此时编译工程会报以下错误:

image-20240123150159419

需要更改静态库的文件类型,步骤如下(右键.a文件,点击魔术棒,将File Type修改如图所示):

image-20240123150303732

image-20240123150421293

再编译就无报错了

image-20240123150517088

3 测试IQmathLib

添加头文件

image-20240123150652029

添加测试代码(测试代码大致如下)

/* 添加头文件 */
#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);
    }
}

测试结果如下:
image-20240123151612816

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值