8. MODULATOR

 

8.1 Description

 

 

graphics6

 

 

 

 

 

8.2 Creating Module

To create Modulator module use steps for creating modules, Sub-chapter 2.3.1 Creating a Module Using an Text Editor.

 

Modulator VHDL model:

 

library ieee;

    use ieee.std_logic_1164.all;

    use ieee.std_logic_arith.all;

    use ieee.std_logic_textio.all;

    use ieee.std_logic_unsigned.all;

 

    use work.modulator_pkg.all;

 

library unisim;

    use unisim.vcomponents.all;

 

entity modulator is

    generic(

        this_module_is_top_g : module_is_top_t := yes;                                                                                  

        );

 

    port(

        clk_p        : in  std_logic; -- differential input clock signal

        clk_n        : in std_logic;   – differential input clock signal

        sw0          : in  std_logic;   -- signal made for selecting frequency

        pwm_out  : out std_logic -- pulse width modulated signal

        );

end;

 

architecture rtl of modulator is

 

    signal clk_in_s         : std_logic;

    signal ampl_cnt_s   : std_logic_vector(design_setting_g.depth-1 downto 0); -- amplitude counter

    signal sine_ampl_s : std_logic_vector(design_setting_g.width-1 downto 0);  -- current amplitude value of the sine signal

    signal freq_trig_s    : std_logic := '0';                                                            – signal which frequency depends on the sw0 state

 

    constant c1_c : real := board_name_g.fclk/(real((2**design_setting_g.depth)*(2**design_setting_g.width)));            

    -- c1_c = fclk/(2^depth*2^width)     - c1_c = 190.73486, fclk = 200 MHz

    constant div_factor_freqhigh_c : integer := integer(c1_c/design_setting_g.f_high)*(2**design_setting_g.width);   

    -- div_factor_freqhigh_c = (c1_c/f_high)*2^width   - threshold value of frequency a = 221184

    constant div_factor_freqlow_c  : integer := integer(c1_c/design_setting_g.f_low)*(2**design_setting_g.width);  

    -- div_factor_freqlow_c  = (c1_c/f_low)*2^width     - threshold value of frequency b = 782336

 

begin

 

-- if module is top, it has to generate the differential clock buffer in case       

-- of a differential clock, otherwise it will get a single ended clock signal

-- from the higher hierarchy

 

    clk_buf_if_top : if (this_module_is_top_g = yes) generate

 

        clk_buf : if (board_name_g.has_diff_clk = yes) generate

 

            IBUFGDS_inst : IBUFGDS

                generic map (