A cordic algorithm for obtaining the angle of the Verilog program in the vector mode under the circular system

Source: Internet
Author: User
Tags modulus

The following is a Verilog procedure for obtaining the angle of a cordic algorithm in the vector mode under a circular system:/*=================================================================== ===========*\
Filename:cordic.v
discription: Coordinate rotation number calculation method. Through this algorithm, the vector coordinates of the input are iterated 9 times
Calculation, the modulus and phase angle of the vector are obtained.

\*==============================================================================*/module CORDIC
(
clk_20m,
_rst,
Cordic_start,
Ug_d,
Ug_q,
Ug
Delta); Input clk_20m,
_rst,
Cordic_start; Cordic Transform Start flag

INPUT[15:0] Ug_d,//d-axis component of output voltage
Ug_q; Q-axis component of the output voltage
OUTPUT[15:0] Ug; Modulo value of the output voltage vector
OUTPUT[13:0] Delta; Phase angle of the output voltage vector

WIRE[31:0] ug_tmp;
Reg[3:0] times; Iteration Count Accumulator
REG[15:0] ug_d_tmp,//output voltage D-Axis component intermediate Iteration results
ug_q_tmp; Intermediate iteration result of the output voltage Q-Axis component

REG[13:0]//delta,
delta_tmp; Phase Angle Rotation Cumulative register


Assign Ug = (ug_d_tmp>>1) + (ug_d_tmp>>3)-(ug_d_tmp>>6)-(ug_d_tmp>>9);

Proportional coefficient adjustment of the voltage modulus to get 32 times times the actual modulus value
Assign ug_tmp[31:0] = ug_d_tmp[15:0] * + ' d48224;//d39797;
Assign ug_tmp[31:0] = ug_d_tmp[15:0] * + ' d45208;
Assign ug[15:0] = ug_tmp[31:16];
The phase angle of the output voltage vector is the rotation angle of the output of the CORDIC algorithm.
Assign Delta = delta_tmp;
/*
Always @ (Posedge clk_20m or Negedge _rst)
Begin
if (!_rst)
Delta <= ' H0;
else if (delta_tmp <= ' h6)
Delta <= delta_tmp;
else if (delta_tmp <= ' h1fff)
Delta <= ' h6;
else if (delta_tmp <= ' H3ffa)
Delta <= ' H3ffa;
Else
Delta <= delta_tmp;
Else
Delta <= ' h6;

end*/
Always @ (Posedge clk_20m or Negedge _rst)
Begin
if (!_rst)
Begin
TIMES[3:0] <= 4 ' HF;
Ug_d_tmp[15:0] <= ' H0;
Ug_q_tmp[15:0] <= ' H0;
Delta_tmp[13:0] <= ' H0;
End
else if (Cordic_start)//Start Cordic transform
Begin
TIMES[3:0] <= 4 ' H0;
Ug_d_tmp <= ug_d;
Ug_q_tmp <= ug_q;
Delta_tmp <= ' H0;
End
else if (Times <= 4 ' D9)//Start Iteration calculation
Begin
TIMES[3:0] <= times[3:0] + 4 ' H1; Iteration Count plus 1
Case (Times)
4 ' h0://ug_q_tmp[15] sign bit
if (ug_q_tmp[15])//The goal of the rotation is to bring the ug_q_tmp closer to 0,
According to the judgment of the ug_q_tmp symbol, decide whether to rotate forward or reverse
Begin
Ug_d_tmp <= ug_d_tmp-ug_q_tmp; Recalculate new D-axis components
Ug_q_tmp <= ug_q_tmp + ug_d_tmp; Recalculate new Q-axis components
Delta_tmp <= delta_tmp-14 ' hB40; To calculate the phase angle cumulatively
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + ug_q_tmp;
Ug_q_tmp <= ug_q_tmp-ug_d_tmp;
Delta_tmp <= delta_tmp + "HB40; (2880/64) =45
End
4 ' H1:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{ug_q_tmp[15], ug_q_tmp[15:1]};
Ug_q_tmp <= ug_q_tmp + {ug_d_tmp[15], ug_d_tmp[15:1]};
Delta_tmp <= delta_tmp-14 ' h6a4; (1700/64) =26.5625
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {ug_q_tmp[15], ug_q_tmp[15:1]};
Ug_q_tmp <= ug_q_tmp-{ug_d_tmp[15], ug_d_tmp[15:1]};
Delta_tmp <= delta_tmp + "H6A4; //
End
4 ' H2:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{{2{ug_q_tmp[15]}}, Ug_q_tmp[15:2]};
Ug_q_tmp <= ug_q_tmp + {{2{ug_d_tmp[15]}}, Ug_d_tmp[15:2]};
Delta_tmp <= delta_tmp-14 ' h382; (382/64=14.03125)
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {{2{ug_q_tmp[15]}}, Ug_q_tmp[15:2]};
Ug_q_tmp <= ug_q_tmp-{{2{ug_d_tmp[15]}}, Ug_d_tmp[15:2]};
Delta_tmp <= delta_tmp + "h382;
End
4 ' H3:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{{3{ug_q_tmp[15]}}, Ug_q_tmp[15:3]};
Ug_q_tmp <= ug_q_tmp + {{3{ug_d_tmp[15]}}, Ug_d_tmp[15:3]};
Delta_tmp <= delta_tmp-14 ' H1c8; (382/64=14.03125)
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {{3{ug_q_tmp[15]}}, Ug_q_tmp[15:3]};
Ug_q_tmp <= ug_q_tmp-{{3{ug_d_tmp[15]}}, Ug_d_tmp[15:3]};
Delta_tmp <= delta_tmp + "H1C8; (456/64=7.125)
End
4 ' H4:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{{4{ug_q_tmp[15]}}, Ug_q_tmp[15:4]};
Ug_q_tmp <= ug_q_tmp + {{4{ug_d_tmp[15]}}, Ug_d_tmp[15:4]};
Delta_tmp <= delta_tmp-14 ' hE5; (229/64=3.578125)
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {{4{ug_q_tmp[15]}}, Ug_q_tmp[15:4]};
Ug_q_tmp <= ug_q_tmp-{{4{ug_d_tmp[15]}}, Ug_d_tmp[15:4]};
Delta_tmp <= delta_tmp + "HE5;
End
4 ' h5:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{{5{ug_q_tmp[15]}}, Ug_q_tmp[15:5]};
Ug_q_tmp <= ug_q_tmp + {{5{ug_d_tmp[15]}}, Ug_d_tmp[15:5]};
Delta_tmp <= delta_tmp-14 ' h72; (114/64=1.78125)
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {{5{ug_q_tmp[15]}}, Ug_q_tmp[15:5]};
Ug_q_tmp <= ug_q_tmp-{{5{ug_d_tmp[15]}}, Ug_d_tmp[15:5]};
Delta_tmp <= delta_tmp + "H72;
End
4 ' h6:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{{6{ug_q_tmp[15]}}, Ug_q_tmp[15:6]};
Ug_q_tmp <= ug_q_tmp + {{6{ug_d_tmp[15]}}, Ug_d_tmp[15:6]};
Delta_tmp <= delta_tmp-14 ' h39;//(57/64=0.890625)
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {{6{ug_q_tmp[15]}}, Ug_q_tmp[15:6]};
Ug_q_tmp <= ug_q_tmp-{{6{ug_d_tmp[15]}}, Ug_d_tmp[15:6]};
Delta_tmp <= delta_tmp + "H39;
End
4 ' H7:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{{7{ug_q_tmp[15]}}, Ug_q_tmp[15:7]};
Ug_q_tmp <= ug_q_tmp + {{7{ug_d_tmp[15]}}, Ug_d_tmp[15:7]};
Delta_tmp <= delta_tmp-14 ' h1c;//(28/64=0.4375)
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {{7{ug_q_tmp[15]}}, Ug_q_tmp[15:7]};
Ug_q_tmp <= ug_q_tmp-{{7{ug_d_tmp[15]}}, Ug_d_tmp[15:7]};
Delta_tmp <= delta_tmp + "H1C;
End
4 ' H8:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{{8{ug_q_tmp[15]}}, Ug_q_tmp[15:8]};
Ug_q_tmp <= ug_q_tmp + {{8{ug_d_tmp[15]}}, Ug_d_tmp[15:8]};
Delta_tmp <= delta_tmp-14 ' he;//(14/64=0.21875)
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {{8{ug_q_tmp[15]}}, Ug_q_tmp[15:8]};
Ug_q_tmp <= ug_q_tmp-{{8{ug_d_tmp[15]}}, Ug_d_tmp[15:8]};
Delta_tmp <= delta_tmp + ' HE;
End
4 ' H9:
if (ug_q_tmp[15])
Begin
Ug_d_tmp <= ug_d_tmp-{{9{ug_q_tmp[15]}}, Ug_q_tmp[15:9]};
Ug_q_tmp <= ug_q_tmp + {{9{ug_d_tmp[15]}}, Ug_d_tmp[15:9]};
Delta_tmp <= delta_tmp-14 ' H7;
End
Else
Begin
Ug_d_tmp <= ug_d_tmp + {{9{ug_q_tmp[15]}}, Ug_q_tmp[15:9]};
Ug_q_tmp <= ug_q_tmp-{{9{ug_d_tmp[15]}}, Ug_d_tmp[15:9]};
Delta_tmp <= delta_tmp + "H7; (7/64=0.109375)
End
Default://All registers are zeroed by default
Begin
Ug_d_tmp <= "H0;
Ug_q_tmp <= "H0;
Delta_tmp <= ' H0;
End
//      ;
Endcase
End
Else
TIMES[3:0] <= 4 ' HF; Iterative calculation completed, end cordic algorithm, iteration number reset value


End Endmodule

A cordic algorithm for obtaining the angle of the Verilog program in the vector mode under the circular system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.