1 | ----------------------------------------------------------------------------------
|
2 | -- Company:Zuritronic
|
3 | -- Engineer:a.Kurka
|
4 | --
|
5 | -- Create Date: 06.05.2021 by a.kurka
|
6 | -- Design Name: AS21
|
7 | -- Module Name: cosFP - Behavioral
|
8 | -- modified : 09.05.2021 by a.kurka
|
9 | -- cos = func_C(ainp^2); -- für den Bereich [-PI/2,PI/2]
|
10 | ----------------------------------------------------------------------------------
|
11 | library IEEE;
|
12 | use IEEE.STD_LOGIC_1164.ALL;
|
13 | use IEEE.STD_LOGIC_ARITH.ALL;
|
14 | use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
15 |
|
16 |
|
17 | entity CosFP is
|
18 | port( nrst : in std_logic;
|
19 | clk : in std_logic;
|
20 | cecos : in std_logic;-- startimpuls afkt
|
21 | ainp :in std_logic_vector(31 downto 0);-- input afkt FP format
|
22 | cos :OUT std_logic_vector(31 downto 0)-- output afkt FP format
|
23 | );
|
24 | end CosFP;
|
25 |
|
26 | architecture Behavioral of CosFP is
|
27 | --====================================================
|
28 | COMPONENT func_C is
|
29 | port( nrst : in std_logic;
|
30 | clk : in std_logic;
|
31 | cefktC : in std_logic;-- startimpuls fkt_C
|
32 | Xinp :in std_logic_vector(31 downto 0);-- input afkt FP format
|
33 | aout :OUT std_logic_vector(31 downto 0)-- output afkt FP format
|
34 | );
|
35 | END COMPONENT;
|
36 | -----------------------------------------
|
37 | COMPONENT mulFP IS
|
38 | port (
|
39 | a: IN std_logic_VECTOR(31 downto 0);
|
40 | b: IN std_logic_VECTOR(31 downto 0);
|
41 | clk: IN std_logic;
|
42 | ce: IN std_logic;
|
43 | result: OUT std_logic_VECTOR(31 downto 0));
|
44 | END COMPONENT;
|
45 |
|
46 | --========================================================
|
47 | CONSTANT PIdiv2 :std_logic_vector(31 DOWNTO 0):=X"3FC90FDB";--1.57079632679 PI/2 in FP Format
|
48 |
|
49 | --==================================================================
|
50 | SIGNAL ce1 :std_logic:= '0';
|
51 | SIGNAL ce2 :std_logic:= '0';
|
52 | SIGNAL ain :std_logic_VECTOR(31 downto 0):=X"00000000";
|
53 | --==================================================================
|
54 | begin
|
55 | --------------------------------------------------------------
|
56 | pcos :PROCESS (clk)
|
57 | VARIABLE cntrclk : INTEGER RANGE 0 TO 127:= 0;
|
58 | variable state :INTEGER RANGE 0 TO 7:= 0;
|
59 | BEGIN
|
60 | IF rising_edge(clk) THEN
|
61 | IF nrst = '0' THEN
|
62 | state := 0;
|
63 | cntrclk := 0;
|
64 | --(OTHERS => '0');
|
65 | ELSE
|
66 | CASE state IS
|
67 | WHEN 0 =>
|
68 | IF cecos = '1' THEN
|
69 | ce1 <= '1';-- start für 1-x, x`2, ComP0.5
|
70 | state := 1;
|
71 | ELSE
|
72 | state := 0;
|
73 | END IF;
|
74 | WHEN 1 => --- Ausführen ain :=ainp^2
|
75 | ce1 <= '0';
|
76 | ce2 <= '1';-- start für fkt_c
|
77 | cntrclk := 11;
|
78 | state := 2;
|
79 | WHEN 2 => ---- mul2mX,2powX fertig
|
80 | IF cntrclk = 0 THEN
|
81 | state := 0;--warten auf nächste Start
|
82 | ELSE
|
83 | ce2 <= '0';
|
84 | cntrclk := cntrclk -1;
|
85 | state := 2;
|
86 | END IF;
|
87 | WHEN OTHERS =>
|
88 | state := 0;
|
89 | END CASE;
|
90 | END IF; -- if nrst/else
|
91 | END IF; -- clk
|
92 | END PROCESS;--end pacos
|
93 |
|
94 | --=======Implementation==================================
|
95 |
|
96 | cmulX : mulFP port map(a=>ainp,b=>ainp,clk=>clk,ce=>ce1,result=>ain);
|
97 | cfuncC: func_c port map(nrst=>nrst,clk=>clk,cefktC=>ce2,Xinp=>ain,aout=>cos);
|
98 |
|
99 | ---------------------------------------------------
|
100 | end Behavioral;
|