Vivado cordic IP核rotate和translate使用详解(附有代码)

Vivado cordic IP核rotate和translate使用详解(附有代码)

目录

前言

一、cordic简介

二、使用cordic IP核需要知道的预备知识

1.数据端口

2.Q Numbers Format

3.Vector Translation

4.Vector Rotation

三、IP核配置说明

1.translate

2.Rotate

四、Translate仿真

1.顶层代码

2.仿真代码

五、Rotate仿真

1.顶层代码

2.仿真代码

总结

参考链接:http://t.csdn.cn/pha8V


前言

        利用givens旋转可以把一个矩阵分解为一个正交矩阵和一个三角矩阵,在FPGA中要想实现矩阵的上述分解操作,需要用到的就是cordic IP核当中的rotate和translate模式。本文将结合官方的cordic数据手册和自身使用经历详细介绍cordic IP核当中的rotate和translate模式的使用方法。


提示:以下是本篇文章正文内容,写文章实属不易,希望能帮助到各位,转载请附上链接。

一、cordic简介

        CORDIC(Coordinate Rotation Digital Computer)算法即坐标旋转数字计算方法,是J.D.Volder1于1959年首次提出,主要用于三角函数、双曲线、指数、对数的计算。该算法通过基本的加和移位运算代替乘法运算,使得矢量的旋转和定向的计算不再需要三角函数、乘法、开方、反三角、指数等函数。

        CORDIC IP核支持的模式如图0所示,本文介绍的为前2个。

图0 功能概述

        CORDIC算法具体介绍和Square root模式操作可见文章末尾附上的链接,本文注重介绍cordic IP核的使用,原理在此不做赘述。

二、使用cordic IP核需要知道的预备知识

        以下说明大多来自于cordic IP核官方给出的英文数据手册,此处作一定解释,帮助大家理解。

1.数据端口

图1 端口介绍

         观察图1,会发现输入的数据(不看相位输入)和输出的数据就只有一个端口,但在rotate和translate模式中被操作的数应该是一个矢量,也就是一个坐标,输入输出应当是成双成对的,而图1所示却只有一个端口,这是为什么呢?

        这里就是大家使用该IP核需要注意的一个地方,它这个数据输入输出拼接到一个端口了。如图2和图3所示。

图2 输入数据格式
图3 输出数据格式

         看完图2和图3我们需要注意数据拼接时坐标x在低位,坐标y或者相位输出在高位。

2.Q Numbers Format

        cordic IP核操作数为定点数,坐标x、y输入输出和相位输入输出的格式有所不同。

        首先我们需要知道XQN格式,所谓XQN格式就是1+X+N位补码二进制数,1位符号位,后面跟着X个整数位,后面跟着一个N位尾数(分数)。

        cordic IP核中坐标是1QN格式,相角是2QN格式,其实这个格式与数据范围有一定关系,相角范围比坐标范围要宽一些,所以相交整数位要多一位。

         输入向量(Xin, Yin)和输出向量(Xout, Yout)表示为一对宽度为2位的整数二补数(1QN格式)。输入旋转角度,引脚弧度,也表示为一个固定的二补数,但宽度为3位(2QN格式)。

3.Vector Translation

图4 translation数据范围
图5 例子
图6 例子MATLAB

 对比图5与图6相位,可见10位误差较大。

4.Vector Rotation

图7 数据范围
图8 例子

 图8将输入(x,y)沿坐标轴旋转了-pi/2。

三、IP核配置说明

1.translate

图9 page1配置

 Functional Selection:此处选择Translate

Architectural Configuration: CORDIC核心有两种架构配置,并行和字串行。此处选择并行。

Pipelining Mode:CORDIC核心提供了三种流水线模式:无、最优和最大。流水线模式的选择基于功能配置和体系结构配置的选择。不可用的管道模式在CORDIC GUI中是灰色的。

None: CORDIC核心在没有流水线的情况下实现。

优化:CORDIC核心实现了尽可能多的流水线阶段,而不使用任何额外的lut。

最大:CORDIC核心在每个shift-add子阶段之后都有一个管道实现。

此处选择优化。

Data Format: Translate默认不可选。

Phase Format:CORDIC核心提供两种相位格式选项。

Radians:相位表示为3位整数宽度的定点二补数,以弧度单位表示。例如:01100000代表3.0弧度。

 Scaled Radians:相位表示为3位整数宽度的定点二补数,以π弧度为单位。一个缩放弧度等于π * 1弧度。例如:11110000表示-0.5 * Pi弧度。

此处选择Radians。

Input Width:输入坐标位宽。

Output Width:输出坐标位宽。

Round Mode:CORDIC核心提供四种舍入模式。

Truncate: The X_OUT, Y_OUT, and PHASE_OUT outputs are truncated.
Positive Infinity: The X_OUT, Y_OUT, and PHASE_OUT outputs are rounded such 
that 1/2 is rounded up (towards positive infinity). It is equivalent to the MATLAB
function floor(x + 0.5)
Pos Neg Infinity: The outputs X_OUT, Y_OUT, and PHASE_OUT are rounded such 
that 1/2 is rounded up (towards positive infinity) and -1/2 is rounded down 
(towards negative infinity). It is equivalent to the MATLAB function round(x).
Nearest Even: The X_OUT, Y_OUT, and PHASE_OUT outputs are rounded toward the 
nearest even number such that a 1/2 is rounded down and 3/2 is rounded up.

此处选择Round Pos Neg Inf。

Iterations和 Precision:不选设为0 IP核根据其他设置默认设置。

Coarse Rotation:如果关闭粗旋转,输入/输出范围将限制在第一象限(-Pi/4到+ Pi/4)。所以应该勾上。

Compensation Scaling:补偿方式。

No Scale Compensation: 输出X和Y没有补偿,并生成,按比例Zi缩放。

LUT Based:输出X和Y补偿使用基于LUT的常系数乘法器。

BRAM: 输出X和Y使用块ram为基础的常系数乘法器进行补偿。

Embedded Multiplier: 输出X和Y使用DSP Slice进行补偿。

此处如果选No,不会补偿,输出结果不对。以保证结果正确,必须选择一项补偿方式。此处默认选LUT Based。

图10 page2配置

 第2页的配置全部不用管,默认即可,几乎无影响。

2.Rotate

Rotate配置同Translate。模式选择Rotate即可。

四、Translate仿真

1.顶层代码

`timescale 1ns / 1ps
//
// Company: cq university
// Engineer: clg
// Create Date: 2023/01/10 13:04:52
// Design Name: 
// Module Name: cordic_translate_test
// Project Name: 
// Target Devices: 
// Tool Versions: 2017.4
// Description: 
// Dependencies: 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//

module cordic_translate_test(
input clk,                    //输入时钟信号
input start,                  //输入开始计算信号
input [31:0] x_in,            //输入坐标x
input [31:0] y_in,            //输入坐标y
output wire over,              //输出计算完成标志
output wire [31:0] x_out,      //输出坐标x
output wire [31:0] pha_out     //输出相角
);


cordic_translate_ip u_cordic_translate_ip(
  .aclk(clk),                                        // input wire aclk
  .s_axis_cartesian_tvalid(start),  // input wire s_axis_cartesian_tvalid
  .s_axis_cartesian_tdata({y_in,x_in}),    // input wire [63 : 0] s_axis_cartesian_tdata
  .m_axis_dout_tvalid(over),            // output wire m_axis_dout_tvalid
  .m_axis_dout_tdata({pha_out,x_out})              // output wire [63 : 0] m_axis_dout_tdata
);

endmodule

2.仿真代码

`timescale 1ns / 1ps
//
// Company: cq university
// Engineer: clg
// Create Date: 2023/01/10 13:06:20
// Design Name: 
// Module Name: cordic_translate_test_tb
// Project Name: 
// Target Devices: 
// Tool Versions: 2017.4
// Description: 
// Dependencies: 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//

module cordic_translate_test_tb();

// cordic_translate_test Parameters
parameter PERIOD  = 2;

// cordic_translate_test Inputs
reg   clk                                  = 0 ;
reg   start                                = 0 ;
reg   [31:0]  x_in                         = 0 ;
reg   [31:0]  y_in                         = 0 ;

// cordic_translate_test Outputs
wire  over                                 ;
wire  [31:0]  x_out                        ;
wire  [31:0]  pha_out                      ;

initial
begin
    forever #(PERIOD/2)  clk=~clk;
end

cordic_translate_test  u_cordic_translate_test (
    .clk                     ( clk             ),
    .start                   ( start           ),
    .x_in                    ( x_in     [31:0] ),
    .y_in                    ( y_in     [31:0] ),

    .over                    ( over            ),
    .x_out                   ( x_out    [31:0] ),
    .pha_out                 ( pha_out  [31:0] )
);


initial
begin
    #5  start<=1;
    x_in<=32'b00110000000000000000000000000000;
    y_in<=32'b00110000000000000000000000000000;
    #2  
    x_in<=32'b11100000000000000000000000000000;
    y_in<=32'b11100000000000000000000000000000;
end

endmodule
图11 translate仿真结果
图12 MATLAB结果

 对比图11和图12可知仿真正确。

五、Rotate仿真

1.顶层代码

`timescale 1ns / 1ps
//
// Company: cq university
// Engineer: clg
// Create Date: 2023/01/10 14:40:46
// Design Name: 
// Module Name: cordic_rotate_test
// Project Name: 
// Target Devices: 
// Tool Versions: 2017.4
// Description: 
// Dependencies: 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//

module cordic_rotate_test(
input clk,                    //输入时钟信号
input start,                  //输入开始计算信号
input [31:0] x_in,            //输入坐标x
input [31:0] y_in,            //输入坐标y
input [31:0] pha_in,          //输入相角
output wire over,             //输出计算完成标志
output wire [31:0] x_out,     //输出坐标x
output wire [31:0] y_out      //输出坐标y
    );
    
cordic_rotate_ip u_cordic_rotate_ip (
  .aclk(clk),                                        // input wire aclk
  .s_axis_phase_tvalid(start),          // input wire s_axis_phase_tvalid
  .s_axis_phase_tdata(pha_in),            // input wire [31 : 0] s_axis_phase_tdata
  .s_axis_cartesian_tvalid(start),  // input wire s_axis_cartesian_tvalid
  .s_axis_cartesian_tdata({y_in,x_in}),    // input wire [63 : 0] s_axis_cartesian_tdata
  .m_axis_dout_tvalid(over),            // output wire m_axis_dout_tvalid
  .m_axis_dout_tdata({y_out,x_out})              // output wire [63 : 0] m_axis_dout_tdata
);


endmodule

2.仿真代码

`timescale 1ns / 1ps
//
// Company: cq university
// Engineer: clg
// Create Date: 2023/01/10 14:41:21
// Design Name: 
// Module Name: cordic_rotate_test_tb
// Project Name: 
// Target Devices: 
// Tool Versions: 2017.4
// Description: 
// Dependencies: 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//

module cordic_rotate_test_tb();

// cordic_rotate_test Parameters
parameter PERIOD  = 2;

// cordic_rotate_test Inputs
reg   clk                                  = 0 ;
reg   start                                = 0 ;
reg   [31:0]  x_in                         = 0 ;
reg   [31:0]  y_in                         = 0 ;
reg   [31:0]  pha_in                       = 0 ;

// cordic_rotate_test Outputs
wire  over                                 ;
wire  [31:0]  x_out                        ;
wire  [31:0]  y_out                        ;


initial
begin
    forever #(PERIOD/2)  clk=~clk;
end

cordic_rotate_test  u_cordic_rotate_test (
    .clk                     ( clk            ),
    .start                   ( start          ),
    .x_in                    ( x_in    [31:0] ),
    .y_in                    ( y_in    [31:0] ),
    .pha_in                  ( pha_in  [31:0] ),

    .over                    ( over           ),
    .x_out                   ( x_out   [31:0] ),
    .y_out                   ( y_out   [31:0] )
);


initial
begin
    #5  start<=1;
  pha_in<=32'b00110010010000111111011010101000;
    x_in<=32'b00110000000000000000000000000000;
    y_in<=32'b00110000000000000000000000000000;
    #2  
  pha_in<=32'b10011011011110000001001010101111;
    x_in<=32'b11100000000000000000000000000000;
    y_in<=32'b11100000000000000000000000000000;
end



endmodule
图13 Rotate仿真结果

 如图13所示,(-0.5,-0.5)旋转-pi后为(0.5,0.5)。


总结

        以上就是今天要讲的内容,本文主要介绍了xilinx提供的CORDIC IP核当中Translate和Rotate模式的使用方法。

参考链接:http://t.csdn.cn/pha8V

猜你喜欢

转载自blog.csdn.net/m0_66360845/article/details/128634971